public class EncapsulatedInputStream extends InputStream
A class that extends InputStream
by adding
a mechanism for unecapsulating an undefined length DICOM attribute, such as is used for
compressed Pixel Data.
The read methods hide the fact that the data is encapsulated by removing the Items and Item and Sequence delimiter tags, as well as skipping any Basic Offset Table that may be present in the first Item.
Since an individual frame may be fragmented and padded with 0xff bytes beyond the JPEG EOI marker (0xffd9), and since the codec used for decoding may be "reading ahead" this class also removes any padding 0xff bytes at the end of any fragment, back as far as the EOI marker. Note that this means that theorectically frames could span fragments as long as there was no padding between them.
Constructor and Description |
---|
EncapsulatedInputStream(BinaryInputStream i)
Construct a byte ordered stream from the supplied stream.
|
EncapsulatedInputStream(BinaryInputStream i,
boolean jpegEOIDetection)
Construct a byte ordered stream from the supplied stream.
|
Modifier and Type | Method and Description |
---|---|
protected long |
getBytesRead() |
int |
getOffsetOfNextByteToReadFromStartOfFragment() |
void |
nextFrame()
Skip to the start of a fragment, if not already there.
|
int |
read()
Extracts the next byte of data from the current or
subsequent fragments.
|
int |
read(byte[] b)
Extracts
byte.length bytes of data from the current or
subsequent fragments. |
int |
read(byte[] b,
int off,
int len)
Extracts
len bytes of data from the current or
subsequent fragments. |
void |
readSequenceDelimiter() |
void |
readUnsigned16(short[] w,
int offset,
int len)
Read an array of unsigned integer 16 bit values.
|
long |
readUnsigned32LittleEndian()
Read an unsigned integer 32 bit values little endian regardless of endianness of stream.
|
void |
readUnsigned32LittleEndian(long[] w,
int offset,
int len)
Read an array of unsigned integer 32 bit values little endian regardless of endianness of stream.
|
void |
skipInsistently(long length)
Skip as many bytes as requested, unless an exception occurs.
|
available, close, mark, markSupported, reset, skip
public EncapsulatedInputStream(BinaryInputStream i, boolean jpegEOIDetection)
Construct a byte ordered stream from the supplied stream.
The byte order may be changed later.
Do not use jpegEOIDetection for RLE encapsulated data.
i
- the input stream to read fromjpegEOIDetection
- whether or not to detect JPEG EOI, to allow frames to span fragmentspublic EncapsulatedInputStream(BinaryInputStream i)
Construct a byte ordered stream from the supplied stream.
The byte order may be changed later.
JPEG EOI detection is enabled, to allow frames to span fragments.
i
- the input stream to read fromjpegEOIDetection
- whether or not to detectprotected long getBytesRead()
public void readSequenceDelimiter() throws IOException
IOException
public void nextFrame()
Skip to the start of a fragment, if not already there.
public 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
public final long readUnsigned32LittleEndian() throws IOException
Read an unsigned integer 32 bit values little endian regardless of endianness of stream.
IOException
public final void readUnsigned32LittleEndian(long[] w, int offset, int len) throws IOException
Read an array of unsigned integer 32 bit values little endian regardless of endianness of stream.
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
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
public final int read() throws IOException
Extracts the next byte of data from the current or subsequent fragments.
read
in class InputStream
IOException
- if an I/O error occurs.public final int read(byte[] b) throws IOException
Extracts byte.length
bytes of data from the current or
subsequent fragments.
This method simply performs the call read(b, 0, b.length)
and returns
the result.
read
in class InputStream
b
- the buffer into which the data is read.IOException
- if an I/O error occurs.read(byte[], int, int)
public final int read(byte[] b, int off, int len) throws IOException
Extracts len
bytes of data from the current or
subsequent fragments.
read
in class InputStream
b
- the buffer into which the data is read.off
- the start offset of the data.len
- the number of bytes read.IOException
- if an I/O error occurs.public int getOffsetOfNextByteToReadFromStartOfFragment()