コード例 #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
 private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
   int mark = src.position();
   try {
     while (src.hasRemaining()) {
       char c = src.get();
       int b = encode(c);
       if (b == UNMAPPABLE_ENCODING) {
         if (Character.isSurrogate(c)) {
           if (sgp == null) sgp = new Surrogate.Parser();
           if (sgp.parse(c, src) < 0) return sgp.error();
           return sgp.unmappableResult();
         }
         return CoderResult.unmappableForLength(1);
       }
       if (!dst.hasRemaining()) return CoderResult.OVERFLOW;
       dst.put((byte) b);
       mark++;
     }
     return CoderResult.UNDERFLOW;
   } finally {
     src.position(mark);
   }
 }