1 18 19 package org.apache.tools.zip; 20 21 26 public final class ZipShort implements Cloneable { 27 28 private int value; 29 30 35 public ZipShort (int value) { 36 this.value = value; 37 } 38 39 44 public ZipShort (byte[] bytes) { 45 this(bytes, 0); 46 } 47 48 54 public ZipShort (byte[] bytes, int offset) { 55 value = ZipShort.getValue(bytes, offset); 56 } 57 58 63 public byte[] getBytes() { 64 byte[] result = new byte[2]; 65 result[0] = (byte) (value & 0xFF); 66 result[1] = (byte) ((value & 0xFF00) >> 8); 67 return result; 68 } 69 70 75 public int getValue() { 76 return value; 77 } 78 79 84 public static byte[] getBytes(int value) { 85 byte[] result = new byte[2]; 86 result[0] = (byte) (value & 0xFF); 87 result[1] = (byte) ((value & 0xFF00) >> 8); 88 return result; 89 } 90 91 97 public static int getValue(byte[] bytes, int offset) { 98 int value = (bytes[offset + 1] << 8) & 0xFF00; 99 value += (bytes[offset] & 0xFF); 100 return value; 101 } 102 103 108 public static int getValue(byte[] bytes) { 109 return getValue(bytes, 0); 110 } 111 112 118 public boolean equals(Object o) { 119 if (o == null || !(o instanceof ZipShort)) { 120 return false; 121 } 122 return value == ((ZipShort) o).getValue(); 123 } 124 125 130 public int hashCode() { 131 return value; 132 } 133 } 134 | Popular Tags |