Class BufferedDataOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.BufferedOutputStream
nom.tam.util.BufferedDataOutputStream
- All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable, ArrayDataOutput, FitsIO
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 Summary
FieldsFields inherited from class BufferedOutputStream
buf, countFields inherited from class FilterOutputStream
outFields inherited from interface FitsIO
BITS_OF_1_BYTE, BITS_OF_2_BYTES, BITS_OF_3_BYTES, BITS_OF_4_BYTES, BITS_OF_5_BYTES, BITS_OF_6_BYTES, BITS_OF_7_BYTES, BYTE_1_OF_LONG_MASK, BYTE_2_OF_LONG_MASK, BYTE_3_OF_LONG_MASK, BYTE_4_OF_LONG_MASK, BYTE_MASK, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_FLOAT, BYTES_IN_INTEGER, BYTES_IN_LONG, BYTES_IN_SHORT, DEFAULT_BUFFER_SIZE, HIGH_INTEGER_MASK, INTEGER_MASK, SHORT_MASK, SHORT_OF_LONG_MASK -
Constructor Summary
ConstructorsConstructorDescriptionUse the BufferedOutputStream constructorBufferedDataOutputStream(OutputStream o, int bufLength) Use the BufferedOutputStream constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckBuf(int need) See if there is enough space to add something to the buffer.voidwrite(boolean[] b) Write an array of boolean's.voidwrite(boolean[] b, int start, int length) Write a segment of an array of boolean's.voidwrite(char[] c) Write an array of char's.voidwrite(char[] c, int start, int length) Write a segment of an array of char's.voidwrite(double[] d) Write an array of double's.voidwrite(double[] d, int start, int length) Write a segment of an array of double's.voidwrite(float[] f) Write an array of float's.voidwrite(float[] f, int start, int length) Write a segment of an array of float's.voidwrite(int[] i) Write an array of int's.voidwrite(int[] i, int start, int length) Write a segment of an array of int's.voidwrite(long[] l) Write an array of longs.voidwrite(long[] l, int start, int length) Write a segment of an array of longs.voidwrite(short[] s) Write an array of shorts.voidwrite(short[] s, int start, int length) Write a segment of an array of shorts.voidWrite an array of Strings.voidWrite a segment of an array of Strings.voidwriteArray(Object o) This routine provides efficient writing of arrays of any primitive type.voidwriteBoolean(boolean b) voidwriteByte(int b) voidwriteBytes(String s) voidwriteChar(int c) voidwriteChars(String s) voidwriteDouble(double d) voidwriteFloat(float f) voidwriteInt(int i) voidwriteLong(long l) voidDeprecated.voidwriteShort(int s) Write a short value.voidMethods inherited from class BufferedOutputStream
flush, write, writeMethods inherited from class FilterOutputStream
close, writeMethods inherited from class OutputStream
nullOutputStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ArrayDataOutput
flushMethods inherited from interface DataOutput
write, write, write
-
Field Details
-
bufferPointer
-
bufferEncoder
-
-
Constructor Details
-
BufferedDataOutputStream
Use the BufferedOutputStream constructor- Parameters:
o- An open output stream.
-
BufferedDataOutputStream
Use the BufferedOutputStream constructor- Parameters:
o- An open output stream.bufLength- The buffer size.
-
-
Method Details
-
checkBuf
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
Description copied from interface:ArrayDataOutputWrite an array of boolean's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
b- array of boolean's.- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of boolean's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
b- array of boolean's.start- start index in the arraylength- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite an array of char's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
c- array of char's.- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of char's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
c- array of char's.start- start index in the arraylength- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite an array of double's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
d- array of double's.- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of double's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
d- array of double's.start- start index in the arraylength- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite an array of float's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
f- array of float's.- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of float's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
f- array of float's.start- start index in the arraylength- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite an array of int's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
i- array of int's- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of int's.- Specified by:
writein interfaceArrayDataOutput- Parameters:
i- array of int'sstart- start index in the arraylength- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite an array of longs.- Specified by:
writein interfaceArrayDataOutput- Parameters:
l- array of longs- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of longs.- Specified by:
writein interfaceArrayDataOutput- Parameters:
l- array of longsstart- start index in the arraylength- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite an array of shorts.- Specified by:
writein interfaceArrayDataOutput- Parameters:
s- the value to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of shorts.- Specified by:
writein interfaceArrayDataOutput- Parameters:
s- the value to writestart- start index in the arraylength- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite an array of Strings. Equivalent to calling writeBytes for the selected elements.- Specified by:
writein interfaceArrayDataOutput- Parameters:
s- the array to write- Throws:
IOException- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutputWrite a segment of an array of Strings. Equivalent to calling writeBytes for the selected elements.- Specified by:
writein interfaceArrayDataOutput- Parameters:
s- the array to writestart- start index in the arraylen- number of array elements to write- Throws:
IOException- if one of the underlying write operations failed
-
writeArray
Description copied from interface:ArrayDataOutputThis 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:
writeArrayin interfaceArrayDataOutput- 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
- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeBytes
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChar
- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeChars
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeDouble
- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeFloat
- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeInt
- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writePrimitiveArray
Deprecated.usewriteArray(Object)insteadDeprecated usewriteArray(Object).- Parameters:
o- The object to be written.- Throws:
IOException- if one of the underlying write operations failed
-
writeShort
Write a short value.- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeUTF
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
writeArray(Object)instead