Class ShortField

java.lang.Object
org.apache.poi.util.ShortField
All Implemented Interfaces:
FixedField

public class ShortField extends Object implements FixedField
representation of a short (16-bit) field at a fixed location within a byte array
Author:
Marc Johnson (mjohnson at apache dot org
  • Constructor Summary

    Constructors
    Constructor
    Description
    ShortField(int offset)
    construct the ShortField with its offset into its containing byte array
    ShortField(int offset, byte[] data)
    Construct the ShortField with its offset into its containing byte array and initialize its value from its byte array
    ShortField(int offset, short value)
    construct the ShortField with its offset into its containing byte array and initialize its value
    ShortField(int offset, short value, byte[] data)
    construct the ShortField with its offset into its containing byte array, initialize its value, and write its value to its byte array
  • Method Summary

    Modifier and Type
    Method
    Description
    short
    get()
    get the ShortField's current value
    void
    readFromBytes(byte[] data)
    set the value from its offset into an array of bytes
    void
    set the value from an InputStream
    void
    set(short value)
    set the ShortField's current value
    void
    set(short value, byte[] data)
    set the ShortField's current value and write it to a byte array
    return the value as a String
    void
    writeToBytes(byte[] data)
    write the value out to an array of bytes at the appropriate offset

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ShortField

      public ShortField(int offset) throws ArrayIndexOutOfBoundsException
      construct the ShortField with its offset into its containing byte array
      Parameters:
      offset - of the field within its byte array
      Throws:
      ArrayIndexOutOfBoundsException - if offset is negative
    • ShortField

      public ShortField(int offset, short value) throws ArrayIndexOutOfBoundsException
      construct the ShortField with its offset into its containing byte array and initialize its value
      Parameters:
      offset - of the field within its byte array
      value - the initial value
      Throws:
      ArrayIndexOutOfBoundsException - if offset is negative
    • ShortField

      public ShortField(int offset, byte[] data) throws ArrayIndexOutOfBoundsException
      Construct the ShortField with its offset into its containing byte array and initialize its value from its byte array
      Parameters:
      offset - of the field within its byte array
      data - the byte array to read the value from
      Throws:
      ArrayIndexOutOfBoundsException - if the offset is not within the range of 0..(data.length - 1)
    • ShortField

      public ShortField(int offset, short value, byte[] data) throws ArrayIndexOutOfBoundsException
      construct the ShortField with its offset into its containing byte array, initialize its value, and write its value to its byte array
      Parameters:
      offset - of the field within its byte array
      value - the initial value
      data - the byte array to write the value to
      Throws:
      ArrayIndexOutOfBoundsException - if offset is negative
  • Method Details

    • get

      public short get()
      get the ShortField's current value
      Returns:
      current value
    • set

      public void set(short value)
      set the ShortField's current value
      Parameters:
      value - to be set
    • set

      public void set(short value, byte[] data) throws ArrayIndexOutOfBoundsException
      set the ShortField's current value and write it to a byte array
      Parameters:
      value - to be set
      data - the byte array to write the value to
      Throws:
      ArrayIndexOutOfBoundsException - if the offset is out of range
    • readFromBytes

      public void readFromBytes(byte[] data) throws ArrayIndexOutOfBoundsException
      set the value from its offset into an array of bytes
      Specified by:
      readFromBytes in interface FixedField
      Parameters:
      data - the byte array from which the value is to be read
      Throws:
      ArrayIndexOutOfBoundsException - if the offset is out of range
    • readFromStream

      public void readFromStream(InputStream stream) throws IOException
      set the value from an InputStream
      Specified by:
      readFromStream in interface FixedField
      Parameters:
      stream - the InputStream from which the value is to be read
      Throws:
      LittleEndian.BufferUnderrunException - if there is not enough data available from the InputStream
      IOException - if an IOException is thrown from reading the InputStream
    • writeToBytes

      public void writeToBytes(byte[] data) throws ArrayIndexOutOfBoundsException
      write the value out to an array of bytes at the appropriate offset
      Specified by:
      writeToBytes in interface FixedField
      Parameters:
      data - the array of bytes to which the value is to be written
      Throws:
      ArrayIndexOutOfBoundsException - if the offset is out of range
    • toString

      public String toString()
      return the value as a String
      Specified by:
      toString in interface FixedField
      Overrides:
      toString in class Object
      Returns:
      the value as a String