1 18 19 package org.apache.tools.zip; 20 21 26 public final class ZipLong implements Cloneable { 27 28 private long value; 29 30 35 public ZipLong(long value) { 36 this.value = value; 37 } 38 39 44 public ZipLong (byte[] bytes) { 45 this(bytes, 0); 46 } 47 48 54 public ZipLong (byte[] bytes, int offset) { 55 value = ZipLong.getValue(bytes, offset); 56 } 57 58 63 public byte[] getBytes() { 64 return ZipLong.getBytes(value); 65 } 66 67 72 public long getValue() { 73 return value; 74 } 75 76 81 public static byte[] getBytes(long value) { 82 byte[] result = new byte[4]; 83 result[0] = (byte) ((value & 0xFF)); 84 result[1] = (byte) ((value & 0xFF00) >> 8); 85 result[2] = (byte) ((value & 0xFF0000) >> 16); 86 result[3] = (byte) ((value & 0xFF000000L) >> 24); 87 return result; 88 } 89 90 96 public static long getValue(byte[] bytes, int offset) { 97 long value = (bytes[offset + 3] << 24) & 0xFF000000L; 98 value += (bytes[offset + 2] << 16) & 0xFF0000; 99 value += (bytes[offset + 1] << 8) & 0xFF00; 100 value += (bytes[offset] & 0xFF); 101 return value; 102 } 103 104 109 public static long getValue(byte[] bytes) { 110 return getValue(bytes, 0); 111 } 112 113 119 public boolean equals(Object o) { 120 if (o == null || !(o instanceof ZipLong)) { 121 return false; 122 } 123 return value == ((ZipLong) o).getValue(); 124 } 125 126 131 public int hashCode() { 132 return (int) value; 133 } 134 } 135 | Popular Tags |