public class BinaryInputStream extends FilterInputStream
A class that extends FilterInputStream by adding
the concept of little and big endian binary value encoding, and supplies functions
for reading various sized integer and floating point words.
BinaryOutputStreamin| Constructor and Description |
|---|
BinaryInputStream(File file,
boolean big)
Construct a byte ordered stream from the supplied file.
|
BinaryInputStream(InputStream i,
boolean big)
Construct a byte ordered stream from the supplied stream.
|
| Modifier and Type | Method and Description |
|---|---|
File |
getFile()
Get the file associated with this stream.
|
boolean |
isBigEndian()
Is the stream byte order big endian ?
|
boolean |
isLittleEndian()
Is the stream byte order little endian ?
|
static void |
main(String[] arg)
For testing.
|
void |
readComplexDouble(double[] freal,
double[] fimaginary,
int len)
Read interleaved complex floating point 64 bit value pairs into real and imaginary arrays.
|
void |
readComplexFloat(float[] freal,
float[] fimaginary,
int len)
Read interleaved complex floating point 32 bit value pairs into real and imaginary arrays.
|
double |
readDouble()
Read one floating point 64 bit value.
|
void |
readDouble(double[] f,
int len)
Read an array of floating point 64 bit values.
|
float |
readFloat()
Read one floating point 32 bit value.
|
void |
readFloat(float[] f,
int len)
Read an array of floating point 32 bit values.
|
void |
readInsistently(byte[] b,
int offset,
int length)
Read as many bytes as requested, unless an exception occurs.
|
int |
readSigned16()
Read one signed integer 16 bit value.
|
int |
readSigned32()
Read one signed integer 32 bit value.
|
long |
readSigned64()
Read one signed integer 64 bit value.
|
int |
readUnsigned16()
Read one unsigned integer 16 bit value.
|
void |
readUnsigned16(short[] w,
int len)
Read an array of unsigned integer 16 bit values.
|
void |
readUnsigned16(short[] w,
int offset,
int len)
Read an array of unsigned integer 16 bit values.
|
long |
readUnsigned32()
Read one unsigned integer 32 bit value.
|
void |
readUnsigned32(int[] w,
int len)
Read an array of unsigned integer 32 bit values.
|
void |
readUnsigned32(int[] w,
int offset,
int len)
Read an array of unsigned integer 32 bit values.
|
long |
readUnsigned64()
Read one unsigned integer 64 bit value.
|
void |
readUnsigned64(long[] w,
int len)
Read an array of unsigned integer 64 bit values.
|
void |
readUnsigned64(long[] w,
int offset,
int len)
Read an array of unsigned integer 64 bit values.
|
int |
readUnsigned8()
Read one unsigned integer 8 bit value.
|
void |
setBigEndian()
Set the stream byte order to big endian.
|
void |
setEndian(boolean big)
Set the stream byte order to that specified.
|
void |
setFile(File file)
Set the file associated with this stream.
|
void |
setLittleEndian()
Set the stream byte order to little endian.
|
void |
skipInsistently(long length)
Skip as many bytes as requested, unless an exception occurs.
|
available, close, mark, markSupported, read, read, read, reset, skippublic BinaryInputStream(File file, boolean big) throws FileNotFoundException
Construct a byte ordered stream from the supplied file.
The byte order may be changed later.
file - the file to read frombig - true if big endian, false if little endianFileNotFoundException - if file is not foundpublic BinaryInputStream(InputStream i, boolean big)
Construct a byte ordered stream from the supplied stream.
The byte order may be changed later.
i - the input stream to read frombig - true if big endian, false if little endianpublic File getFile()
Get the file associated with this stream.
public boolean isBigEndian()
Is the stream byte order big endian ?
public boolean isLittleEndian()
Is the stream byte order little endian ?
public static void main(String[] arg)
For testing.
arg - file to read frompublic final void readComplexDouble(double[] freal,
double[] fimaginary,
int len)
throws IOException
Read interleaved complex floating point 64 bit value pairs into real and imaginary arrays.
freal - an array of sufficient size in which to return the real values read, may be null if don't want real valuesfimaginary - an array of sufficient size in which to return the real values read, may be null if don't want imaginary valueslen - the number of 64 bit values to readIOException - if an I/O error occurspublic final void readComplexFloat(float[] freal,
float[] fimaginary,
int len)
throws IOException
Read interleaved complex floating point 32 bit value pairs into real and imaginary arrays.
freal - an array of sufficient size in which to return the real values read, may be null if don't want real valuesfimaginary - an array of sufficient size in which to return the real values read, may be null if don't want imaginary valueslen - the number of 32 bit values to readIOException - if an I/O error occurspublic final double readDouble()
throws IOException
Read one floating point 64 bit value.
IOException - if an I/O error occurspublic final void readDouble(double[] f,
int len)
throws IOException
Read an array of floating point 64 bit values.
f - an array of sufficient size in which to return the values readlen - the number of 64 bit values to readIOException - if an I/O error occurspublic final float readFloat()
throws IOException
Read one floating point 32 bit value.
IOException - if an I/O error occurspublic final void readFloat(float[] f,
int len)
throws IOException
Read an array of floating point 32 bit values.
f - an array of sufficient size in which to return the values readlen - the number of 32 bit values to readIOException - if an I/O error occurspublic void readInsistently(byte[] b,
int offset,
int length)
throws IOException
Read as many bytes as requested, unless an exception occurs.
b - buffer to read intooffset - offset (from 0) in buffer to read intolength - number of bytes to read (no more and no less)IOException - if an I/O error occurspublic final int readSigned16()
throws IOException
Read one signed integer 16 bit value.
IOException - if an I/O error occurspublic final int readSigned32()
throws IOException
Read one signed integer 32 bit value.
IOException - if an I/O error occurspublic final long readSigned64()
throws IOException
Read one signed integer 64 bit value.
IOException - if an I/O error occurspublic final int readUnsigned16()
throws IOException
Read one unsigned integer 16 bit value.
IOException - if an I/O error occurspublic final void readUnsigned16(short[] w,
int len)
throws IOException
Read an array of unsigned integer 16 bit values.
w - an array of sufficient size in which to return the values readlen - the number of 16 bit values to readIOException - if an I/O error occurspublic final void readUnsigned16(short[] w,
int offset,
int len)
throws IOException
Read an array of unsigned integer 16 bit values.
w - an array of sufficient size in which to return the values readoffset - the offset in the array at which to begin storing valueslen - the number of 16 bit values to readIOException - if an I/O error occurspublic final long readUnsigned32()
throws IOException
Read one unsigned integer 32 bit value.
IOException - if an I/O error occurspublic final void readUnsigned32(int[] w,
int len)
throws IOException
Read an array of unsigned integer 32 bit values.
w - an array of sufficient size in which to return the values readlen - the number of 32 bit values to readIOException - if an I/O error occurspublic final void readUnsigned32(int[] w,
int offset,
int len)
throws IOException
Read an array of unsigned integer 32 bit values.
w - an array of sufficient size in which to return the values readoffset - the offset in the array at which to begin storing valueslen - the number of 32 bit values to readIOException - if an I/O error occurspublic final long readUnsigned64()
throws IOException
Read one unsigned integer 64 bit value.
IOException - if an I/O error occurspublic final void readUnsigned64(long[] w,
int len)
throws IOException
Read an array of unsigned integer 64 bit values.
w - an array of sufficient size in which to return the values readlen - the number of 64 bit values to readIOException - if an I/O error occurspublic final void readUnsigned64(long[] w,
int offset,
int len)
throws IOException
Read an array of unsigned integer 64 bit values.
w - an array of sufficient size in which to return the values readoffset - the offset in the array at which to begin storing valueslen - the number of 64 bit values to readIOException - if an I/O error occurspublic final int readUnsigned8()
throws IOException
Read one unsigned integer 8 bit value.
IOException - if an I/O error occurspublic 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 setFile(File file)
Set the file associated with this stream.
This may be used if constructed with a constructor that does not supply a File parameter, e.g., has been indirected through a BufferedInputStream.
file - the file associated with this stream, or null if not a file input streampublic void setLittleEndian()
Set the stream byte order to little endian.
public void skipInsistently(long length)
throws IOException
Skip as many bytes as requested, unless an exception occurs.
length - number of bytes to read (no more and no less)IOException - if an I/O error occurs