public class BinaryOutputStream
extends java.io.FilterOutputStream
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.
BinaryInputStream
Modifier and Type | Field and Description |
---|---|
protected long |
byteOffset |
Constructor and Description |
---|
BinaryOutputStream(java.io.OutputStream o,
boolean big) |
Modifier and Type | Method and Description |
---|---|
long |
getByteOffset()
Get the byte offset where the next byte will be written.
|
boolean |
isBigEndian()
Is the stream byte order big endian ?
|
boolean |
isLittleEndian()
Is the stream byte order little endian ?
|
protected void |
localInit(boolean big) |
static void |
main(java.lang.String[] arg)
For testing.
|
void |
setBigEndian()
Set the stream byte order to big endian.
|
void |
setEndian(boolean big)
Set the stream byte order to that specified.
|
void |
setLittleEndian()
Set the stream byte order to little endian.
|
void |
write(byte[] b)
Writes
b.length bytes to this output stream. |
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array
starting at offset off to this output stream. |
void |
write(int b)
Writes the specified
byte to this output stream. |
void |
writeDouble(double value)
Write one floating point 64 bit value.
|
void |
writeDouble(double[] f,
int len)
Write an array of floating point 64 bit values.
|
void |
writeFloat(float value)
Write one floating point 32 bit value.
|
void |
writeFloat(float[] f,
int len)
Write an array of floating point 32 bit values.
|
void |
writeSigned16(int v)
Write one signed integer 16 bit value.
|
void |
writeSigned32(long v)
Write one signed integer 32 bit value.
|
void |
writeSigned64(long v)
Write one signed integer 64 bit value.
|
void |
writeUnsigned16(int v)
Write one unsigned integer 16 bit value.
|
void |
writeUnsigned16(short[] w,
int len)
Write an array of unsigned integer 16 bit values.
|
void |
writeUnsigned32(int[] w,
int len)
Write an array of unsigned integer 32 bit values.
|
void |
writeUnsigned32(long v)
Write one unsigned integer 32 bit value.
|
void |
writeUnsigned64(long v)
Write one unsigned integer 64 bit value.
|
void |
writeUnsigned64(long[] w,
int len)
Write an array of unsigned integer 64 bit values.
|
void |
writeUnsigned8(int v)
Write one unsigned integer 8 bit value.
|
public BinaryOutputStream(java.io.OutputStream o, boolean big)
o
- the output streambig
- true if big endian, false if little endianpublic long getByteOffset()
Get the byte offset where the next byte will be written.
Will be zero at the start of the file.
public boolean isBigEndian()
Is the stream byte order big endian ?
public boolean isLittleEndian()
Is the stream byte order little endian ?
protected void localInit(boolean big)
big
- true if big endian, false if little endianpublic static void main(java.lang.String[] arg)
For testing.
arg
- file to write topublic void setBigEndian()
Set the stream byte order to big endian.
public void setEndian(boolean big)
Set the stream byte order to that specified.
big
- true if to set to big endian, false if little endianpublic void setLittleEndian()
Set the stream byte order to little endian.
public void write(byte[] b) throws java.io.IOException
b.length
bytes to this output stream.write
in class java.io.FilterOutputStream
b
- the data to be written.java.io.IOException
- if an I/O error occurs.public void write(byte[] b, int off, int len) throws java.io.IOException
len
bytes from the specified byte array
starting at offset off
to this output stream.
The write
method of BinaryOutputStream
calls
the corresponding multi-byte write method of one argument of the.
OutputStream
supplied in the constructor, and
overrides the default use of multiple calls to the single-byte
write method that is the behavior of FilterOutputStream
.
The exceptions thrown are whatever is thrown by the OutputStream
write method.
write
in class java.io.FilterOutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.java.io.IOException
- if an I/O error occurs.public void write(int b) throws java.io.IOException
byte
to this output stream.write
in class java.io.FilterOutputStream
b
- the byte
.java.io.IOException
- if an I/O error occurs.public final void writeDouble(double value) throws java.io.IOException
Write one floating point 64 bit value.
value
- a double valuejava.io.IOException
- if an I/O error occurspublic final void writeDouble(double[] f, int len) throws java.io.IOException
Write an array of floating point 64 bit values.
f
- an array of floats to writelen
- the number of values to writejava.io.IOException
- if an I/O error occurspublic final void writeFloat(float value) throws java.io.IOException
Write one floating point 32 bit value.
value
- a float valuejava.io.IOException
- if an I/O error occurspublic final void writeFloat(float[] f, int len) throws java.io.IOException
Write an array of floating point 32 bit values.
f
- an array of floats to writelen
- the number of values to writejava.io.IOException
- if an I/O error occurspublic final void writeSigned16(int v) throws java.io.IOException
Write one signed integer 16 bit value.
v
- an int containing an signed valuejava.io.IOException
- if an I/O error occurspublic final void writeSigned32(long v) throws java.io.IOException
Write one signed integer 32 bit value.
v
- a long containing an signed valuejava.io.IOException
- if an I/O error occurspublic final void writeSigned64(long v) throws java.io.IOException
Write one signed integer 64 bit value.
v
- a long containing a signed valuejava.io.IOException
- if an I/O error occurspublic final void writeUnsigned16(int v) throws java.io.IOException
Write one unsigned integer 16 bit value.
v
- an int containing an unsigned valuejava.io.IOException
- if an I/O error occurspublic final void writeUnsigned16(short[] w, int len) throws java.io.IOException
Write an array of unsigned integer 16 bit values.
w
- an array of integers to writelen
- the number of 16 bit values to writejava.io.IOException
- if an I/O error occurspublic final void writeUnsigned32(int[] w, int len) throws java.io.IOException
Write an array of unsigned integer 32 bit values.
w
- an array of integers to writelen
- the number of 32 bit values to writejava.io.IOException
- if an I/O error occurspublic final void writeUnsigned32(long v) throws java.io.IOException
Write one unsigned integer 32 bit value.
v
- a long containing an unsigned valuejava.io.IOException
- if an I/O error occurspublic final void writeUnsigned64(long v) throws java.io.IOException
Write one unsigned integer 64 bit value.
v
- a long containing an unsigned valuejava.io.IOException
- if an I/O error occurspublic final void writeUnsigned64(long[] w, int len) throws java.io.IOException
Write an array of unsigned integer 64 bit values.
w
- an array of integers to writelen
- the number of 64 bit values to writejava.io.IOException
- if an I/O error occurspublic final void writeUnsigned8(int v) throws java.io.IOException
Write one unsigned integer 8 bit value.
v
- an int containing an unsigned valuejava.io.IOException
- if an I/O error occurs