Changeset 15387


Ignore:
Timestamp:
10/01/20 22:29:11 (3 years ago)
Author:
Mark Evenson
Message:

Reset file charset decoder before conversion

Using FILE-POSITION to rewind streams that had advanced past the EOF
was throwing internal Java exceptions.

Fixes <https://abcl.org/trac/ticket/473>.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java

    r15359 r15387  
    4949import java.nio.charset.CharsetDecoder;
    5050import java.nio.charset.CharsetEncoder;
     51import java.nio.charset.CoderMalfunctionError;
    5152import java.nio.charset.CoderResult;
    5253import java.nio.charset.CodingErrorAction;
     
    387388    final int read(char[] cb, int off, int len) throws IOException {
    388389        CharBuffer cbuf = CharBuffer.wrap(cb, off, len);
     390        cdec.reset();
    389391        boolean decodeWasUnderflow = false;
    390392        boolean atEof = false;
     
    392394            int oldRemaining = cbuf.remaining();
    393395            atEof = ! ensureReadBbuf(decodeWasUnderflow);
    394             CoderResult r = cdec.decode(bbuf, cbuf, atEof );
     396            CoderResult r;
     397            try {
     398              r = cdec.decode(bbuf, cbuf, atEof );
     399            } catch (IllegalStateException e) {
     400              throw new IOException("CharsetDecoder failed", e);
     401            } catch (CoderMalfunctionError e) {
     402              throw new IOException("CharsetDecoder malfunction", e);
     403            }
     404             
    395405            if (oldRemaining == cbuf.remaining()
    396406                && CoderResult.OVERFLOW == r) {
Note: See TracChangeset for help on using the changeset viewer.