Exemple #1
0
 @Override
 public void prepend(char[] chars, int offset, int length, IUnitChain unitChain) {
   final ICharsetCodec cc = CharsetCodec.get(m_charsetName);
   try (BytesBuilder bb = BytesBuilder.get()) {
     cc.encode(chars, offset, length, bb);
     length = bb.length();
     IUnit unit = Util.firstUnit(unitChain);
     while ((length -= Helper.prepend(bb, 0, length, unit)) > 0)
       unit = Util.prependNewUnit(unitChain);
   }
 }
Exemple #2
0
 @Override
 public char[] get(IUnitChain unitChain, int index) {
   final ByteBufferArray bba = ByteBufferArray.get();
   try {
     IUnit unit = unitChain.currentUnit();
     bba.add(unit.getByteBufferForRead(index, unit.size() - index));
     while ((unit = unitChain.nextUnit()) != null)
       bba.add(unit.getByteBufferForRead(0, unit.size()));
     final ICharsetCodec cc = CharsetCodec.get(m_charsetName);
     return cc.decode(bba.array(), 0, bba.size());
   } finally {
     bba.clear();
   }
 }
Exemple #3
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();
   }
 }
Exemple #4
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();
    }
  }
Exemple #5
0
  @Override
  public char[] get(IUnitChain unitChain, int index, int length) {
    if (length < 0) throw new IndexOutOfBoundsException();
    if (length == 0) return Helper.EMPTY_CHARS;

    final ByteBufferArray bba = ByteBufferArray.get();
    try {
      IUnit unit = unitChain.currentUnit();
      bba.add(unit.getByteBufferForRead(index, length));
      length -= (unit.size() - index);
      while (length > 0) {
        unit = unitChain.nextUnit();
        if (unit == null) throw new IndexOutOfBoundsException();
        bba.add(unit.getByteBufferForRead(0, length));
        length -= unit.size();
      }
      final ICharsetCodec cc = CharsetCodec.get(m_charsetName);
      return cc.decode(bba.array(), 0, bba.size());
    } finally {
      bba.clear();
    }
  }
Exemple #6
0
 @Override
 public void write(char[] chars, int offset, int length, IUnitChain unitChain) {
   final ICharsetCodec cc = CharsetCodec.get(m_charsetName);
   Helper.write(cc, CharBuffer.wrap(chars, offset, length), unitChain);
 }