Class BinaryInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- com.pixelmed.dicom.BinaryInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
DicomInputStream
public class BinaryInputStream extends java.io.FilterInputStreamA class that extends
FilterInputStreamby adding the concept of little and big endian binary value encoding, and supplies functions for reading various sized integer and floating point words.- See Also:
BinaryOutputStream
-
-
Constructor Summary
Constructors Constructor Description BinaryInputStream(java.io.File file, boolean big)Construct a byte ordered stream from the supplied file.BinaryInputStream(java.io.InputStream i, boolean big)Construct a byte ordered stream from the supplied stream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.FilegetFile()Get the file associated with this stream.booleanisBigEndian()Is the stream byte order big endian ?booleanisLittleEndian()Is the stream byte order little endian ?static voidmain(java.lang.String[] arg)For testing.voidreadComplexDouble(double[] freal, double[] fimaginary, int len)Read interleaved complex floating point 64 bit value pairs into real and imaginary arrays.voidreadComplexFloat(float[] freal, float[] fimaginary, int len)Read interleaved complex floating point 32 bit value pairs into real and imaginary arrays.doublereadDouble()Read one floating point 64 bit value.voidreadDouble(double[] f, int len)Read an array of floating point 64 bit values.floatreadFloat()Read one floating point 32 bit value.voidreadFloat(float[] f, int len)Read an array of floating point 32 bit values.voidreadInsistently(byte[] b, int offset, int length)Read as many bytes as requested, unless an exception occurs.intreadSigned16()Read one signed integer 16 bit value.intreadSigned32()Read one signed integer 32 bit value.longreadSigned64()Read one signed integer 64 bit value.intreadUnsigned16()Read one unsigned integer 16 bit value.voidreadUnsigned16(short[] w, int len)Read an array of unsigned integer 16 bit values.voidreadUnsigned16(short[] w, int offset, int len)Read an array of unsigned integer 16 bit values.longreadUnsigned32()Read one unsigned integer 32 bit value.voidreadUnsigned32(int[] w, int len)Read an array of unsigned integer 32 bit values.voidreadUnsigned32(int[] w, int offset, int len)Read an array of unsigned integer 32 bit values.longreadUnsigned64()Read one unsigned integer 64 bit value.voidreadUnsigned64(long[] w, int len)Read an array of unsigned integer 64 bit values.voidreadUnsigned64(long[] w, int offset, int len)Read an array of unsigned integer 64 bit values.intreadUnsigned8()Read one unsigned integer 8 bit value.voidsetBigEndian()Set the stream byte order to big endian.voidsetEndian(boolean big)Set the stream byte order to that specified.voidsetFile(java.io.File file)Set the file associated with this stream.voidsetLittleEndian()Set the stream byte order to little endian.voidskipInsistently(long length)Skip as many bytes as requested, unless an exception occurs.-
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skip
-
-
-
-
Constructor Detail
-
BinaryInputStream
public BinaryInputStream(java.io.File file, boolean big) throws java.io.FileNotFoundExceptionConstruct a byte ordered stream from the supplied file.
The byte order may be changed later.
- Parameters:
file- the file to read frombig- true if big endian, false if little endian- Throws:
java.io.FileNotFoundException- if file is not found
-
BinaryInputStream
public BinaryInputStream(java.io.InputStream i, boolean big)Construct a byte ordered stream from the supplied stream.
The byte order may be changed later.
- Parameters:
i- the input stream to read frombig- true if big endian, false if little endian
-
-
Method Detail
-
getFile
public java.io.File getFile()
Get the file associated with this stream.
- Returns:
- file the file, or null if not a file input stream
-
setFile
public void setFile(java.io.File file)
Set the file associated with this stream.
This may be used if constructed with a constructor that does not supply a
Fileparameter, e.g., has been indirected through aBufferedInputStream.- Parameters:
file- the file associated with this stream, or null if not a file input stream
-
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
-
readInsistently
public void readInsistently(byte[] b, int offset, int length) throws java.io.IOExceptionRead as many bytes as requested, unless an exception occurs.
- Parameters:
b- buffer to read intooffset- offset (from 0) in buffer to read intolength- number of bytes to read (no more and no less)- Throws:
java.io.IOException- if an I/O error occurs
-
skipInsistently
public void skipInsistently(long length) throws java.io.IOExceptionSkip as many bytes as requested, unless an exception occurs.
- Parameters:
length- number of bytes to read (no more and no less)- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned8
public final int readUnsigned8() throws java.io.IOExceptionRead one unsigned integer 8 bit value.
- Returns:
- an int containing an unsigned value
- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned16
public final int readUnsigned16() throws java.io.IOExceptionRead one unsigned integer 16 bit value.
- Returns:
- an int containing an unsigned value
- Throws:
java.io.IOException- if an I/O error occurs
-
readSigned16
public final int readSigned16() throws java.io.IOExceptionRead one signed integer 16 bit value.
- Returns:
- an int containing an unsigned value
- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned32
public final long readUnsigned32() throws java.io.IOExceptionRead one unsigned integer 32 bit value.
- Returns:
- a long containing an unsigned value
- Throws:
java.io.IOException- if an I/O error occurs
-
readSigned32
public final int readSigned32() throws java.io.IOExceptionRead one signed integer 32 bit value.
- Returns:
- an int containing an signed value
- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned64
public final long readUnsigned64() throws java.io.IOExceptionRead one unsigned integer 64 bit value.
- Returns:
- a long containing an unsigned value
- Throws:
java.io.IOException- if an I/O error occurs
-
readSigned64
public final long readSigned64() throws java.io.IOExceptionRead one signed integer 64 bit value.
- Returns:
- a long containing an signed value
- Throws:
java.io.IOException- if an I/O error occurs
-
readFloat
public final float readFloat() throws java.io.IOExceptionRead one floating point 32 bit value.
- Returns:
- a float value
- Throws:
java.io.IOException- if an I/O error occurs
-
readDouble
public final double readDouble() throws java.io.IOExceptionRead one floating point 64 bit value.
- Returns:
- a double value
- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned16
public final void readUnsigned16(short[] w, int len) throws java.io.IOExceptionRead an array of unsigned integer 16 bit values.
- Parameters:
w- an array of sufficient size in which to return the values readlen- the number of 16 bit values to read- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned16
public final void readUnsigned16(short[] w, int offset, int len) throws java.io.IOExceptionRead an array of unsigned integer 16 bit values.
- Parameters:
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 read- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned32
public final void readUnsigned32(int[] w, int len) throws java.io.IOExceptionRead an array of unsigned integer 32 bit values.
- Parameters:
w- an array of sufficient size in which to return the values readlen- the number of 32 bit values to read- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned32
public final void readUnsigned32(int[] w, int offset, int len) throws java.io.IOExceptionRead an array of unsigned integer 32 bit values.
- Parameters:
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 read- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned64
public final void readUnsigned64(long[] w, int len) throws java.io.IOExceptionRead an array of unsigned integer 64 bit values.
- Parameters:
w- an array of sufficient size in which to return the values readlen- the number of 64 bit values to read- Throws:
java.io.IOException- if an I/O error occurs
-
readUnsigned64
public final void readUnsigned64(long[] w, int offset, int len) throws java.io.IOExceptionRead an array of unsigned integer 64 bit values.
- Parameters:
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 read- Throws:
java.io.IOException- if an I/O error occurs
-
readFloat
public final void readFloat(float[] f, int len) throws java.io.IOExceptionRead an array of floating point 32 bit values.
- Parameters:
f- an array of sufficient size in which to return the values readlen- the number of 32 bit values to read- Throws:
java.io.IOException- if an I/O error occurs
-
readComplexFloat
public final void readComplexFloat(float[] freal, float[] fimaginary, int len) throws java.io.IOExceptionRead interleaved complex floating point 32 bit value pairs into real and imaginary arrays.
- Parameters:
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 read- Throws:
java.io.IOException- if an I/O error occurs
-
readDouble
public final void readDouble(double[] f, int len) throws java.io.IOExceptionRead an array of floating point 64 bit values.
- Parameters:
f- an array of sufficient size in which to return the values readlen- the number of 64 bit values to read- Throws:
java.io.IOException- if an I/O error occurs
-
readComplexDouble
public final void readComplexDouble(double[] freal, double[] fimaginary, int len) throws java.io.IOExceptionRead interleaved complex floating point 64 bit value pairs into real and imaginary arrays.
- Parameters:
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 read- Throws:
java.io.IOException- if an I/O error occurs
-
main
public static void main(java.lang.String[] arg)
For testing.
- Parameters:
arg- file to read from
-
-