Class ChunkReader
- java.lang.Object
-
- ghidra.framework.main.logviewer.model.ChunkReader
-
public class ChunkReader extends java.lang.Object
This class handles reading data from the input file, in the form ofChunk
objects. Each chunk is stored in theChunkModel
and represents a single block of text that is displayed in theFVTable
.
-
-
Constructor Summary
Constructors Constructor Description ChunkReader(java.io.File file, ChunkModel model)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.File
getFile()
Returns the file being read.long
getFileSize()
Returns the number of bytes in the input file.long
getStartOfNextLine(long startByte)
Returns the start of the next line after the given byte.java.util.List<byte[]>
readBytes(long startByte, long endByte)
Reads all bytes from the given byte to the end byte.java.util.List<java.lang.String>
readLastChunk()
Reads one chunk from the end of the file.java.util.List<java.lang.String>
readNextChunk()
Reads the next chunk in the file past the last one specified in theChunkModel
.java.util.List<java.lang.String>
readNextChunkFrom(long startByte)
Reads a chunk of data from the given location in the file.java.util.List<java.lang.String>
readPreviousChunk()
Reads the chunk immediately before the first visible one.void
reload()
-
-
-
Constructor Detail
-
ChunkReader
public ChunkReader(java.io.File file, ChunkModel model) throws java.io.IOException
- Parameters:
file
-model
-- Throws:
java.io.IOException
-
-
Method Detail
-
getFileSize
public long getFileSize() throws java.io.IOException
Returns the number of bytes in the input file.- Returns:
- number of bytes
- Throws:
java.io.IOException
-
getFile
public java.io.File getFile()
Returns the file being read.- Returns:
-
reload
public void reload() throws java.io.IOException
- Throws:
java.io.IOException
-
readLastChunk
public java.util.List<java.lang.String> readLastChunk() throws java.io.IOException
Reads one chunk from the end of the file. This is useful when scrolling to the bottom of the viewport.- Returns:
- the last chunk, or an empty list
- Throws:
java.io.IOException
-
readPreviousChunk
public java.util.List<java.lang.String> readPreviousChunk() throws java.io.IOException
Reads the chunk immediately before the first visible one.- Returns:
- the previous chunk, or an empty list
- Throws:
java.io.IOException
-
readNextChunkFrom
public java.util.List<java.lang.String> readNextChunkFrom(long startByte) throws java.io.IOException
Reads a chunk of data from the given location in the file. To ensure we're always reading full lines, take the given start position and move forward to the next full line before reading.- Parameters:
startByte
- the position to start reading from- Returns:
- the lines of text read
- Throws:
java.io.IOException
-
readBytes
public java.util.List<byte[]> readBytes(long startByte, long endByte) throws java.io.IOException
Reads all bytes from the given byte to the end byte. If the amount of bytes to be read is greater than the size of an INT, we will have to read this in several chunks, hence the need to return a list of arrays, and not just a single byte array.- Parameters:
startByte
-endByte
-- Returns:
- a map of all the bytes read in (index 0 is first chunk, 1 is next, etc...).
- Throws:
java.io.IOException
-
readNextChunk
public java.util.List<java.lang.String> readNextChunk() throws java.io.FileNotFoundException, java.io.IOException
Reads the next chunk in the file past the last one specified in theChunkModel
.- Returns:
- the lines of text read
- Throws:
java.io.FileNotFoundException
java.io.IOException
-
getStartOfNextLine
public long getStartOfNextLine(long startByte) throws java.io.IOException
Returns the start of the next line after the given byte. To do this, simply read backwards from the given point until a newline or carriage return is found.- Parameters:
startByte
-- Returns:
- Throws:
java.io.IOException
-
-