Java Code Examples for java.nio.charset.CodingErrorAction#REPLACE

The following examples show how to use java.nio.charset.CodingErrorAction#REPLACE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: B2CConverter.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public B2CConverter(Charset charset, boolean replaceOnError) {
    byte[] left = new byte[LEFTOVER_SIZE];
    leftovers = ByteBuffer.wrap(left);
    CodingErrorAction action;
    if (replaceOnError) {
        action = CodingErrorAction.REPLACE;
    } else {
        action = CodingErrorAction.REPORT;
    }
    // Special case. Use the Apache Harmony based UTF-8 decoder because it
    // - a) rejects invalid sequences that the JVM decoder does not
    // - b) fails faster for some invalid sequences
    if (charset.equals(StandardCharsets.UTF_8)) {
        decoder = new Utf8Decoder();
    } else {
        decoder = charset.newDecoder();
    }
    decoder.onMalformedInput(action);
    decoder.onUnmappableCharacter(action);
}
 
Example 2
Source File: BaseFileManager.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
    Charset cs = (this.charset == null)
        ? Charset.forName(encodingName)
        : this.charset;
    CharsetDecoder decoder = cs.newDecoder();

    CodingErrorAction action;
    if (ignoreEncodingErrors)
        action = CodingErrorAction.REPLACE;
    else
        action = CodingErrorAction.REPORT;

    return decoder
        .onMalformedInput(action)
        .onUnmappableCharacter(action);
}
 
Example 3
Source File: BaseFileManager.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
    Charset cs = (this.charset == null)
        ? Charset.forName(encodingName)
        : this.charset;
    CharsetDecoder decoder = cs.newDecoder();

    CodingErrorAction action;
    if (ignoreEncodingErrors)
        action = CodingErrorAction.REPLACE;
    else
        action = CodingErrorAction.REPORT;

    return decoder
        .onMalformedInput(action)
        .onUnmappableCharacter(action);
}
 
Example 4
Source File: BaseFileManager.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
    Charset cs = (this.charset == null)
        ? Charset.forName(encodingName)
        : this.charset;
    CharsetDecoder decoder = cs.newDecoder();

    CodingErrorAction action;
    if (ignoreEncodingErrors)
        action = CodingErrorAction.REPLACE;
    else
        action = CodingErrorAction.REPORT;

    return decoder
        .onMalformedInput(action)
        .onUnmappableCharacter(action);
}
 
Example 5
Source File: BaseFileManager.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
    Charset cs = (this.charset == null)
        ? Charset.forName(encodingName)
        : this.charset;
    CharsetDecoder decoder = cs.newDecoder();

    CodingErrorAction action;
    if (ignoreEncodingErrors)
        action = CodingErrorAction.REPLACE;
    else
        action = CodingErrorAction.REPORT;

    return decoder
        .onMalformedInput(action)
        .onUnmappableCharacter(action);
}
 
Example 6
Source File: BaseFileManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
    Charset cs = (this.charset == null)
        ? Charset.forName(encodingName)
        : this.charset;
    CharsetDecoder decoder = cs.newDecoder();

    CodingErrorAction action;
    if (ignoreEncodingErrors)
        action = CodingErrorAction.REPLACE;
    else
        action = CodingErrorAction.REPORT;

    return decoder
        .onMalformedInput(action)
        .onUnmappableCharacter(action);
}
 
Example 7
Source File: CESU_8.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = replacement()[0];
            } else {
                to3Bytes(da, dp, Character.highSurrogate(uc));
                dp += 3;
                to3Bytes(da, dp, Character.lowSurrogate(uc));
                dp += 3;
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            to3Bytes(da, dp, c);
            dp += 3;
        }
    }
    return dp;
}
 
Example 8
Source File: UTF_8.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = repl;
            } else {
                da[dp++] = (byte)(0xf0 | ((uc >> 18)));
                da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
                da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
                da[dp++] = (byte)(0x80 | (uc & 0x3f));
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            da[dp++] = (byte)(0xe0 | ((c >> 12)));
            da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        }
    }
    return dp;
}
 
Example 9
Source File: UTF_8.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = repl;
            } else {
                da[dp++] = (byte)(0xf0 | ((uc >> 18)));
                da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
                da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
                da[dp++] = (byte)(0x80 | (uc & 0x3f));
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            da[dp++] = (byte)(0xe0 | ((c >> 12)));
            da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        }
    }
    return dp;
}
 
Example 10
Source File: UTF_8.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = repl;
            } else {
                da[dp++] = (byte)(0xf0 | ((uc >> 18)));
                da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
                da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
                da[dp++] = (byte)(0x80 | (uc & 0x3f));
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            da[dp++] = (byte)(0xe0 | ((c >> 12)));
            da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        }
    }
    return dp;
}
 
Example 11
Source File: EmptyLombokFileObject.java    From EasyMPermission with MIT License 4 votes vote down vote up
@Override public CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
	CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
	CodingErrorAction action = ignoreEncodingErrors ? CodingErrorAction.REPLACE : CodingErrorAction.REPORT;
	return decoder.onMalformedInput(action).onUnmappableCharacter(action);
}
 
Example 12
Source File: CESU_8.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = replacement()[0];
            } else {
                to3Bytes(da, dp, Character.highSurrogate(uc));
                dp += 3;
                to3Bytes(da, dp, Character.lowSurrogate(uc));
                dp += 3;
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            to3Bytes(da, dp, c);
            dp += 3;
        }
    }
    return dp;
}
 
Example 13
Source File: UTF_8.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = repl;
            } else {
                da[dp++] = (byte)(0xf0 | ((uc >> 18)));
                da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
                da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
                da[dp++] = (byte)(0x80 | (uc & 0x3f));
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            da[dp++] = (byte)(0xe0 | ((c >> 12)));
            da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        }
    }
    return dp;
}
 
Example 14
Source File: CESU_8.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = replacement()[0];
            } else {
                to3Bytes(da, dp, Character.highSurrogate(uc));
                dp += 3;
                to3Bytes(da, dp, Character.lowSurrogate(uc));
                dp += 3;
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            to3Bytes(da, dp, c);
            dp += 3;
        }
    }
    return dp;
}
 
Example 15
Source File: CESU_8.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = replacement()[0];
            } else {
                to3Bytes(da, dp, Character.highSurrogate(uc));
                dp += 3;
                to3Bytes(da, dp, Character.lowSurrogate(uc));
                dp += 3;
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            to3Bytes(da, dp, c);
            dp += 3;
        }
    }
    return dp;
}
 
Example 16
Source File: UTF_8.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = repl;
            } else {
                da[dp++] = (byte)(0xf0 | ((uc >> 18)));
                da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
                da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
                da[dp++] = (byte)(0x80 | (uc & 0x3f));
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            da[dp++] = (byte)(0xe0 | ((c >> 12)));
            da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        }
    }
    return dp;
}
 
Example 17
Source File: CESU_8.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = replacement()[0];
            } else {
                to3Bytes(da, dp, Character.highSurrogate(uc));
                dp += 3;
                to3Bytes(da, dp, Character.lowSurrogate(uc));
                dp += 3;
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            to3Bytes(da, dp, c);
            dp += 3;
        }
    }
    return dp;
}
 
Example 18
Source File: CESU_8.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = replacement()[0];
            } else {
                to3Bytes(da, dp, Character.highSurrogate(uc));
                dp += 3;
                to3Bytes(da, dp, Character.lowSurrogate(uc));
                dp += 3;
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            to3Bytes(da, dp, c);
            dp += 3;
        }
    }
    return dp;
}
 
Example 19
Source File: CESU_8.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = replacement()[0];
            } else {
                to3Bytes(da, dp, Character.highSurrogate(uc));
                dp += 3;
                to3Bytes(da, dp, Character.lowSurrogate(uc));
                dp += 3;
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            to3Bytes(da, dp, c);
            dp += 3;
        }
    }
    return dp;
}
 
Example 20
Source File: UTF_8.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public int encode(char[] sa, int sp, int len, byte[] da) {
    int sl = sp + len;
    int dp = 0;
    int dlASCII = dp + Math.min(len, da.length);

    // ASCII only optimized loop
    while (dp < dlASCII && sa[sp] < '\u0080')
        da[dp++] = (byte) sa[sp++];

    while (sp < sl) {
        char c = sa[sp++];
        if (c < 0x80) {
            // Have at most seven bits
            da[dp++] = (byte)c;
        } else if (c < 0x800) {
            // 2 bytes, 11 bits
            da[dp++] = (byte)(0xc0 | (c >> 6));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        } else if (Character.isSurrogate(c)) {
            if (sgp == null)
                sgp = new Surrogate.Parser();
            int uc = sgp.parse(c, sa, sp - 1, sl);
            if (uc < 0) {
                if (malformedInputAction() != CodingErrorAction.REPLACE)
                    return -1;
                da[dp++] = repl;
            } else {
                da[dp++] = (byte)(0xf0 | ((uc >> 18)));
                da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
                da[dp++] = (byte)(0x80 | ((uc >>  6) & 0x3f));
                da[dp++] = (byte)(0x80 | (uc & 0x3f));
                sp++;  // 2 chars
            }
        } else {
            // 3 bytes, 16 bits
            da[dp++] = (byte)(0xe0 | ((c >> 12)));
            da[dp++] = (byte)(0x80 | ((c >>  6) & 0x3f));
            da[dp++] = (byte)(0x80 | (c & 0x3f));
        }
    }
    return dp;
}