Class BinaryOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
DicomOutputStream
A class that extends FilterOutputStream by adding
the concept of little and big endian binary value encoding, and supplies functions
for writing various sized integer and floating point words.
- See Also:
-
Field Summary
FieldsFields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongGet the byte offset where the next byte will be written.booleanIs the stream byte order big endian ?booleanIs the stream byte order little endian ?protected voidlocalInit(boolean big) static voidFor testing.voidSet the stream byte order to big endian.voidsetEndian(boolean big) Set the stream byte order to that specified.voidSet the stream byte order to little endian.voidwrite(byte[] b) Writesb.lengthbytes to this output stream.voidwrite(byte[] b, int off, int len) Writeslenbytes from the specified byte array starting at offsetoffto this output stream.voidwrite(int b) Writes the specifiedbyteto this output stream.final voidwriteDouble(double value) Write one floating point 64 bit value.final voidwriteDouble(double[] f, int len) Write an array of floating point 64 bit values.final voidwriteFloat(float value) Write one floating point 32 bit value.final voidwriteFloat(float[] f, int len) Write an array of floating point 32 bit values.final voidwriteSigned16(int v) Write one signed integer 16 bit value.final voidwriteSigned32(long v) Write one signed integer 32 bit value.final voidwriteSigned64(long v) Write one signed integer 64 bit value.final voidwriteUnsigned16(int v) Write one unsigned integer 16 bit value.final voidwriteUnsigned16(short[] w, int len) Write an array of unsigned integer 16 bit values.final voidwriteUnsigned32(int[] w, int len) Write an array of unsigned integer 32 bit values.final voidwriteUnsigned32(long v) Write one unsigned integer 32 bit value.final voidwriteUnsigned64(long v) Write one unsigned integer 64 bit value.final voidwriteUnsigned64(long[] w, int len) Write an array of unsigned integer 64 bit values.final voidwriteUnsigned8(int v) Write one unsigned integer 8 bit value.Methods inherited from class java.io.FilterOutputStream
close, flushMethods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
byteOffset
protected long byteOffset
-
-
Constructor Details
-
BinaryOutputStream
- Parameters:
o- the output streambig- true if big endian, false if little endian
-
-
Method Details
-
getByteOffset
public long getByteOffset()Get the byte offset where the next byte will be written.
Will be zero at the start of the file.
- Returns:
- the byte offset
-
localInit
protected void localInit(boolean big) - Parameters:
big- true if big endian, false if little endian
-
write
Writeslenbytes from the specified byte array starting at offsetoffto this output stream.The
writemethod ofBinaryOutputStreamcalls the corresponding multi-byte write method of one argument of the.OutputStreamsupplied in the constructor, and overrides the default use of multiple calls to the single-byte write method that is the behavior ofFilterOutputStream.The exceptions thrown are whatever is thrown by the
OutputStreamwrite method.- Overrides:
writein classFilterOutputStream- Parameters:
b- the data.off- the start offset in the data.len- the number of bytes to write.- Throws:
IOException- if an I/O error occurs.
-
write
Writes the specifiedbyteto this output stream.- Overrides:
writein classFilterOutputStream- Parameters:
b- thebyte.- Throws:
IOException- if an I/O error occurs.
-
write
Writesb.lengthbytes to this output stream.- Overrides:
writein classFilterOutputStream- Parameters:
b- the data to be written.- Throws:
IOException- if an I/O error occurs.
-
isBigEndian
public boolean isBigEndian()Is the stream byte order big endian ?
- Returns:
- true if big endian, false if little endian
-
isLittleEndian
public boolean isLittleEndian()Is the stream byte order little endian ?
- Returns:
- true if little endian, false if big endian
-
setBigEndian
public void setBigEndian()Set the stream byte order to big endian.
-
setLittleEndian
public void setLittleEndian()Set the stream byte order to little endian.
-
setEndian
public void setEndian(boolean big) Set the stream byte order to that specified.
- Parameters:
big- true if to set to big endian, false if little endian
-
writeUnsigned8
Write one unsigned integer 8 bit value.
- Parameters:
v- an int containing an unsigned value- Throws:
IOException- if an I/O error occurs
-
writeUnsigned16
Write one unsigned integer 16 bit value.
- Parameters:
v- an int containing an unsigned value- Throws:
IOException- if an I/O error occurs
-
writeSigned16
Write one signed integer 16 bit value.
- Parameters:
v- an int containing an signed value- Throws:
IOException- if an I/O error occurs
-
writeUnsigned32
Write one unsigned integer 32 bit value.
- Parameters:
v- a long containing an unsigned value- Throws:
IOException- if an I/O error occurs
-
writeSigned32
Write one signed integer 32 bit value.
- Parameters:
v- a long containing an signed value- Throws:
IOException- if an I/O error occurs
-
writeUnsigned64
Write one unsigned integer 64 bit value.
- Parameters:
v- a long containing an unsigned value- Throws:
IOException- if an I/O error occurs
-
writeSigned64
Write one signed integer 64 bit value.
- Parameters:
v- a long containing a signed value- Throws:
IOException- if an I/O error occurs
-
writeFloat
Write one floating point 32 bit value.
- Parameters:
value- a float value- Throws:
IOException- if an I/O error occurs
-
writeDouble
Write one floating point 64 bit value.
- Parameters:
value- a double value- Throws:
IOException- if an I/O error occurs
-
writeUnsigned16
Write an array of unsigned integer 16 bit values.
- Parameters:
w- an array of integers to writelen- the number of 16 bit values to write- Throws:
IOException- if an I/O error occurs
-
writeUnsigned32
Write an array of unsigned integer 32 bit values.
- Parameters:
w- an array of integers to writelen- the number of 32 bit values to write- Throws:
IOException- if an I/O error occurs
-
writeUnsigned64
Write an array of unsigned integer 64 bit values.
- Parameters:
w- an array of integers to writelen- the number of 64 bit values to write- Throws:
IOException- if an I/O error occurs
-
writeFloat
Write an array of floating point 32 bit values.
- Parameters:
f- an array of floats to writelen- the number of values to write- Throws:
IOException- if an I/O error occurs
-
writeDouble
Write an array of floating point 64 bit values.
- Parameters:
f- an array of floats to writelen- the number of values to write- Throws:
IOException- if an I/O error occurs
-
main
For testing.
- Parameters:
arg- file to write to
-