Package bdsup2sub.tools
Class FileBuffer
java.lang.Object
bdsup2sub.tools.FileBuffer
Very simple version of a read only memory mapped file used for parsing large packet based files.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
Buffer in memoryprivate static final int
Size of the buffer in memoryprivate FileChannel
File channel of the input fileprivate FileInputStream
File input stream of the input fileprivate String
File name of the input fileprivate long
Length of fileprivate long
Current offset in file = start of memory bufferprivate long
Last valid offset that is stored in internal buffer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close file buffer (closes input file).void
finalize()
int
getByte
(long offset) Read one byte from the buffer.void
getBytes
(long ofs, byte[] b, int len) Read multiple bytes from the buffer.int
getDWord
(long offset) Read one (big endian) 32bit dword from the buffer.int
getDWordLE
(long offset) Read one (little endian) 32bit dword from the buffer.long
getSize()
Get size of input file.int
getWord
(long offset) Read one (big endian) 16bit word from the buffer.int
getWordLE
(long offset) Read one (little endian) 16bit word from the buffer.private void
readBuffer
(long offset) Move offset, read file to memory buffer.
-
Field Details
-
BUFFERSIZE
private static final int BUFFERSIZESize of the buffer in memory- See Also:
-
buf
private byte[] bufBuffer in memory -
filename
File name of the input file -
fi
File input stream of the input file -
fc
File channel of the input file -
offset
private long offsetCurrent offset in file = start of memory buffer -
offsetEnd
private long offsetEndLast valid offset that is stored in internal buffer -
length
private long lengthLength of file
-
-
Constructor Details
-
FileBuffer
- Throws:
FileBufferException
-
-
Method Details
-
readBuffer
Move offset, read file to memory buffer.- Parameters:
offset
- New file offset- Throws:
FileBufferException
-
getByte
Read one byte from the buffer.- Parameters:
offset
- File offset- Returns:
- Byte read from the buffer
- Throws:
FileBufferException
-
getWord
Read one (big endian) 16bit word from the buffer.- Parameters:
offset
- File offset- Returns:
- Word read from the buffer
- Throws:
FileBufferException
-
getWordLE
Read one (little endian) 16bit word from the buffer.- Parameters:
offset
- File offset- Returns:
- Word read from the buffer
- Throws:
FileBufferException
-
getDWord
Read one (big endian) 32bit dword from the buffer.- Parameters:
offset
- File offset- Returns:
- Dword read from the buffer
- Throws:
FileBufferException
-
getDWordLE
Read one (little endian) 32bit dword from the buffer.- Parameters:
offset
- File offset- Returns:
- Dword read from the buffer
- Throws:
FileBufferException
-
getBytes
Read multiple bytes from the buffer.- Parameters:
ofs
- File offsetb
- Buffer to store bytes (has to be allocated and large enough)len
- Number of bytes to read- Throws:
FileBufferException
-
getSize
public long getSize()Get size of input file.- Returns:
- Size of input file in bytes
-
close
public void close()Close file buffer (closes input file). -
finalize
-