Package org.apache.fontbox.ttf
Class RandomAccessReadDataStream
java.lang.Object
org.apache.fontbox.ttf.TTFDataStream
org.apache.fontbox.ttf.RandomAccessReadDataStream
- All Implemented Interfaces:
Closeable,AutoCloseable
An implementation of the TTFDataStream using RandomAccessRead as source.
The underlying RandomAccessRead can be any length, but this implementation supports
only bufferLengths upto Integer.MAX_VALUE.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final byte[]private final longprivate static final org.apache.commons.logging.Log -
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessReadDataStream(InputStream inputStream) Constructor.RandomAccessReadDataStream(RandomAccessRead randomAccessRead) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the underlying resources.createSubView(long length) Creates a view from current position topos + length.longGet the current position in the stream.This will get the original data file that was used for this stream.longThis will get the original data size that was used for this stream.intread()Read an unsigned byte.intread(byte[] b, int off, int len) private intreadInt()Read a signed 32-bit integer.final longreadLong()Read a signed 64-bit integer.voidseek(long pos) Seek into the datasource.Methods inherited from class org.apache.fontbox.ttf.TTFDataStream
read, read32Fixed, readInternationalDate, readSignedByte, readSignedShort, readString, readString, readTag, readUnsignedByte, readUnsignedByteArray, readUnsignedInt, readUnsignedShort, readUnsignedShortArray
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
length
private final long length -
data
private final byte[] data -
currentPosition
private int currentPosition
-
-
Constructor Details
-
RandomAccessReadDataStream
RandomAccessReadDataStream(RandomAccessRead randomAccessRead) throws IOException Constructor.- Parameters:
randomAccessRead- source to be read from. Caller should close it.- Throws:
IOException- If there is a problem reading the source data.
-
RandomAccessReadDataStream
RandomAccessReadDataStream(InputStream inputStream) throws IOException Constructor.- Parameters:
inputStream- source to be read from. Caller should close it.- Throws:
IOException- If there is a problem reading the source data.
-
-
Method Details
-
getCurrentPosition
Get the current position in the stream.- Specified by:
getCurrentPositionin classTTFDataStream- Returns:
- The current position in the stream.
- Throws:
IOException- If an error occurs while reading the stream.
-
close
Close the underlying resources.- Throws:
IOException- If there is an error closing the resources.
-
read
Read an unsigned byte.- Specified by:
readin classTTFDataStream- Returns:
- An unsigned byte, or -1, signalling 'no more data'
- Throws:
IOException- If there is an error reading the data.
-
readLong
Read a signed 64-bit integer.- Specified by:
readLongin classTTFDataStream- Returns:
- eight bytes interpreted as a long.
- Throws:
IOException- If there is an error reading the data.
-
readInt
Read a signed 32-bit integer.- Returns:
- 4 bytes interpreted as an int.
- Throws:
IOException- If there is an error reading the data.
-
seek
Seek into the datasource. When the requestedposis < 0, an IOException() is fired. When the requestedposis ≥length, thecurrentPositionis set to the first byte after thedata!- Specified by:
seekin classTTFDataStream- Parameters:
pos- The position to seek to.- Throws:
IOException- If there is an error seeking to that position.
-
read
- Specified by:
readin classTTFDataStream- Parameters:
b- The buffer to write to.off- The offset into the buffer.len- The length into the buffer.- Returns:
- The number of bytes read or -1, signalling 'no more data'
- Throws:
IOException- If there is an error reading from the stream.- See Also:
-
createSubView
Description copied from class:TTFDataStreamCreates a view from current position topos + length. It can be faster thanread(length)if you only need a few bytes.SubView.close()should never closeTTFDataStream.this, only itself.- Overrides:
createSubViewin classTTFDataStream- Returns:
- A view or null (caller can use
TTFDataStream.read()instead). Please close() the result
-
getOriginalData
This will get the original data file that was used for this stream.- Specified by:
getOriginalDatain classTTFDataStream- Returns:
- The data that was read from.
- Throws:
IOException- If there is an issue reading the data.
-
getOriginalDataSize
public long getOriginalDataSize()This will get the original data size that was used for this stream.- Specified by:
getOriginalDataSizein classTTFDataStream- Returns:
- The size of the original data.
-