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.
|
Modifier and Type | Method and Description |
---|---|
protected long |
getBytesRead() |
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.
|
available, close, mark, markSupported, reset, skip
public EncapsulatedInputStream(BinaryInputStream i)
Construct a byte ordered stream from the supplied stream.
The byte order may be changed later.
i
- the input stream to read fromprotected 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 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.