Package org.apache.fontbox.ttf
Class TTFDataStream
- java.lang.Object
-
- org.apache.fontbox.ttf.TTFDataStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
RandomAccessReadDataStream,RandomAccessReadUnbufferedDataStream,TTCDataStream
abstract class TTFDataStream extends java.lang.Object implements java.io.CloseableAn abstract class to read a data stream.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.TimeZoneTIMEZONE_UTC
-
Constructor Summary
Constructors Constructor Description TTFDataStream()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description RandomAccessReadcreateSubView(long length)Creates a view from current position topos + length.abstract longgetCurrentPosition()Get the current position in the stream.abstract java.io.InputStreamgetOriginalData()This will get the original data file that was used for this stream.abstract longgetOriginalDataSize()This will get the original data size that was used for this stream.abstract intread()Read an unsigned byte.abstract intread(byte[] b, int off, int len)byte[]read(int numberOfBytes)Read a specific number of bytes from the stream.floatread32Fixed()Read a 16.16 fixed value, where the first 16 bits are the decimal and the last 16 bits are the fraction.java.util.CalendarreadInternationalDate()Read an eight byte international date.abstract longreadLong()Read an unsigned byte.intreadSignedByte()Read a signed byte.shortreadSignedShort()Read a signed short.java.lang.StringreadString(int length)Read a fixed length ascii string.java.lang.StringreadString(int length, java.nio.charset.Charset charset)Read a fixed length string.java.lang.StringreadTag()Reads a tag, an array of four uint8s used to identify a script, language system, feature, or baseline.intreadUnsignedByte()Read an unsigned byte.int[]readUnsignedByteArray(int length)Read an unsigned byte array.longreadUnsignedInt()Read an unsigned integer.intreadUnsignedShort()Read an unsigned short.int[]readUnsignedShortArray(int length)Read an unsigned short array.abstract voidseek(long pos)Seek into the datasource.
-
-
-
Method Detail
-
read32Fixed
public float read32Fixed() throws java.io.IOExceptionRead a 16.16 fixed value, where the first 16 bits are the decimal and the last 16 bits are the fraction.- Returns:
- A 32 bit value.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readString
public java.lang.String readString(int length) throws java.io.IOExceptionRead a fixed length ascii string.- Parameters:
length- The length of the string to read.- Returns:
- A string of the desired length.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readString
public java.lang.String readString(int length, java.nio.charset.Charset charset) throws java.io.IOExceptionRead a fixed length string.- Parameters:
length- The length of the string to read in bytes.charset- The expected character set of the string.- Returns:
- A string of the desired length.
- Throws:
java.io.IOException- If there is an error reading the data.
-
read
public abstract int read() throws java.io.IOExceptionRead an unsigned byte.- Returns:
- An unsigned byte.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readLong
public abstract long readLong() throws java.io.IOExceptionRead an unsigned byte.- Returns:
- An unsigned byte.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readSignedByte
public int readSignedByte() throws java.io.IOExceptionRead a signed byte.- Returns:
- A signed byte.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOExceptionRead an unsigned byte. Similar toread(), but throws an exception if EOF is unexpectedly reached.- Returns:
- An unsigned byte.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readUnsignedInt
public long readUnsignedInt() throws java.io.IOExceptionRead an unsigned integer.- Returns:
- An unsigned integer.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOExceptionRead an unsigned short.- Returns:
- An unsigned short.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readUnsignedByteArray
public int[] readUnsignedByteArray(int length) throws java.io.IOExceptionRead an unsigned byte array.- Parameters:
length- the length of the array to be read- Returns:
- An unsigned byte array.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readUnsignedShortArray
public int[] readUnsignedShortArray(int length) throws java.io.IOExceptionRead an unsigned short array.- Parameters:
length- The length of the array to read.- Returns:
- An unsigned short array.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readSignedShort
public short readSignedShort() throws java.io.IOExceptionRead a signed short.- Returns:
- A signed short.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readInternationalDate
public java.util.Calendar readInternationalDate() throws java.io.IOExceptionRead an eight byte international date.- Returns:
- A signed short.
- Throws:
java.io.IOException- If there is an error reading the data.
-
readTag
public java.lang.String readTag() throws java.io.IOExceptionReads a tag, an array of four uint8s used to identify a script, language system, feature, or baseline.- Throws:
java.io.IOException
-
seek
public abstract void seek(long pos) throws java.io.IOExceptionSeek into the datasource.- Parameters:
pos- The position to seek to.- Throws:
java.io.IOException- If there is an error seeking to that position.
-
read
public byte[] read(int numberOfBytes) throws java.io.IOExceptionRead a specific number of bytes from the stream.- Parameters:
numberOfBytes- The number of bytes to read.- Returns:
- The byte buffer.
- Throws:
java.io.IOException- If there is an error while reading.
-
read
public abstract int read(byte[] b, int off, int len) throws java.io.IOException- 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 )
-
createSubView
public RandomAccessRead createSubView(long length)
Creates 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.- Returns:
- A view or null (caller can use
read()instead). Please close() the result
-
getCurrentPosition
public abstract long getCurrentPosition() throws java.io.IOExceptionGet the current position in the stream.- Returns:
- The current position in the stream.
- Throws:
java.io.IOException- If an error occurs while reading the stream.
-
getOriginalData
public abstract java.io.InputStream getOriginalData() throws java.io.IOExceptionThis will get the original data file that was used for this stream.- Returns:
- The data that was read from.
- Throws:
java.io.IOException- If there is an issue reading the data.
-
getOriginalDataSize
public abstract long getOriginalDataSize()
This will get the original data size that was used for this stream.- Returns:
- The size of the original data.
-
-