Class Output

java.lang.Object
com.xinapse.io.Output

public abstract class Output extends Object
Abstract class providing methods to write primitve data values to output files and streams. The byte order of the data output file/stream can be specified for multi-byte primitive values.
  • Method Details

    • Byte

      public static long Byte(byte b, OutputStream strm) throws IOException
      Write a single byte value to an OutputStream strm.
      Parameters:
      b - the byte to write.
      strm - the OutputStream to which the byte will be written. If strm is null, no data are written.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Byte

      public static long Byte(byte b, RandomAccessFile f) throws IOException
      Write a single byte value to a RandomAccessFile f.
      Parameters:
      b - the byte to write.
      f - the RandomAccessFile to which the byte will be written. If f is null, no data are written.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Short

      public static long Short(Short s, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single Short to a OutputStream strm as a primitive short value.
      Parameters:
      s - the Short to write.
      strm - the OutputStream to which the Short's short value will be written. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Short

      public static long Short(short s, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single short to a OutputStream strm.
      Parameters:
      s - the short to write.
      strm - theOutputStream to which the short value will be written. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Short

      public static long Short(Short s, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single Short to a RandomAccessFile f as a primitive short value.
      Parameters:
      s - the Short to write.
      f - the RandomAccessFile to which the Short's short value will be written. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the file.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Short

      public static long Short(short s, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single short to aRandomAccessFile f.
      Parameters:
      s - the short to write.
      f - the RandomAccessFile to which the short value will be written. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the file.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UShort

      public static long UShort(Integer i, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single Integer to a OutputStream strm as an unsigned short value. If the Integer's size or sign mean that it cannot be written as an unsigned short, then the incorrect value will be written.
      Parameters:
      i - the Integer to write.
      strm - the OutputStream to which the Integer's value will be written as an unsigned short. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UShort

      public static long UShort(int i, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single int to a OutputStream strm as an unsigned short value. If the int's size or sign mean that it cannot be written as an unsigned short, then the incorrect value will be written.
      Parameters:
      i - the int to write.
      strm - the OutputStream to which the int's value will be written as an unsigned short. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UShort

      public static long UShort(Integer i, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single Integer to a RandomAccessFile f as an unsigned short value. If the Integer's size or sign mean that it cannot be written as an unsigned short, then the incorrect value will be written.
      Parameters:
      i - the Integer to write.
      f - the RandomAccessFile to which the Integer's value will be written as an unsigned short. If f is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UShort

      public static long UShort(int i, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single int to a RandomAccessFile f as an unsigned short value. If the int's size or sign mean that it cannot be written as an unsigned short, then the incorrect value will be written.
      Parameters:
      i - the int to write.
      f - the RandomAccessFile to which the int's value will be written as an unsigned short. If f is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Integer

      public static long Integer(Integer i, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single Integer to a OutputStream strm as a primitive int value.
      Parameters:
      i - the Integer to write.
      strm - the OutputStream to which the Integer's value will be written as an int. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Integer

      public static long Integer(int i, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single int to a OutputStream strm.
      Parameters:
      i - the int to write.
      strm - the OutputStream to which the int's value will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Integer

      public static long Integer(Integer i, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single Integer to a RandomAccessFile f as a primitive int value.
      Parameters:
      i - the Integer to write.
      f - the RandomAccessFile to which the Integer's value will be written as an int. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Integer

      public static long Integer(int i, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single int to a RandomAccessFile f.
      Parameters:
      i - the int to write.
      f - the RandomAccessFile to which the int's value will be written. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UInteger

      public static long UInteger(Long l, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single Long to a OutputStream strm as an unsigned int value. If the Long's size or sign mean that it cannot be written as an unsigned int, then the incorrect value will be written.
      Parameters:
      l - the Long to write.
      strm - the OutputStream to which the Long's value will be written as an unsigned int. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UInteger

      public static long UInteger(long l, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single long to a OutputStream strm as an unsigned int value. If the long's size or sign mean that it cannot be written as an unsigned int, then the incorrect value will be written.
      Parameters:
      l - the long to write.
      strm - the OutputStream to which the long's value will be written as an unsigned int. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UInteger

      public static long UInteger(Long l, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single Long to a OutputStream strm as an unsigned int value. If the long's size or sign mean that it cannot be written as an unsigned short, then the incorrect value will be written.
      Parameters:
      l - the unsigned integer value (as a Long) to write.
      f - the RandomAccessFile to which the unsigned integer value will be written as an int. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • UInteger

      public static long UInteger(long l, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single Long to a RandomAccessFile f as an unsigned int value. If the long's size or sign mean that it cannot be written as an unsigned short, then the incorrect value will be written.
      Parameters:
      l - the unsigned int value (as a long) to write.
      f - the RandomAccessFile to which the unsigned int value will be written. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Long

      public static long Long(long l, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single long to a OutputStream strm.
      Parameters:
      l - the long to write.
      strm - the OutputStream to which the long's value will be written. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Long

      public static long Long(long l, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single long to a RandomAccessFile f.
      Parameters:
      l - the long to write.
      f - the RandomAccessFile to which the long's value will be written. If f is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Float

      public static long Float(Float f, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single Float to a OutputStream strm as a float primitive.
      Parameters:
      f - the Float to write.
      strm - the OutputStream to which the Float's value will be written. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Float

      public static long Float(float f, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single float to a OutputStream strm.
      Parameters:
      f - the float value to write.
      strm - the OutputStream to which the float's value will be written. If strm is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Float

      public static long Float(Float flt, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single Float to a RandomAccessFile f as a float primitive.
      Parameters:
      flt - the Float to write.
      f - the RandomAccessFile to which the Float's value will be written. If f is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Float

      public static long Float(float flt, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single float to a RandomAccessFile f.
      Parameters:
      flt - the float to write.
      f - the RandomAccessFile to which the float's value will be written. If f is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Double

      public static long Double(Double d, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single Double to a OutputStream strm as a double primitive.
      Parameters:
      d - the Double to write.
      strm - the OutputStream to which the Double's value will be written.
      byteOrder - the ByteOrder of the data in the stream. If f is null, no data are written.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Double

      public static long Double(double d, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write a single double to a OutputStream strm.
      Parameters:
      d - the double to write.
      strm - the OutputStream to which the double's value will be written. If f is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Double

      public static long Double(Double d, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single Double to a RandomAccessFile f as a double primitive.
      Parameters:
      d - the Double to write.
      f - the RandomAccessFile to which the Double's value will be written.
      byteOrder - the ByteOrder of the data in the stream. If f is null, no data are written.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • Double

      public static long Double(double d, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write a single double to a RandomAccessFile f.
      Parameters:
      d - the double to write.
      f - the RandomAccessFile to which the double's value will be written. If f is null, no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • String

      public static long String(String s, OutputStream strm) throws IOException
      Write a String to a OutputStream strm. The String is encoded using UTF-8 Character Encoding.
      Parameters:
      s - the String to write.
      strm - the OutputStream to which the String will be written.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • String

      public static long String(String s, OutputStream strm, Charset charset) throws IOException
      Write a String to a OutputStream strm. The String is encoded using the specified Charset's Character Encoding.
      Parameters:
      s - the String to write.
      strm - the OutputStream to which the String will be written.
      charset - the charset that will be used to encode the String.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • ByteArray

      public static long ByteArray(byte[] b, OutputStream strm) throws IOException
      Write an array of byte values to a OutputStream strm.
      Parameters:
      b - the array of bytes to write.
      strm - the OutputStream to which the bytes will be written. If strm is null, no data are written.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • BitSet

      public static long BitSet(BitSet bitSet, OutputStream strm) throws IOException
      Writes a BitSet as individual bits to a OutputStream strm.

      If the number of boolean values to be written is not a multiple of 8, then a full byte is written at the end, with any unused bits written as 0's.

      Parameters:
      bitSet - the BitSet of values to write.
      strm - the OutputStream to which the boolean values will be written.
      Returns:
      the number of bytes written, or that would have been written if strm were non-null.
      Throws:
      IOException - if writing can't be completed due to an I/O error.
    • BitSet

      public static long BitSet(BitSet bitSet, RandomAccessFile f, int bitOffset) throws IOException
      Writes a BitSet as individual bits to a RandomAccessFile f.

      If the number of boolean values to be written is not a multiple of 8, then a full byte is written at the end, with any unused bits written as 0's.

      Parameters:
      bitSet - the BitSet of values to write.
      f - the RandomAccessFile to which the boolean values will be written.
      bitOffset - an offset (in bits) from the current location in the RandomAccessFile to the point where writing bits should start.
      Returns:
      the number of bytes written rounded up to the nearest full byte.
      Throws:
      IOException - if writing can't be completed due to an I/O error.
    • ShortArray

      public static long ShortArray(short[] sArray, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write an array of short values to a OutputStream strm.
      Parameters:
      sArray - the array of shorts to write.
      strm - the OutputStream to which the shorts will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • ShortArray

      public static long ShortArray(short[] sArray, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of short values to a RandomAccessFile f.
      Parameters:
      sArray - the array of shorts to write.
      f - the RandomAccessFile to which the shorts will be written. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • ShortArray

      public static long ShortArray(short[] sArray, int off, int len, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of short values to aRandomAccessFile f.
      Parameters:
      sArray - the array of shorts to write.
      off - the offset (number of shorts) into the sArray at which writing begins.
      len - the number of shorts to write.
      f - the RandomAccessFile to which the shorts will be written. If f is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • IntArray

      public static long IntArray(int[] iArray, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write an array of int values to a OutputStream strm.
      Parameters:
      iArray - the array of ints to write.
      strm - the OutputStream to which the ints will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • IntArray

      public static long IntArray(int[] iArray, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of int values to a RandomAccessFile f.
      Parameters:
      iArray - the array of ints to write.
      f - the RandomAccessFile to which the ints will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • IntArray

      public static long IntArray(int[] iArray, int off, int len, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of int values to a RandomAccessFile f.
      Parameters:
      iArray - the array of ints to write.
      off - the offset (number of ints) into the iArray at which writing begins.
      len - the number of ints to write.
      f - the RandomAccessFile to which the ints will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • LongArray

      public static long LongArray(long[] lArray, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write an array of long values to a OutputStream strm.
      Parameters:
      lArray - the array of longs to write.
      strm - the OutputStream to which the longs will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • LongArray

      public static long LongArray(long[] lArray, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of long values to a RandomAccessFile f.
      Parameters:
      lArray - the array of longs to write.
      f - the RandomAccessFile to which the longs will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • LongArray

      public static long LongArray(long[] lArray, int off, int len, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of long values to a RandomAccessFile f.
      Parameters:
      lArray - the array of longs to write.
      off - the offset (number of longs) into the lArray at which writing begins.
      len - the number of longs to write.
      f - the RandomAccessFile to which the longs will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • FloatArray

      public static long FloatArray(float[] fArray, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write an array of float values to a OutputStream strm.
      Parameters:
      fArray - the array of floats to write.
      strm - the OutputStream to which the floats will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • FloatArray

      public static long FloatArray(float[] fArray, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of float values to a RandomAccessFile f.
      Parameters:
      fArray - the array of floats to write.
      f - the RandomAccessFile to which the floats will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • FloatArray

      public static long FloatArray(float[] fArray, int off, int len, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of float values to a RandomAccessFile f.
      Parameters:
      fArray - the array of floats to write.
      off - the offset (number of floats) into the fArray at which writing begins.
      len - the number of floats to write.
      f - the RandomAccessFile to which the floats will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • DoubleArray

      public static long DoubleArray(double[] dArray, OutputStream strm, ByteOrder byteOrder) throws IOException
      Write an array of double values to a OutputStream strm.
      Parameters:
      dArray - the array of doubles to write.
      strm - the OutputStream to which the doubles will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if strm had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • DoubleArray

      public static long DoubleArray(double[] dArray, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of double values to a RandomAccessFile f.
      Parameters:
      dArray - the array of doubles to write.
      f - the RandomAccessFile to which the doubles will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.
    • DoubleArray

      public static long DoubleArray(double[] dArray, int off, int len, RandomAccessFile f, ByteOrder byteOrder) throws IOException
      Write an array of double values to a RandomAccessFile f.
      Parameters:
      dArray - the array of doubles to write.
      off - the offset (number of doubles) into the dArray at which writing begins.
      len - the number of doubles to write.
      f - the RandomAccessFile to which the doubles will be written. If strm is null no data are written.
      byteOrder - the ByteOrder of the data in the stream.
      Returns:
      the number of bytes written, or that would have been written if f had not been null.
      Throws:
      IOException - if an error occurs while performing the write.