示例#1
0
 @Override
 public char[] read(IUnitChain unitChain) {
   final ByteBufferArray bba = ByteBufferArray.get();
   try {
     IUnit unit = unitChain.currentUnit();
     bba.add(unit.getByteBufferForRead(unit.position(), unit.remaining()));
     unit.position(unit.size());
     while ((unit = unitChain.nextUnit()) != null) {
       bba.add(unit.getByteBufferForRead(unit.position(), unit.remaining()));
       unit.position(unit.size());
     }
     final ICharsetCodec cc = CharsetCodec.get(m_charsetName);
     return cc.decode(bba.array(), 0, bba.size());
   } finally {
     bba.clear();
   }
 }
示例#2
0
  @Override
  public char[] read(IUnitChain unitChain, int length) {
    if (length < 0) throw new IllegalArgumentException();
    if (length == 0) return Helper.EMPTY_CHARS;

    final ByteBufferArray bba = ByteBufferArray.get();
    try {
      IUnit unit = unitChain.currentUnit();
      bba.add(unit.getByteBufferForRead(unit.position(), length));
      while ((length -= unit.skip(length)) > 0) {
        unit = unitChain.nextUnit();
        bba.add(unit.getByteBufferForRead(unit.position(), length));
      }
      final ICharsetCodec cc = CharsetCodec.get(m_charsetName);
      return cc.decode(bba.array(), 0, bba.size());
    } finally {
      bba.clear();
    }
  }