public class SectionedCharBuffer extends Object
CharBuffer, but is tailored to how BufferedCharSeeker
works and to be able to take full advantage of ThreadAheadReadable.
First of all this thing wraps a char[] where the array, while still being one array,
is sectioned into two equally sized parts: the back and the front. The flow of things is as follows:
Reader using readFrom(Reader) into the front section,
i.e. starting from the middle of the array and forwards.array() and starts reading from the pivot()
point, which is the middle, to finally reach the end, denoted by front() (exclusive).
During the reading typically characters are read into some sort of fields/values, and so the last characters
of the array might represent an incomplete value.compact(SectionedCharBuffer, int) where
after that call back() will point to the index in the array() containing the first value
in the array.readFrom(Reader).ThreadAheadReadable where the
thread that reads ahead reads into the front section of another buffer, a double buffer,
and the current buffer that BufferedCharSeeker is working with can
compact(SectionedCharBuffer, int) its last incomplete characters into that double buffer
and flip so that the BufferedCharSeeker continues to read from the other buffer, i.e. flips
buffer every call to ThreadAheadReadable.read(SectionedCharBuffer, int). Without these sections
the entire double buffer would have to be copied into the char seekers buffer to get the same behavior.| Constructor and Description |
|---|
SectionedCharBuffer(int effectiveBuffserSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
append(char ch)
Puts a character into the front section of the buffer and increments the front index.
|
char[] |
array() |
int |
available() |
int |
back() |
void |
compact(SectionedCharBuffer into,
int from)
|
int |
front() |
boolean |
hasAvailable() |
int |
pivot() |
void |
readFrom(Reader reader)
Reads characters from
reader into the front section of this buffer, setting front()
accordingly afterwards. |
void |
readFrom(Reader reader,
int max)
Like
readFrom(Reader) but with added max argument for limiting the number of
characters read from the Reader. |
public SectionedCharBuffer(int effectiveBuffserSize)
effectiveBuffserSize - Size of each section, i.e. effective buffer size that can be
read each time.public char[] array()
public void compact(SectionedCharBuffer into, int from)
array() from (and including) the given from index of the array
and all characters forwards to front() (excluding) index. These characters are copied into
the array() of the given into buffer, where the character array[from] will
be be copied to into.array[pivot-(front-from)], and so on. As an example:
pivot (i.e. effective buffer size) = 16
buffer A
<------ back ------> <------ front ----->
[ . . . |abcd.efgh.ijkl.mnop]
^ = 25
A.compactInto( B, 25 )
buffer B
<------ back ------> <------ front ----->
[ . . jkl.mnop| . . . ]
into - which buffer to compact into.from - the array index to start compacting from.public void readFrom(Reader reader) throws IOException
reader into the front section of this buffer, setting front()
accordingly afterwards. If no characters were read due to end reached then hasAvailable() will
return false after this call, likewise available() will return 0.reader - Reader to read from.IOException - any exception from the Reader.public void readFrom(Reader reader, int max) throws IOException
readFrom(Reader) but with added max argument for limiting the number of
characters read from the Reader.IOExceptionreadFrom(Reader)public void append(char ch)
ch - public int pivot()
array(). Before the pivot there are characters saved
from a previous compaction and after (and including) this point
are characters read from readFrom(Reader).public int back()
public int front()
public boolean hasAvailable()
public int available()
Copyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.