Class LineByteStream
java.lang.Object
edu.stanford.slac.archiverappliance.PB.utils.LineByteStream
- All Implemented Interfaces:
Closeable,AutoCloseable
This class wraps a RandomAccessFile and returns byte arrays separated by lines.
In addition it also maintains a count of the bytes read.
We expect the file channel to be positioned correctly for the initial read.
After each read, the channel is positioned just after the newline.
- Author:
- mshankar
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intstatic int -
Constructor Summary
ConstructorsConstructorDescriptionLineByteStream(Path path) LineByteStream(Path path, long startPosition) LineByteStream(Path path, long startPosition, long endPosition) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longbyte[]readLine()Optimize the readline by offering the abilty to reuse the same memory allocation.voidvoidSeeks and positions the pointer to to the last line in the file.voidseekToBeforePreviousLine(long posn) Seeks and positions the pointer to line previous to the specified position.voidSeeks to the first new line after the current position in the rndAccFile.
-
Field Details
-
MAX_LINE_SIZE
public static int MAX_LINE_SIZE -
MAX_ITERATIONS_TO_DETERMINE_LINE
public static int MAX_ITERATIONS_TO_DETERMINE_LINE
-
-
Constructor Details
-
LineByteStream
- Throws:
IOException
-
LineByteStream
- Throws:
IOException
-
LineByteStream
- Throws:
IOException
-
-
Method Details
-
readLine
- Throws:
IOException
-
readLine
Optimize the readline by offering the abilty to reuse the same memory allocation. This does not escape the bytes as it is reading the line. While this is optimal to do, it means for raw responses, we'll be redoing some of the work and raw responses are 90% of the requests. If in future, we determine that unescaping here is more optimal, this method has an unescape version in version control history. Returns the same byte array as the input.- Parameters:
bar- ByteArray- Returns:
- bar ByteArray
- Throws:
IOException-
-
seekToFirstNewLine
Seeks to the first new line after the current position in the rndAccFile. The file pointer is located just after the first newline.- Throws:
IOException-
-
seekToBeforeLastLine
Seeks and positions the pointer to to the last line in the file. The file pointer is located just before the last line so that readLine gets a valid line. About the only thing once can do after this is to read a line and stop...- Throws:
IOException-
-
seekToBeforePreviousLine
Seeks and positions the pointer to line previous to the specified position. The file pointer is located just so that one can do a readline. Note that this method is not efficient at all; so use with care.- Parameters:
posn-- Throws:
IOException-
-
getCurrentPosition
- Throws:
IOException
-
safeClose
public void safeClose() -
getAbsolutePath
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-