FileDocCategorySizeDatePackage
ZipShort.javaAPI DocApache Ant 1.703915Wed Dec 13 06:16:18 GMT 2006org.apache.tools.zip

ZipShort

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

Fields Summary
private int
value
Constructors Summary
public ZipShort(int value)
Create instance from a number.

param
value the int to store as a ZipShort
since
1.1

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

param
bytes the bytes to store as a ZipShort
since
1.1

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

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

        value = ZipShort.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 ZipShort)) {
            return false;
        }
        return value == ((ZipShort) o).getValue();
    
public byte[]getBytes()
Get value as two bytes in big endian byte order.

return
the value as a a two byte array in big endian byte order
since
1.1

        byte[] result = new byte[2];
        result[0] = (byte) (value & 0xFF);
        result[1] = (byte) ((value & 0xFF00) >> 8);
        return result;
    
public static byte[]getBytes(int value)
Get value as two bytes in big endian byte order.

param
value the Java int to convert to bytes
return
the converted int as a byte array in big endian byte order

        byte[] result = new byte[2];
        result[0] = (byte) (value & 0xFF);
        result[1] = (byte) ((value & 0xFF00) >> 8);
        return result;
    
public intgetValue()
Get value as Java int.

return
value as a Java int
since
1.1

        return value;
    
public static intgetValue(byte[] bytes, int offset)
Helper method to get the value as a java int from two bytes starting at given array offset

param
bytes the array of bytes
param
offset the offset to start
return
the correspondanding java int value

        int value = (bytes[offset + 1] << 8) & 0xFF00;
        value += (bytes[offset] & 0xFF);
        return value;
    
public static intgetValue(byte[] bytes)
Helper method to get the value as a java int from a two-byte array

param
bytes the array of bytes
return
the correspondanding java int value

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

return
the value stored in the ZipShort
since
1.1

        return value;