use of com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint in project ion-java by amzn.
the class IonReaderBinaryUserX method seek.
public void seek(IonReaderBinarySpan position) {
IonReaderBinarySpan pos = position;
if (pos == null) {
throw new IllegalArgumentException("Position invalid for binary reader");
}
if (!(_input instanceof FromByteArray)) {
throw new UnsupportedOperationException("Binary seek not implemented for non-byte array backed sources");
}
// TODO test that span is within the bounds of the input byte[]
// manually reset the input specific type of input stream
FromByteArray input = (FromByteArray) _input;
input._pos = (int) (pos._offset + _physical_start_offset);
input._limit = (int) (pos._limit + _physical_start_offset);
// TODO: these (eof and save points) should be put into
// a re-init method on the input stream
input._eof = false;
for (; ; ) {
SavePoint sp = input._save_points._active_stack;
if (sp == null)
break;
input._save_points.savePointPopActive(sp);
sp.free();
}
// reset the raw reader
re_init_raw();
// reset the system reader
// - nothing to do
// reset the user reader
init_user(this._catalog);
// now we need to set our symbol table
_symbols = pos._symbol_table;
// and the other misc state variables we had
// read past before getPosition gets called
// Don't do this, we'll re-read the data from the stream.
// Otherwise, this reader will be in the wrong state.
// For example, getType() will return non-null but that
// shouldn't happen until the user calls next().
// _state = pos._state;
// _value_type = pos._value_type;
// _value_is_null = pos._value_is_null;
// _value_is_true = pos._value_is_true;
// _is_in_struct = false;
}
use of com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint in project ion-java by amzn.
the class UnifiedInputStreamX method refill.
/**
* the refill method is the key override that is filled in by
* the various subclasses. It fills either the byte or char
* array with a block of data from the input source. As this
* is a virtual function the right version will get called for
* each source type. Since it is only called once per block,
* and from then on the final method which pulls data from
* the block can return the value this should be a reasonable
* performance trade off.
* @return first value from the refilled input source or EOF
* @throws IOException
*/
protected int refill() throws IOException {
UnifiedDataPageX curr = _buffer.getCurrentPage();
SavePoint sp = _save_points.savePointActiveTop();
if (!can_fill_new_page()) {
// (and it's used up)
return refill_is_eof();
}
if (sp != null && sp.getEndIdx() == _buffer.getCurrentPageIdx()) {
// also EOF but the case is odd enough to call it out
return refill_is_eof();
}
long file_position;
int start_pos = UNREAD_LIMIT;
if (curr == null) {
file_position = 0;
start_pos = 0;
} else {
file_position = curr.getFilePosition(_pos);
if (file_position == 0) {
// unread before the beginning of file is not allowed,
// so we don't have to leave room for it
start_pos = 0;
}
}
// see if we are re-reading saved buffers
int new_idx = _buffer.getNextFilledPageIdx();
if (new_idx < 0) {
// there is no pre-filled page waiting for us, so we need to
// read new data on a new page or over our current page
curr = _buffer.getCurrentPage();
boolean needs_new_page = (curr == null);
new_idx = _buffer.getCurrentPageIdx();
if (_save_points.isSavePointOpen()) {
new_idx++;
needs_new_page = true;
}
if (needs_new_page) {
curr = _buffer.getEmptyPageIdx();
}
//
// here we actually read data into our buffers -----
//
int read = load(curr, start_pos, file_position);
if (read < 1) {
return refill_is_eof();
}
assert (curr != null && curr.getOffsetOfFilePosition(file_position) == start_pos);
set_current_page(new_idx, curr, start_pos);
} else {
assert (!isEOF());
if (sp != null) {
int endidx = sp.getEndIdx();
if (endidx != -1 && endidx < new_idx) /*_buffer.getCurrentPageIdx()*/
{
return refill_is_eof();
}
}
curr = _buffer.getPage(new_idx);
assert (curr.getStartingFileOffset() == file_position);
set_current_page(new_idx, curr, curr.getStartingOffset());
if (sp != null && sp.getEndIdx() == new_idx) /*_buffer.getCurrentPageIdx()*/
{
// the last page in the marked range will probably
// require a different limit
_limit = sp.getEndPos();
}
}
// xor: either we're at eof or we have data to read
assert (isEOF() ^ (_limit > 0));
return _limit;
}
use of com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint in project ion-java by amzn.
the class IonReaderTextRawTokensX method skip_over_blob.
private void skip_over_blob(SavePoint sp) throws IOException {
int c = skip_over_blob_whitespace();
for (; ; ) {
if (c == UnifiedInputStreamX.EOF)
break;
if (c == '}')
break;
c = skip_over_blob_whitespace();
}
if (sp != null) {
// we don't care about these last 2 closing curly braces
// but we may have seen one of them already
int offset = (c == '}') ? -1 : 0;
sp.markEnd(offset);
}
// did we hit EOF or the first '}' ?
if (c != '}')
unexpected_eof();
c = read_char();
if (c < 0) {
unexpected_eof();
}
if (c != '}') {
String message = "improperly closed BLOB, " + IonTextUtils.printCodePointAsString(c) + " encountered when '}' was expected";
error(message);
}
if (sp != null) {
sp.markEnd();
}
return;
}
use of com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint in project ion-java by amzn.
the class IonReaderTextRawTokensX method skipOverRadix.
private int skipOverRadix(SavePoint sp, Radix radix) throws IOException {
int c;
c = read_char();
if (c == '-') {
c = read_char();
}
assert (c == '0');
c = read_char();
radix.assertPrefix(c);
c = readNumeric(NULL_APPENDABLE, radix);
if (!is_value_terminating_character(c)) {
bad_token(c);
}
if (sp != null) {
sp.markEnd(-1);
}
return c;
}
use of com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint in project ion-java by amzn.
the class IonReaderTextRawTokensX method skip_over_timestamp.
private int skip_over_timestamp(SavePoint sp) throws IOException {
// we know we have dddd- or ddddT we don't know what follows
// is should be dddd-mm
int c = skip_timestamp_past_digits(4);
if (c == 'T') {
// yyyyT
if (sp != null) {
sp.markEnd(0);
}
// prefetch
return skip_over_whitespace();
}
if (c != '-') {
error("invalid timestamp encountered");
}
// yyyy-mmT
// yyyy-mm-ddT
// yyyy-mm-ddT+hh:mm
// yyyy-mm-ddThh:mm+hh:mm
// yyyy-mm-ddThh:mm:ss+hh:mm
// yyyy-mm-ddThh:mm:ss.dddd+hh:mm
// yyyy-mm-ddThh:mmZ
// yyyy-mm-ddThh:mm:ssZ
// yyyy-mm-ddThh:mm:ss.ddddZ
c = skip_timestamp_past_digits(2);
if (c == 'T') {
// yyyy-mmT
if (sp != null) {
sp.markEnd(0);
}
// prefetch
return skip_over_whitespace();
}
skip_timestamp_validate(c, '-');
c = skip_timestamp_past_digits(2);
if (c != 'T') {
return skip_timestamp_finish(c, sp);
}
c = read_char();
if (!IonTokenConstsX.isDigit(c)) {
// yyyy-mm-ddT
return skip_timestamp_finish(skip_optional_timestamp_offset(c), sp);
}
// one hour digit already read above
c = skip_timestamp_past_digits(1);
if (c != ':') {
bad_token(c);
}
c = skip_timestamp_past_digits(2);
if (c != ':') {
// yyyy-mm-ddThh:mm?
return skip_timestamp_offset_or_z(c, sp);
}
c = skip_timestamp_past_digits(2);
if (c != '.') {
// yyyy-mm-ddThh:mm:ss?
return skip_timestamp_offset_or_z(c, sp);
}
c = read_char();
if (IonTokenConstsX.isDigit(c)) {
c = skip_over_digits(c);
}
return skip_timestamp_offset_or_z(c, sp);
}
Aggregations