Package nom.tam.util
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
Fields inherited from class java.io.BufferedOutputStream
buf, count
Fields inherited from class java.io.FilterOutputStream
out
Fields inherited from interface nom.tam.util.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 void
checkBuf
(int need) See if there is enough space to add something to the buffer.void
write
(boolean[] b) Write an array of boolean's.void
write
(boolean[] b, int start, int length) Write a segment of an array of boolean's.void
write
(char[] c) Write an array of char's.void
write
(char[] c, int start, int length) Write a segment of an array of char's.void
write
(double[] d) Write an array of double's.void
write
(double[] d, int start, int length) Write a segment of an array of double's.void
write
(float[] f) Write an array of float's.void
write
(float[] f, int start, int length) Write a segment of an array of float's.void
write
(int[] i) Write an array of int's.void
write
(int[] i, int start, int length) Write a segment of an array of int's.void
write
(long[] l) Write an array of longs.void
write
(long[] l, int start, int length) Write a segment of an array of longs.void
write
(short[] s) Write an array of shorts.void
write
(short[] s, int start, int length) Write a segment of an array of shorts.void
Write an array of Strings.void
Write a segment of an array of Strings.void
writeArray
(Object o) This routine provides efficient writing of arrays of any primitive type.void
writeBoolean
(boolean b) void
writeByte
(int b) void
writeBytes
(String s) void
writeChar
(int c) void
writeChars
(String s) void
writeDouble
(double d) void
writeFloat
(float f) void
writeInt
(int i) void
writeLong
(long l) void
Deprecated.void
writeShort
(int s) Write a short value.void
Methods inherited from class java.io.BufferedOutputStream
flush, write, write
Methods inherited from class java.io.FilterOutputStream
close, write
Methods inherited from class java.io.OutputStream
nullOutputStream
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface nom.tam.util.ArrayDataOutput
flush
Methods inherited from interface java.io.DataOutput
write, write, write
-
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:ArrayDataOutput
Write an array of boolean's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
b
- array of boolean's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of boolean's.- Specified by:
write
in 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:ArrayDataOutput
Write an array of char's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
c
- array of char's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of char's.- Specified by:
write
in 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:ArrayDataOutput
Write an array of double's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
d
- array of double's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of double's.- Specified by:
write
in 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:ArrayDataOutput
Write an array of float's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
f
- array of float's.- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of float's.- Specified by:
write
in 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:ArrayDataOutput
Write an array of int's.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
i
- array of int's- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of int's.- Specified by:
write
in 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:ArrayDataOutput
Write an array of longs.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
l
- array of longs- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of longs.- Specified by:
write
in 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:ArrayDataOutput
Write an array of shorts.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
s
- the value to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
Description copied from interface:ArrayDataOutput
Write a segment of an array of shorts.- Specified by:
write
in 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:ArrayDataOutput
Write an array of Strings. Equivalent to calling writeBytes for the selected elements.- Specified by:
write
in interfaceArrayDataOutput
- Parameters:
s
- the array to write- Throws:
IOException
- if one of the underlying write operations failed
-
write
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 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: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 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:
writeBoolean
in interfaceDataOutput
- Throws:
IOException
-
writeByte
- Specified by:
writeByte
in interfaceDataOutput
- Throws:
IOException
-
writeBytes
- Specified by:
writeBytes
in interfaceDataOutput
- Throws:
IOException
-
writeChar
- Specified by:
writeChar
in interfaceDataOutput
- Throws:
IOException
-
writeChars
- Specified by:
writeChars
in interfaceDataOutput
- Throws:
IOException
-
writeDouble
- Specified by:
writeDouble
in interfaceDataOutput
- Throws:
IOException
-
writeFloat
- Specified by:
writeFloat
in interfaceDataOutput
- Throws:
IOException
-
writeInt
- Specified by:
writeInt
in interfaceDataOutput
- Throws:
IOException
-
writeLong
- Specified by:
writeLong
in 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:
writeShort
in interfaceDataOutput
- Throws:
IOException
-
writeUTF
- Specified by:
writeUTF
in interfaceDataOutput
- Throws:
IOException
-
writeArray(Object)
instead