Charset encoding = encodingSpecToCharset(encodingSpec);
if (encoding == null)
throw ERT.badarg(charlist, encodingSpec);
CharArrayWriter out = new CharArrayWriter();
CharCollector collector = new CharCollector(encoding, out);
ESeq rest = ERT.NIL;
try {
rest = charlist.collectCharList(collector, rest);
} catch (CharCollector.InvalidElementException e) {
throw ERT.badarg(charlist, encodingSpec);
} catch (CharCollector.CollectingException e) {
EObject data = output_converter.convert(out);
return ETuple.make(ERROR_ATOM, data, e.restOfInput);
} catch (IOException e) {
throw new Error(e); // Not supposed to happen.
}
try {
collector.end();
if (rest != ERT.NIL) {
return ETuple.make(INCOMPLETE_ATOM,
output_converter.convert(out),
ErlConvert.iolist_to_binary(rest.reverse()));