FileDocCategorySizeDatePackage
ZipLong.javaAPI DocApache Ant 1.703994Wed Dec 13 06:16:22 GMT 2006org.apache.tools.zip

ZipLong

public final class ZipLong extends Object implements Cloneable
Utility class that represents a four byte integer with conversion rules for the big endian byte order of ZIP files.

Fields Summary
private long
value
Constructors Summary
public ZipLong(long value)
Create instance from a number.

param
value the long to store as a ZipLong
since
1.1

        this.value = value;
    
public ZipLong(byte[] bytes)
Create instance from bytes.

param
bytes the bytes to store as a ZipLong
since
1.1

        this(bytes, 0);
    
public ZipLong(byte[] bytes, int offset)
Create instance from the four bytes starting at offset.

param
bytes the bytes to store as a ZipLong
param
offset the offset to start
since
1.1

        value = ZipLong.getValue(bytes, offset);
    
Methods Summary
public booleanequals(java.lang.Object o)
Override to make two instances with same value equal.

param
o an object to compare
return
true if the objects are equal
since
1.1

        if (o == null || !(o instanceof ZipLong)) {
            return false;
        }
        return value == ((ZipLong) o).getValue();
    
public byte[]getBytes()
Get value as four bytes in big endian byte order.

since
1.1
return
value as four bytes in big endian order

        return ZipLong.getBytes(value);
    
public static byte[]getBytes(long value)
Get value as four bytes in big endian byte order.

param
value the value to convert
return
value as four bytes in big endian byte order

        byte[] result = new byte[4];
        result[0] = (byte) ((value & 0xFF));
        result[1] = (byte) ((value & 0xFF00) >> 8);
        result[2] = (byte) ((value & 0xFF0000) >> 16);
        result[3] = (byte) ((value & 0xFF000000L) >> 24);
        return result;
    
public longgetValue()
Get value as Java long.

since
1.1
return
value as a long

        return value;
    
public static longgetValue(byte[] bytes, int offset)
Helper method to get the value as a Java long from four bytes starting at given array offset

param
bytes the array of bytes
param
offset the offset to start
return
the correspondanding Java long value

        long value = (bytes[offset + 3] << 24) & 0xFF000000L;
        value += (bytes[offset + 2] << 16) & 0xFF0000;
        value += (bytes[offset + 1] << 8) & 0xFF00;
        value += (bytes[offset] & 0xFF);
        return value;
    
public static longgetValue(byte[] bytes)
Helper method to get the value as a Java long from a four-byte array

param
bytes the array of bytes
return
the correspondanding Java long value

        return getValue(bytes, 0);
    
public inthashCode()
Override to make two instances with same value equal.

return
the value stored in the ZipLong
since
1.1

        return (int) value;