protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) { int mark = src.position(); if (needsMark) { if (dst.remaining() < 2) return CoderResult.OVERFLOW; put(BYTE_ORDER_MARK, dst); needsMark = false; } try { while (src.hasRemaining()) { char c = src.get(); if (!Surrogate.is(c)) { if (dst.remaining() < 2) return CoderResult.OVERFLOW; mark++; put(c, dst); continue; } int d = sgp.parse(c, src); if (d < 0) return sgp.error(); if (dst.remaining() < 4) return CoderResult.OVERFLOW; mark += 2; put(Surrogate.high(d), dst); put(Surrogate.low(d), dst); } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
public boolean canEncode(char c) { return !Surrogate.is(c); }