use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextSystemX method byteSize.
//
// blob and clob support routines
//
public int byteSize() {
ensureLob("byteSize");
long len;
try {
len = load_lob_contents();
} catch (IOException e) {
throw new IonException(e);
}
if (len < 0 || len > Integer.MAX_VALUE) {
load_lob_length_overflow_error(len);
}
return (int) len;
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextSystemX method getIonValue.
public IonValue getIonValue(IonSystem sys) {
if (isNullValue()) {
switch(_value_type) {
case NULL:
return sys.newNull();
case BOOL:
return sys.newNullBool();
case INT:
return sys.newNullInt();
case FLOAT:
return sys.newNullFloat();
case DECIMAL:
return sys.newNullDecimal();
case TIMESTAMP:
return sys.newNullTimestamp();
case SYMBOL:
return sys.newNullSymbol();
case STRING:
return sys.newNullString();
case CLOB:
return sys.newNullClob();
case BLOB:
return sys.newNullBlob();
case LIST:
return sys.newNullList();
case SEXP:
return sys.newNullSexp();
case STRUCT:
return sys.newNullString();
default:
throw new IonException("unrecognized type encountered");
}
}
switch(_value_type) {
case NULL:
return sys.newNull();
case BOOL:
return sys.newBool(booleanValue());
case INT:
return sys.newInt(longValue());
case FLOAT:
return sys.newFloat(doubleValue());
case DECIMAL:
return sys.newDecimal(decimalValue());
case TIMESTAMP:
IonTimestamp t = sys.newNullTimestamp();
Timestamp ti = timestampValue();
t.setValue(ti);
return t;
case SYMBOL:
return sys.newSymbol(stringValue());
case STRING:
return sys.newString(stringValue());
case CLOB:
IonClob clob = sys.newNullClob();
// FIXME inefficient: both newBytes and setBytes copy the data
clob.setBytes(newBytes());
return clob;
case BLOB:
IonBlob blob = sys.newNullBlob();
// FIXME inefficient: both newBytes and setBytes copy the data
blob.setBytes(newBytes());
return blob;
case LIST:
IonList list = sys.newNullList();
fillContainerList(sys, list);
return list;
case SEXP:
IonSexp sexp = sys.newNullSexp();
fillContainerList(sys, sexp);
return sexp;
case STRUCT:
IonStruct struct = sys.newNullStruct();
fillContainerStruct(sys, struct);
return struct;
default:
throw new IonException("unrecognized type encountered");
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextSystemX method getBytes.
public int getBytes(byte[] buffer, int offset, int len) {
ensureLob("getBytes");
if (_lob_loaded == LOB_STATE.READ) {
// data to something useful
try {
load_lob_contents();
} catch (IOException e) {
throw new IonException(e);
}
}
int len_read;
if (_lob_loaded == LOB_STATE.FINISHED) {
// if we have loaded data, just copy it
len_read = len;
if (len_read > _lob_actual_len) {
len_read = _lob_actual_len;
}
System.arraycopy(_lob_bytes, 0, buffer, offset, len_read);
} else {
// the input source
try {
if (_current_value_save_point_loaded && _lob_value_position > 0) {
if (_current_value_save_point.isActive()) {
_scanner.save_point_deactivate(_current_value_save_point);
}
_scanner.save_point_activate(_current_value_save_point);
_lob_value_position = 0;
}
assert (_current_value_save_point_loaded && _current_value_save_point.isDefined());
_scanner.save_point_activate(_current_value_save_point);
len_read = readBytes(buffer, offset, len);
_scanner.save_point_deactivate(_current_value_save_point);
} catch (IOException e) {
throw new IonException(e);
}
}
return len_read;
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTreeSystem method newBytes.
public byte[] newBytes() {
if (_curr instanceof IonLob) {
IonLob lob = (IonLob) _curr;
int loblen = lob.byteSize();
byte[] buffer = new byte[loblen];
InputStream is = lob.newInputStream();
int retlen;
try {
retlen = readFully(is, buffer, 0, loblen);
is.close();
} catch (IOException e) {
throw new IonException(e);
}
assert (retlen == -1 ? loblen == 0 : retlen == loblen);
return buffer;
}
throw new IllegalStateException("current value is not an ion blob or clob");
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTreeSystem method getBytes.
public int getBytes(byte[] buffer, int offset, int len) {
if (_curr instanceof IonLob) {
IonLob lob = (IonLob) _curr;
int loblen = lob.byteSize();
if (loblen > len) {
throw new IllegalArgumentException("insufficient space in buffer for this value");
}
InputStream is = lob.newInputStream();
int retlen;
try {
retlen = readFully(is, buffer, 0, loblen);
is.close();
} catch (IOException e) {
throw new IonException(e);
}
assert retlen == loblen;
return retlen;
}
throw new IllegalStateException("current value is not an ion blob or clob");
}
Aggregations