Top Description Fields Constructors Methods
org.apache.pdfbox.jbig2.io

public Class SubInputStream

extends ImageInputStreamImpl
Class Inheritance
Imports
java.io.IOException, javax.imageio.stream.ImageInputStream, .ImageInputStreamImpl

A wrapper for an ImageInputStream which is able to provide a view of a specific part of the wrapped stream. Read accesses to the wrapped stream are synchronized, so that users of this stream need to deal with synchronization against other users of the same instance, but not against other users of the wrapped stream.

Field Summary

Modifier and TypeField and Description
private final byte[]
buffer

A buffer which is used to improve read performance.

pack-priv long
bufferBase

Location of the first byte in the buffer with respect to the start of the stream.

pack-priv long
bufferTop

Location of the last byte in the buffer with respect to the start of the stream.

protected final long
length

The length of the window.

protected final long
offset

The position in the wrapped stream at which the window starts.

protected final ImageInputStream
Inherited from javax.imageio.stream.ImageInputStreamImpl:
bitOffsetbyteOrderflushedPosstreamPos

Constructor Summary

AccessConstructor and Description
public
SubInputStream(ImageInputStream
- The stream to be wrapped.
iis
,
long
- The absolute position in the wrapped stream at which the sub-stream starts.
offset
,
long
- The length of the sub-stream.
length
)

Construct a new SubInputStream which provides a view of the wrapped stream.

Method Summary

Modifier and TypeMethod and Description
private boolean

Returns:

Boolean flag. true if successful, false if not.
fillBuffer
()

Fill the buffer at the current stream position.

public long
length()

Overrides javax.imageio.stream.ImageInputStreamImpl.length.

Implements javax.imageio.stream.ImageInputStream.length.

Returns -1L to indicate that the stream has unknown length.

public int
read()

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Reads a single byte from the stream and returns it as an int between 0 and 255.

public int
read(byte[]
an array of bytes to be written to.
b
,
int
the starting position within b to write to.
off
,
int
the maximum number of bytes to read.
len
)

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Reads up to len bytes from the stream, and stores them into b starting at index off.

public void
skipBits()

Skips remaining bits in the current byte.

Inherited from javax.imageio.stream.ImageInputStreamImpl:
checkClosedclosefinalizeflushflushBeforegetBitOffsetgetByteOrdergetFlushedPositiongetStreamPositionisCachedisCachedFileisCachedMemorymarkreadreadBitreadBitsreadBooleanreadBytereadBytesreadCharreadDoublereadFloatreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadFullyreadIntreadLinereadLongreadShortreadUnsignedBytereadUnsignedIntreadUnsignedShortreadUTFresetseeksetBitOffsetsetByteOrderskipBytesskipBytes

Field Detail

bufferback to summary
private final byte[] buffer

A buffer which is used to improve read performance.

bufferBaseback to summary
pack-priv long bufferBase

Location of the first byte in the buffer with respect to the start of the stream.

bufferTopback to summary
pack-priv long bufferTop

Location of the last byte in the buffer with respect to the start of the stream.

lengthback to summary
protected final long length

The length of the window. Length is an relative value.

offsetback to summary
protected final long offset

The position in the wrapped stream at which the window starts. Offset is an absolut value.

wrappedStreamback to summary
protected final ImageInputStream wrappedStream

Constructor Detail

SubInputStreamback to summary
public SubInputStream(ImageInputStream iis, long offset, long length)

Construct a new SubInputStream which provides a view of the wrapped stream.

Parameters
iis:ImageInputStream

- The stream to be wrapped.

offset:long

- The absolute position in the wrapped stream at which the sub-stream starts.

length:long

- The length of the sub-stream.

Method Detail

fillBufferback to summary
private boolean fillBuffer() throws IOException

Fill the buffer at the current stream position.

Returns:boolean

Boolean flag. true if successful, false if not.

lengthback to summary
public long length()

Overrides javax.imageio.stream.ImageInputStreamImpl.length.

Implements javax.imageio.stream.ImageInputStream.length.

Doc from javax.imageio.stream.ImageInputStreamImpl.length.

Returns -1L to indicate that the stream has unknown length. Subclasses must override this method to provide actual length information.

Returns:long

-1L to indicate unknown length.

Annotations
@Override
readback to summary
public int read() throws IOException

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Doc from javax.imageio.stream.ImageInputStreamImpl.read.

Reads a single byte from the stream and returns it as an int between 0 and 255. If EOF is reached, -1 is returned.

Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting.

The bit offset within the stream must be reset to zero before the read occurs.

Returns:int

the value of the next byte in the stream, or -1 if EOF is reached.

Annotations
@Override
Exceptions
IOException:
if the stream has been closed.
readback to summary
public int read(byte[] b, int off, int len) throws IOException

Implements abstract javax.imageio.stream.ImageInputStreamImpl.read.

Implements javax.imageio.stream.ImageInputStream.read.

Doc from javax.imageio.stream.ImageInputStreamImpl.read.

Reads up to len bytes from the stream, and stores them into b starting at index off. If no bytes can be read because the end of the stream has been reached, -1 is returned.

The bit offset within the stream must be reset to zero before the read occurs.

Subclasses must provide an implementation for this method. The subclass implementation should update the stream position before exiting.

Parameters
b:byte[]

an array of bytes to be written to.

off:int

the starting position within b to write to.

len:int

the maximum number of bytes to read.

Returns:int

the number of bytes actually read, or -1 to indicate EOF.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
skipBitsback to summary
public void skipBits()

Skips remaining bits in the current byte.