Package org.apache.fontbox.ttf
Class RandomAccessReadUnbufferedDataStream
- java.lang.Object
-
- org.apache.fontbox.ttf.TTFDataStream
-
- org.apache.fontbox.ttf.RandomAccessReadUnbufferedDataStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
class RandomAccessReadUnbufferedDataStream extends TTFDataStream
In contrast toRandomAccessReadDataStream, this class doesn't pre-loadRandomAccessReadinto abyte[], it works withRandomAccessReaddirectly. Performance: it is much faster if most of the buffer is skipped, and slower if whole buffer is read()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classRandomAccessReadUnbufferedDataStream.RandomAccessReadNonClosingInputStream
-
Field Summary
Fields Modifier and Type Field Description private longlengthprivate RandomAccessReadrandomAccessRead
-
Constructor Summary
Constructors Constructor Description RandomAccessReadUnbufferedDataStream(RandomAccessRead randomAccessRead)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the underlying resources.RandomAccessReadcreateSubView(long length)Creates a view from current position topos + length.longgetCurrentPosition()Get the current position in the stream.java.io.InputStreamgetOriginalData()Lifetime of returned InputStream is bound bythislifetime, it won't close underlyingRandomAccessRead.longgetOriginalDataSize()This 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()longreadLong()Read an unsigned byte.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 Detail
-
length
private final long length
-
randomAccessRead
private final RandomAccessRead randomAccessRead
-
-
Constructor Detail
-
RandomAccessReadUnbufferedDataStream
RandomAccessReadUnbufferedDataStream(RandomAccessRead randomAccessRead) throws java.io.IOException
- Throws:
java.io.IOException- If there is a problem reading the source length.
-
-
Method Detail
-
getCurrentPosition
public long getCurrentPosition() throws java.io.IOExceptionGet the current position in the stream.- Specified by:
getCurrentPositionin classTTFDataStream- Returns:
- The current position in the stream.
- Throws:
java.io.IOException- If an error occurs while reading the stream.
-
close
public void close() throws java.io.IOExceptionClose the underlying resources.- Throws:
java.io.IOException- If there is an error closing the resources.
-
read
public int read() throws java.io.IOExceptionRead an unsigned byte.- Specified by:
readin classTTFDataStream- Returns:
- An unsigned byte.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readLong
public final long readLong() throws java.io.IOExceptionRead an unsigned byte.- Specified by:
readLongin classTTFDataStream- Returns:
- An unsigned byte.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readInt
private int readInt() throws java.io.IOException- Throws:
java.io.IOException
-
seek
public void seek(long pos) throws java.io.IOExceptionSeek into the datasource.- Specified by:
seekin classTTFDataStream- Parameters:
pos- The position to seek to.- Throws:
java.io.IOException- If there is an error seeking to that position.
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- 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 at the end of the stream
- Throws:
java.io.IOException- If there is an error reading from the stream.- See Also:
InputStream.read(byte[], int, int )
-
getOriginalData
public java.io.InputStream getOriginalData() throws java.io.IOExceptionLifetime of returned InputStream is bound bythislifetime, it won't close underlyingRandomAccessRead. 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:
java.io.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.
-
createSubView
public RandomAccessRead createSubView(long length)
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
-
-