## nom.tam.util
Class BufferedDataOutputStream

    java.lang.Object
      java.io.OutputStream
          java.io.FilterOutputStream
              java.io.BufferedOutputStream
                  nom.tam.util.BufferedDataOutputStream

All Implemented Interfaces:
  DataOutput

public class BufferedDataOutputStream
extends BufferedOutputStream
implements DataOutput

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. One routine is added to the public interface of DataOutput, writePrimitiveArray. This routine provides efficient protocols for writing arrays. Note that there is substantial duplication of code to minimize method invocations.

Field Summary

Fields inherited from class java.io.BufferedOutputStream
`buf, count`

Fields inherited from class java.io.FilterOutputStream
`out`

Constructor Summary
`BufferedDataOutputStream(OutputStream o)` Use the BufferedOutputStream constructor
`BufferedDataOutputStream(OutputStream o, int bufLength)` Use the BufferedOutputStream constructor

Method Summary
`static void` `main(String[] args)` Test this class
`void` `writeBoolean(boolean b)` Write a boolean value
`protected void` `writeBooleanArray(boolean[] b)` Write an array of booleans.
`void` `writeByte(int b)` Write a byte value.
`void` `writeBytes(String s)` Write a string using the local protocol to convert char's to bytes.
`void` `writeChar(int c)` Write a char value.
`protected void` `writeCharArray(char[] c)` Write an array of char's.
`void` `writeChars(String s)` Write a string as an array of chars.
`void` `writeDouble(double d)` Write a double value.
`protected void` `writeDoubleArray(double[] d)` Write an array of doubles.
`void` `writeFloat(float f)` Write a float value.
`protected void` `writeFloatArray(float[] f)` Write an array of floats.
`void` `writeInt(int i)` Write an integer value.
`protected void` `writeIntArray(int[] i)` Write an array of int's.
`void` `writeLong(long l)` Write a long value.
`protected void` `writeLongArray(long[] l)` Write an array of longs.
`void` `writePrimitiveArray(Object o)` This routine provides efficient writing of arrays of any primitive type.
`void` `writeShort(int s)` Write a short value.
`protected void` `writeShortArray(short[] s)` Write an array of shorts.
`protected void` `writeStringArray(String[] s)` Write an array of Strings -- equivalent to calling writeBytes for each string.
`void` `writeUTF(String s)` Write a string as a UTF.

Methods inherited from class java.io.BufferedOutputStream
`flush, write, write`

Methods inherited from class java.io.FilterOutputStream
`close, write`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface java.io.DataOutput
`write, write, write`

Constructor Detail

### 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 Detail

### writeBoolean

    public void writeBoolean(boolean b)
                      throws IOException

  Write a boolean value

  Specified by:
    `writeBoolean` in interface `DataOutput`
  Parameters:
    `b` - The value to be written. Externally true is represented as a byte of 1 and false as a byte value of 0.
  Throws:
    `IOException`

### writeByte

    public void writeByte(int b)
                   throws IOException

  Write a byte value.

  Specified by:
    `writeByte` in interface `DataOutput`
  Throws:
    `IOException`

### writeInt

    public void writeInt(int i)
                  throws IOException

  Write an integer value.

  Specified by:
    `writeInt` in interface `DataOutput`
  Throws:
    `IOException`

### writeShort

    public void writeShort(int s)
                    throws IOException

  Write a short value.

  Specified by:
    `writeShort` in interface `DataOutput`
  Throws:
    `IOException`

### writeChar

    public void writeChar(int c)
                   throws IOException

  Write a char value.

  Specified by:
    `writeChar` in interface `DataOutput`
  Throws:
    `IOException`

### writeLong

    public void writeLong(long l)
                   throws IOException

  Write a long value.

  Specified by:
    `writeLong` in interface `DataOutput`
  Throws:
    `IOException`

### writeFloat

    public void writeFloat(float f)
                    throws IOException

  Write a float value.

  Specified by:
    `writeFloat` in interface `DataOutput`
  Throws:
    `IOException`

### writeDouble

    public void writeDouble(double d)
                     throws IOException

  Write a double value.

  Specified by:
    `writeDouble` in interface `DataOutput`
  Throws:
    `IOException`

### writeBytes

    public void writeBytes(String s)
                    throws IOException

  Write a string using the local protocol to convert char's to bytes.

  Specified by:
    `writeBytes` in interface `DataOutput`
  Parameters:
    `s` - The string to be written.
  Throws:
    `IOException`

### writeChars

    public void writeChars(String s)
                    throws IOException

  Write a string as an array of chars.

  Specified by:
    `writeChars` in interface `DataOutput`
  Throws:
    `IOException`

### writeUTF

    public void writeUTF(String s)
                  throws IOException

  Write a string as a UTF. Note that this class does not handle this situation efficiently since it creates new DataOutputStream to handle each call.

  Specified by:
    `writeUTF` in interface `DataOutput`
  Throws:
    `IOException`

### writePrimitiveArray

    public void writePrimitiveArray(Object o)
                             throws IOException

  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.

  Parameters:
    `o` - The object to be written. It must be an array of a primitive type, Object, or String.
  Throws:
    `IOException`

### writeBooleanArray

    protected void writeBooleanArray(boolean[] b)
                              throws IOException

  Write an array of booleans.

  Throws:
    `IOException`

### writeShortArray

    protected void writeShortArray(short[] s)
                            throws IOException

  Write an array of shorts.

  Throws:
    `IOException`

### writeCharArray

    protected void writeCharArray(char[] c)
                           throws IOException

  Write an array of char's.

  Throws:
    `IOException`

### writeIntArray

    protected void writeIntArray(int[] i)
                          throws IOException

  Write an array of int's.

  Throws:
    `IOException`

### writeLongArray

    protected void writeLongArray(long[] l)
                           throws IOException

  Write an array of longs.

  Throws:
    `IOException`

### writeFloatArray

    protected void writeFloatArray(float[] f)
                            throws IOException

  Write an array of floats.

  Throws:
    `IOException`

### writeDoubleArray

    protected void writeDoubleArray(double[] d)
                             throws IOException

  Write an array of doubles.

  Throws:
    `IOException`

### writeStringArray

    protected void writeStringArray(String[] s)
                             throws IOException

  Write an array of Strings -- equivalent to calling writeBytes for each string.

  Throws:
    `IOException`

### main

    public static void main(String[] args)
                     throws Exception

  Test this class

  Throws:
    `Exception`