Top Description Fields Constructors Methods
org.apache.commons.compress.archivers.zip

public final Class ZipShort

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Imports
java.io.Serializable, org.apache.commons.compress.utils.ByteUtils

Utility class that represents a two byte integer with conversion rules for the little-endian byte order of ZIP files.

Field Summary

Modifier and TypeField and Description
private static final long
private final int
public static final ZipShort
ZERO

ZipShort with a value of 0.

Constructor Summary

AccessConstructor and Description
public
ZipShort(final byte[]
the bytes to store as a ZipShort
bytes
)

Constructs a new instance from bytes.

public
ZipShort(final byte[]
the bytes to store as a ZipShort
bytes
,
final int
the offset to start
offset
)

Constructs a new instance from the two bytes starting at offset.

public
ZipShort(final int
the int to store as a ZipShort
value
)

Constructs a new instance from a number.

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public boolean

Returns:

true if the objects are equal
equals
(final Object
an object to compare
o
)

Overrides java.lang.Object.equals.

Override to make two instances with same value equal.
public static byte[]

Returns:

the converted int as a byte array in big-endian byte order
getBytes
(final int
the Java int to convert to bytes
value
)

Gets value as two bytes in big-endian byte order.

public byte[]

Returns:

the value as a two byte array in big-endian byte order
getBytes
()

Gets value as two bytes in big-endian byte order.

public static int

Returns:

the corresponding Java int value
getValue
(final byte[]
the array of bytes
bytes
)

Helper method to get the value as a Java int from a two-byte array

public static int

Returns:

the corresponding Java int value
getValue
(final byte[]
the array of bytes
bytes
,
final int
the offset to start
offset
)

Helper method to get the value as a Java int from two bytes starting at given array offset

public int

Returns:

value as a Java int
getValue
()

Gets value as Java int.

public int

Returns:

the value stored in the ZipShort
hashCode
()

Overrides java.lang.Object.hashCode.

Override to make two instances with same value equal.
public static void
putShort(final int
the Java int to convert to bytes
value
,
final byte[]
the output buffer
buf
,
final int
The offset within the output buffer of the first byte to be written. must be non-negative and no larger than buf.length-2
offset
)

put the value as two bytes in big-endian byte order.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID
valueback to summary
private final int value
ZEROback to summary
public static final ZipShort ZERO

ZipShort with a value of 0.

Since
1.14

Constructor Detail

ZipShortback to summary
public ZipShort(final byte[] bytes)

Constructs a new instance from bytes.

Parameters
bytes:byte[]

the bytes to store as a ZipShort

ZipShortback to summary
public ZipShort(final byte[] bytes, final int offset)

Constructs a new instance from the two bytes starting at offset.

Parameters
bytes:byte[]

the bytes to store as a ZipShort

offset:int

the offset to start

ZipShortback to summary
public ZipShort(final int value)

Constructs a new instance from a number.

Parameters
value:int

the int to store as a ZipShort

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
equalsback to summary
public boolean equals(final Object o)

Overrides java.lang.Object.equals.

Override to make two instances with same value equal.

Parameters
o:Object

an object to compare

Returns:boolean

true if the objects are equal

Annotations
@Override
getBytesback to summary
public static byte[] getBytes(final int value)

Gets value as two bytes in big-endian byte order.

Parameters
value:int

the Java int to convert to bytes

Returns:byte[]

the converted int as a byte array in big-endian byte order

getBytesback to summary
public byte[] getBytes()

Gets value as two bytes in big-endian byte order.

Returns:byte[]

the value as a two byte array in big-endian byte order

getValueback to summary
public static int getValue(final byte[] bytes)

Helper method to get the value as a Java int from a two-byte array

Parameters
bytes:byte[]

the array of bytes

Returns:int

the corresponding Java int value

getValueback to summary
public static int getValue(final byte[] bytes, final int offset)

Helper method to get the value as a Java int from two bytes starting at given array offset

Parameters
bytes:byte[]

the array of bytes

offset:int

the offset to start

Returns:int

the corresponding Java int value

getValueback to summary
public int getValue()

Gets value as Java int.

Returns:int

value as a Java int

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Override to make two instances with same value equal.

Returns:int

the value stored in the ZipShort

Annotations
@Override
putShortback to summary
public static void putShort(final int value, final byte[] buf, final int offset)

put the value as two bytes in big-endian byte order.

Parameters
value:int

the Java int to convert to bytes

buf:byte[]

the output buffer

offset:int

The offset within the output buffer of the first byte to be written. must be non-negative and no larger than buf.length-2

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override