Package nom.tam.util

Class BufferedDataOutputStream

All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable, ArrayDataOutput, FitsIO

public class BufferedDataOutputStream extends BufferedOutputStream implements ArrayDataOutput
This class is intended for high performance I/O in scientific applications. It combines the functionality of the BufferedOutputStream and the DataOutputStream as well as more efficient handling of arrays. This minimizes the number of method calls that are required to write data. Informal tests of this method show that it can be as much as 10 times faster than using a DataOutputStream layered on a BufferedOutputStream for writing large arrays. The performance gain on scalars or small arrays will be less but there should probably never be substantial degradation of performance.

Note that there is substantial duplication of code to minimize method invocations. However simple output methods were used where empirical tests seemed to indicate that the simpler method did not cost any time. It seems likely that most of these variations will be washed out across different compilers and users who wish to tune the method for their particular system may wish to compare the the implementation of write(int[], int, int) with write(float[], int, int).

Testing and timing for this class is performed in the nom.tam.util.test.BufferedFileTester class.

  • Field Details

  • Constructor Details

    • BufferedDataOutputStream

      public BufferedDataOutputStream(OutputStream o)
      Use the BufferedOutputStream constructor
      Parameters:
      o - An open output stream.
    • BufferedDataOutputStream

      public BufferedDataOutputStream(OutputStream o, int bufLength)
      Use the BufferedOutputStream constructor
      Parameters:
      o - An open output stream.
      bufLength - The buffer size.
  • Method Details

    • checkBuf

      protected void checkBuf(int need) throws IOException
      See if there is enough space to add something to the buffer.
      Parameters:
      need - the number of bytes that should be available in the buffer.
      Throws:
      IOException - if the underlying write operation fails
    • write

      public void write(boolean[] b) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of boolean's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      b - array of boolean's.
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(boolean[] b, int start, int length) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of boolean's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      b - array of boolean's.
      start - start index in the array
      length - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(char[] c) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of char's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      c - array of char's.
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(char[] c, int start, int length) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of char's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      c - array of char's.
      start - start index in the array
      length - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(double[] d) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of double's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      d - array of double's.
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(double[] d, int start, int length) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of double's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      d - array of double's.
      start - start index in the array
      length - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(float[] f) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of float's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      f - array of float's.
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(float[] f, int start, int length) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of float's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      f - array of float's.
      start - start index in the array
      length - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(int[] i) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of int's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      i - array of int's
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(int[] i, int start, int length) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of int's.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      i - array of int's
      start - start index in the array
      length - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(long[] l) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of longs.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      l - array of longs
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(long[] l, int start, int length) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of longs.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      l - array of longs
      start - start index in the array
      length - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(short[] s) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of shorts.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      s - the value to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(short[] s, int start, int length) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of shorts.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      s - the value to write
      start - start index in the array
      length - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(String[] s) throws IOException
      Description copied from interface: ArrayDataOutput
      Write an array of Strings. Equivalent to calling writeBytes for the selected elements.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      s - the array to write
      Throws:
      IOException - if one of the underlying write operations failed
    • write

      public void write(String[] s, int start, int len) throws IOException
      Description copied from interface: ArrayDataOutput
      Write a segment of an array of Strings. Equivalent to calling writeBytes for the selected elements.
      Specified by:
      write in interface ArrayDataOutput
      Parameters:
      s - the array to write
      start - start index in the array
      len - number of array elements to write
      Throws:
      IOException - if one of the underlying write operations failed
    • writeArray

      public void writeArray(Object o) throws IOException
      Description copied from interface: ArrayDataOutput
      This routine provides efficient writing of arrays of any primitive type. The String class is also handled but it is an error to invoke this method with an object that is not an array of these types. If the array is multidimensional, then it calls itself recursively to write the entire array. Strings are written using the standard 1 byte format (i.e., as in writeBytes). If the array is an array of objects, then writePrimitiveArray will be called for each element of the array.
      Specified by:
      writeArray in interface ArrayDataOutput
      Parameters:
      o - The object to be written. It must be an array of a primitive type, Object, or String.
      Throws:
      IOException - if one of the underlying write operations failed
    • writeBoolean

      public void writeBoolean(boolean b) throws IOException
      Specified by:
      writeBoolean in interface DataOutput
      Throws:
      IOException
    • writeByte

      public void writeByte(int b) throws IOException
      Specified by:
      writeByte in interface DataOutput
      Throws:
      IOException
    • writeBytes

      public void writeBytes(String s) throws IOException
      Specified by:
      writeBytes in interface DataOutput
      Throws:
      IOException
    • writeChar

      public void writeChar(int c) throws IOException
      Specified by:
      writeChar in interface DataOutput
      Throws:
      IOException
    • writeChars

      public void writeChars(String s) throws IOException
      Specified by:
      writeChars in interface DataOutput
      Throws:
      IOException
    • writeDouble

      public void writeDouble(double d) throws IOException
      Specified by:
      writeDouble in interface DataOutput
      Throws:
      IOException
    • writeFloat

      public void writeFloat(float f) throws IOException
      Specified by:
      writeFloat in interface DataOutput
      Throws:
      IOException
    • writeInt

      public void writeInt(int i) throws IOException
      Specified by:
      writeInt in interface DataOutput
      Throws:
      IOException
    • writeLong

      public void writeLong(long l) throws IOException
      Specified by:
      writeLong in interface DataOutput
      Throws:
      IOException
    • writePrimitiveArray

      @Deprecated public void writePrimitiveArray(Object o) throws IOException
      Deprecated.
      use writeArray(Object) instead
      Deprecated use writeArray(Object).
      Parameters:
      o - The object to be written.
      Throws:
      IOException - if one of the underlying write operations failed
    • writeShort

      public void writeShort(int s) throws IOException
      Write a short value.
      Specified by:
      writeShort in interface DataOutput
      Throws:
      IOException
    • writeUTF

      public void writeUTF(String s) throws IOException
      Specified by:
      writeUTF in interface DataOutput
      Throws:
      IOException