use of com.amazon.ion.IonException in project ion-java by amzn.
the class _Private_Utils method encode.
// ========================================================================
/**
* Encodes a String into bytes of a given encoding.
* <p>
* This method is preferred to {@link Charset#encode(String)} and
* {@link String#getBytes(String)} (<em>etc.</em>)
* since those methods will replace or ignore bad input, and here we throw
* an exception.
*
* @param s the string to encode.
*
* @return the encoded string, not null.
*
* @throws IonException if there's a {@link CharacterCodingException}.
*/
public static byte[] encode(String s, Charset charset) {
CharsetEncoder encoder = charset.newEncoder();
try {
ByteBuffer buffer = encoder.encode(CharBuffer.wrap(s));
byte[] bytes = buffer.array();
// Make another copy iff there's garbage after the limit.
int limit = buffer.limit();
if (limit < bytes.length) {
bytes = copyOf(bytes, limit);
}
return bytes;
} catch (CharacterCodingException e) {
throw new IonException("Invalid string data", e);
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonLoaderLite method load.
public IonDatagram load(Reader ionText) throws IonException, IOException {
try {
IonReader reader = _readerBuilder.build(ionText);
IonDatagramLite datagram = load_helper(reader);
return datagram;
} catch (IonException e) {
IOException io = e.causeOfType(IOException.class);
if (io != null)
throw io;
throw e;
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonLoaderLite method load.
public IonDatagram load(String ionText) throws IonException {
try {
IonReader reader = _readerBuilder.build(ionText);
IonDatagramLite datagram = load_helper(reader);
return datagram;
} catch (IOException e) {
throw new IonException(e);
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextRawX method stepOut.
public void stepOut() {
if (getDepth() < 1) {
throw new IllegalStateException(IonMessages.CANNOT_STEP_OUT);
}
try {
finish_value(null);
switch(getContainerType()) {
case STRUCT:
if (!_eof)
_scanner.skip_over_struct();
break;
case LIST:
if (!_eof)
_scanner.skip_over_list();
break;
case SEXP:
if (!_eof)
_scanner.skip_over_sexp();
break;
case DATAGRAM:
break;
default:
throw new IllegalStateException("Unexpected value type: " + _value_type);
}
} catch (IOException e) {
throw new IonException(e);
}
pop_container_state();
_scanner.tokenIsFinished();
try {
finish_value(null);
} catch (IOException e) {
throw new IonException(e);
}
clear_value();
if (_debug)
System.out.println("stepOUT() new depth: " + getDepth());
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextSystemX method load_lob_contents.
private int load_lob_contents() throws IOException {
if (_lob_loaded == LOB_STATE.EMPTY) {
load_lob_save_point();
}
if (_lob_loaded == LOB_STATE.READ) {
long raw_size = _current_value_save_point.length();
if (raw_size < 0 || raw_size > Integer.MAX_VALUE) {
load_lob_length_overflow_error(raw_size);
}
_lob_bytes = new byte[(int) raw_size];
try {
assert (_current_value_save_point_loaded && _current_value_save_point.isDefined());
_scanner.save_point_activate(_current_value_save_point);
_lob_actual_len = readBytes(_lob_bytes, 0, (int) raw_size);
_scanner.save_point_deactivate(_current_value_save_point);
} catch (IOException e) {
throw new IonException(e);
}
assert (_lob_actual_len <= raw_size);
_lob_loaded = LOB_STATE.FINISHED;
}
assert (_lob_loaded == LOB_STATE.FINISHED);
return _lob_actual_len;
}
Aggregations