org.apache.commons.compress.archivers.zip

## Class ZipShort

- java.lang.Object
- - org.apache.commons.compress.archivers.zip.ZipShort

- All Implemented Interfaces:
    Serializable, Cloneable

      public final class ZipShort
      extends Object
      implements Cloneable, Serializable

  Utility class that represents a two byte integer with conversion rules for the little endian byte order of ZIP files.
  See Also:
    Serialized Form
  This class is immutable

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ZipShort` | `ZERO` ZipShort with a value of 0.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ZipShort(byte[] bytes)` Create instance from bytes.
    `ZipShort(byte[] bytes, int offset)` Create instance from the two bytes starting at offset.
    `ZipShort(int value)` Create instance from a number.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `clone()`
    `boolean` | `equals(Object o)` Override to make two instances with same value equal.
    `byte[]` | `getBytes()` Get value as two bytes in big endian byte order.
    `static byte[]` | `getBytes(int value)` Get value as two bytes in big endian byte order.
    `int` | `getValue()` Get value as Java int.
    `static int` | `getValue(byte[] bytes)` Helper method to get the value as a java int from a two-byte array
    `static int` | `getValue(byte[] bytes, int offset)` Helper method to get the value as a java int from two bytes starting at given array offset
    `int` | `hashCode()` Override to make two instances with same value equal.
    `static void` | `putShort(int value, byte[] buf, int offset)` put the value as two bytes in big endian byte order.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### ZERO

          public static final ZipShort ZERO

      ZipShort with a value of 0.
      Since:
        1.14

  - ### Constructor Detail

    - #### ZipShort

          public ZipShort(int value)

      Create instance from a number.
      Parameters:
        `value` - the int to store as a ZipShort

    - #### ZipShort

          public ZipShort(byte[] bytes)

      Create instance from bytes.
      Parameters:
        `bytes` - the bytes to store as a ZipShort

    - #### ZipShort

          public ZipShort(byte[] bytes,
                          int offset)

      Create instance from the two bytes starting at offset.
      Parameters:
        `bytes` - the bytes to store as a ZipShort
        `offset` - the offset to start

  - ### Method Detail

    - #### getBytes

          public byte[] getBytes()

      Get value as two bytes in big endian byte order.
      Returns:
        the value as a a two byte array in big endian byte order

    - #### getValue

          public int getValue()

      Get value as Java int.
      Returns:
        value as a Java int

    - #### getBytes

          public static byte[] getBytes(int value)

      Get value as two bytes in big endian byte order.
      Parameters:
        `value` - the Java int to convert to bytes
      Returns:
        the converted int as a byte array in big endian byte order

    - #### putShort

          public static void putShort(int value,
                                      byte[] buf,
                                      int offset)

      put the value as two bytes in big endian byte order.
      Parameters:
        `value` - the Java int to convert to bytes
        `buf` - the output buffer
        `offset` - The offset within the output buffer of the first byte to be written. must be non-negative and no larger than `buf.length-2`

    - #### getValue

          public static int getValue(byte[] bytes,
                                     int offset)

      Helper method to get the value as a java int from two bytes starting at given array offset
      Parameters:
        `bytes` - the array of bytes
        `offset` - the offset to start
      Returns:
        the corresponding java int value

    - #### getValue

          public static int getValue(byte[] bytes)

      Helper method to get the value as a java int from a two-byte array
      Parameters:
        `bytes` - the array of bytes
      Returns:
        the corresponding java int value

    - #### equals

          public boolean equals(Object o)

      Override to make two instances with same value equal.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `o` - an object to compare
      Returns:
        true if the objects are equal

    - #### hashCode

          public int hashCode()

      Override to make two instances with same value equal.
      Overrides:
        `hashCode` in class `Object`
      Returns:
        the value stored in the ZipShort

    - #### clone

          public Object clone()

      Overrides:
        `clone` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.