コード例 #1
0
    private CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
      char[] sa = src.array();
      int sp = src.arrayOffset() + src.position();
      int sl = src.arrayOffset() + src.limit();

      byte[] da = dst.array();
      int dp = dst.arrayOffset() + dst.position();
      int dl = dst.arrayOffset() + dst.limit();
      int len = Math.min(dl - dp, sl - sp);

      while (len-- > 0) {
        char c = sa[sp];
        int b = encode(c);
        if (b == UNMAPPABLE_ENCODING) {
          if (Character.isSurrogate(c)) {
            if (sgp == null) sgp = new Surrogate.Parser();
            if (sgp.parse(c, sa, sp, sl) < 0) {
              return withResult(sgp.error(), src, sp, dst, dp);
            }
            return withResult(sgp.unmappableResult(), src, sp, dst, dp);
          }
          return withResult(CoderResult.unmappableForLength(1), src, sp, dst, dp);
        }
        da[dp++] = (byte) b;
        sp++;
      }
      return withResult(sp < sl ? CoderResult.OVERFLOW : CoderResult.UNDERFLOW, src, sp, dst, dp);
    }
コード例 #2
0
 public int encode(char[] src, int sp, int len, byte[] dst) {
   int dp = 0;
   int sl = sp + Math.min(len, dst.length);
   while (sp < sl) {
     char c = src[sp++];
     int b = encode(c);
     if (b != UNMAPPABLE_ENCODING) {
       dst[dp++] = (byte) b;
       continue;
     }
     if (Character.isHighSurrogate(c) && sp < sl && Character.isLowSurrogate(src[sp])) {
       if (len > dst.length) {
         sl++;
         len--;
       }
       sp++;
     }
     dst[dp++] = repl;
   }
   return dp;
 }