org.dicom4j.io
Class EncapsulatedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.dicom4j.io.EncapsulatedInputStream
All Implemented Interfaces:
Closeable

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.

A nextFrame() method is provided to skip any padding at the end of a fragment, if any, and position the stream at the begin of the next fragment, since frame data is not permitted to span fragments, but an individual frame may be fragmented.

Author:
dclunie

Constructor Summary
EncapsulatedInputStream(BinaryInputStream i)
          Construct a byte ordered stream from the supplied stream.
 
Method Summary
 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 readUnsigned16(short[] w, int offset, int len)
          Read an array of unsigned integer 16 bit values.
 
Methods inherited from class java.io.InputStream
available, close, mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EncapsulatedInputStream

public EncapsulatedInputStream(BinaryInputStream i)

Construct a byte ordered stream from the supplied stream.

The byte order may be changed later.

Parameters:
i - the input stream to read from
Method Detail

nextFrame

public void nextFrame()

Skip to the start of a fragment, if not already there.


readUnsigned16

public final void readUnsigned16(short[] w,
                                 int offset,
                                 int len)
                          throws IOException

Read an array of unsigned integer 16 bit values.

Parameters:
w - an array of sufficient size in which to return the values read
offset - the offset in the array at which to begin storing values
len - the number of 16 bit values to read
Throws:
IOException

read

public final int read()
               throws IOException

Extracts the next byte of data from the current or subsequent fragments.

Specified by:
read in class InputStream
Returns:
the next byte of data, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.

read

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.

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer (always whatever was asked for), or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.
See Also:
read(byte[], int, int)

read

public final int read(byte[] b,
                      int off,
                      int len)
               throws IOException

Extracts len bytes of data from the current or subsequent fragments.

Overrides:
read in class InputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the number of bytes read.
Returns:
the total number of bytes read into the buffer (always whatever was asked for), or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.


Copyright © 2009 dicom4j. All Rights Reserved.