Package io.kaitai.struct
Class RandomAccessFileKaitaiStream
- java.lang.Object
-
- io.kaitai.struct.KaitaiStream
-
- io.kaitai.struct.RandomAccessFileKaitaiStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class RandomAccessFileKaitaiStream extends KaitaiStream
An implementation ofKaitaiStreambacked by aRandomAccessFile. Allows reading from local files. Generally, one would want to useByteBufferKaitaiStreaminstead, as it most likely would be faster, but there are two situations when one should consider this one instead:- Processing many small files. Every ByteBuffer invocation requires a mmap call, which can be relatively expensive (per file).
- Accessing extra-long files (>31 bits positioning). Unfortunately, Java's implementation of mmap uses ByteBuffer, which is not addressable beyond 31 bit offsets, even if you use a 64-bit platform.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.kaitai.struct.KaitaiStream
KaitaiStream.KaitaiStructError, KaitaiStream.UndecidedEndiannessError, KaitaiStream.UnexpectedDataError, KaitaiStream.ValidationExprError, KaitaiStream.ValidationFailedError, KaitaiStream.ValidationGreaterThanError, KaitaiStream.ValidationLessThanError, KaitaiStream.ValidationNotAnyOfError, KaitaiStream.ValidationNotEqualError
-
-
Field Summary
Fields Modifier and Type Field Description protected RandomAccessFileraf-
Fields inherited from class io.kaitai.struct.KaitaiStream
bits, bitsLeft
-
-
Constructor Summary
Constructors Constructor Description RandomAccessFileKaitaiStream(String fileName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleanisEof()Check if stream pointer is at the end of stream.intpos()Get current position of a stream pointer.byte[]readBytes(long n)Reads designated number of bytes from the stream.byte[]readBytesFull()Reads all the remaining bytes in a stream as byte array.byte[]readBytesTerm(int term, boolean includeTerm, boolean consumeTerm, boolean eosError)floatreadF4be()floatreadF4le()doublereadF8be()doublereadF8le()bytereadS1()Reads one signed 1-byte integer, returning it properly as Java's "byte" type.shortreadS2be()shortreadS2le()intreadS4be()intreadS4le()longreadS8be()longreadS8le()intreadU1()intreadU2be()intreadU2le()longreadU4be()longreadU4le()voidseek(int newPos)Set stream pointer to designated position (int).voidseek(long newPos)Set stream pointer to designated position (long).longsize()Get total size of the stream in bytes.-
Methods inherited from class io.kaitai.struct.KaitaiStream
alignToByte, byteArrayCompare, byteArrayMax, byteArrayMin, bytesStripRight, bytesTerminate, ensureFixedContents, mod, mod, processRotateLeft, processXor, processXor, processZlib, readBitsInt, readBitsIntBe, readBitsIntLe, readU8be, readU8le, toByteArrayLength
-
-
-
-
Field Detail
-
raf
protected RandomAccessFile raf
-
-
Constructor Detail
-
RandomAccessFileKaitaiStream
public RandomAccessFileKaitaiStream(String fileName) throws IOException
- Throws:
IOException
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classKaitaiStream- Throws:
IOException
-
isEof
public boolean isEof()
Description copied from class:KaitaiStreamCheck if stream pointer is at the end of stream.- Specified by:
isEofin classKaitaiStream- Returns:
- true if we are located at the end of the stream
-
seek
public void seek(int newPos)
Description copied from class:KaitaiStreamSet stream pointer to designated position (int).- Specified by:
seekin classKaitaiStream- Parameters:
newPos- new position (offset in bytes from the beginning of the stream)
-
seek
public void seek(long newPos)
Description copied from class:KaitaiStreamSet stream pointer to designated position (long).- Specified by:
seekin classKaitaiStream- Parameters:
newPos- new position (offset in bytes from the beginning of the stream)
-
pos
public int pos()
Description copied from class:KaitaiStreamGet current position of a stream pointer.- Specified by:
posin classKaitaiStream- Returns:
- pointer position, number of bytes from the beginning of the stream
-
size
public long size()
Description copied from class:KaitaiStreamGet total size of the stream in bytes.- Specified by:
sizein classKaitaiStream- Returns:
- size of the stream in bytes
-
readS1
public byte readS1()
Description copied from class:KaitaiStreamReads one signed 1-byte integer, returning it properly as Java's "byte" type.- Specified by:
readS1in classKaitaiStream- Returns:
- 1-byte integer read from a stream
-
readS2be
public short readS2be()
- Specified by:
readS2bein classKaitaiStream
-
readS4be
public int readS4be()
- Specified by:
readS4bein classKaitaiStream
-
readS8be
public long readS8be()
- Specified by:
readS8bein classKaitaiStream
-
readS2le
public short readS2le()
- Specified by:
readS2lein classKaitaiStream
-
readS4le
public int readS4le()
- Specified by:
readS4lein classKaitaiStream
-
readS8le
public long readS8le()
- Specified by:
readS8lein classKaitaiStream
-
readU1
public int readU1()
- Specified by:
readU1in classKaitaiStream
-
readU2be
public int readU2be()
- Specified by:
readU2bein classKaitaiStream
-
readU4be
public long readU4be()
- Specified by:
readU4bein classKaitaiStream
-
readU2le
public int readU2le()
- Specified by:
readU2lein classKaitaiStream
-
readU4le
public long readU4le()
- Specified by:
readU4lein classKaitaiStream
-
readF4be
public float readF4be()
- Specified by:
readF4bein classKaitaiStream
-
readF8be
public double readF8be()
- Specified by:
readF8bein classKaitaiStream
-
readF4le
public float readF4le()
- Specified by:
readF4lein classKaitaiStream
-
readF8le
public double readF8le()
- Specified by:
readF8lein classKaitaiStream
-
readBytes
public byte[] readBytes(long n)
Description copied from class:KaitaiStreamReads designated number of bytes from the stream.- Specified by:
readBytesin classKaitaiStream- Parameters:
n- number of bytes to read- Returns:
- read bytes as byte array
-
readBytesFull
public byte[] readBytesFull()
Description copied from class:KaitaiStreamReads all the remaining bytes in a stream as byte array.- Specified by:
readBytesFullin classKaitaiStream- Returns:
- all remaining bytes in a stream as byte array
-
readBytesTerm
public byte[] readBytesTerm(int term, boolean includeTerm, boolean consumeTerm, boolean eosError)- Specified by:
readBytesTermin classKaitaiStream
-
-