Search in sources :

Example 51 with CharBuffer

use of java.nio.CharBuffer in project robovm by robovm.

the class OldReaderTest method test_Reader_CharBufferChar.

public void test_Reader_CharBufferChar() throws IOException {
    Support_ASimpleReader simple;
    simple = new Support_ASimpleReader("Bla bla, what else?");
    CharBuffer buf = CharBuffer.allocate(4);
    assertEquals("Wrong return value!", 4, simple.read(buf));
    buf.rewind();
    assertEquals("Wrong stuff read!", "Bla ", String.valueOf(buf));
    simple.read(buf);
    buf.rewind();
    assertEquals("Wrong stuff read!", "bla,", String.valueOf(buf));
    simple.throwExceptionOnNextUse = true;
    try {
        simple.read(buf);
        fail("IOException not thrown!");
    } catch (IOException expected) {
    }
}
Also used : Support_ASimpleReader(tests.support.Support_ASimpleReader) CharBuffer(java.nio.CharBuffer) IOException(java.io.IOException)

Example 52 with CharBuffer

use of java.nio.CharBuffer in project robovm by robovm.

the class CharsetDecoderTest method test_ByteArray_decode_with_offset_using_facade_method.

// http://code.google.com/p/android/issues/detail?id=4237
public void test_ByteArray_decode_with_offset_using_facade_method() throws Exception {
    CharsetDecoder decoder = Charset.forName("UTF-16").newDecoder();
    byte[] arr = encode("UTF-16", "Android");
    arr = prependByteToByteArray(arr, new Integer(1).byteValue());
    int offset = 1;
    CharBuffer outBuffer = decoder.decode(ByteBuffer.wrap(arr, offset, arr.length - offset));
    assertEquals("Android", outBuffer.toString().trim());
}
Also used : CharsetDecoder(java.nio.charset.CharsetDecoder) CharBuffer(java.nio.CharBuffer)

Example 53 with CharBuffer

use of java.nio.CharBuffer in project robovm by robovm.

the class OldCharset_MultiByte_EUC_JP method test_CodecDynamic.

@Override
public void test_CodecDynamic() throws CharacterCodingException {
    encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    decoder.onMalformedInput(CodingErrorAction.REPORT);
    CharBuffer inputCB = CharBuffer.allocate(65536);
    for (char codePoint = 0; codePoint <= 0xfffe; ++codePoint) {
        if (encoder.canEncode(codePoint)) {
            inputCB.put(codePoint);
        }
    }
    inputCB.rewind();
    ByteBuffer intermediateBB = encoder.encode(inputCB);
    inputCB.rewind();
    intermediateBB.rewind();
    CharBuffer outputCB = decoder.decode(intermediateBB);
    outputCB.rewind();
    assertEqualCBs("decode(encode(A)) must be identical with A!", inputCB, outputCB);
}
Also used : CharBuffer(java.nio.CharBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 54 with CharBuffer

use of java.nio.CharBuffer in project robovm by robovm.

the class OldCharset_SingleByteAbstractTest method dumpDecoded.

public static void dumpDecoded() {
    Charset_TestGenerator.Dumper out = new Charset_TestGenerator.Dumper1();
    ByteBuffer inputBB = ByteBuffer.wrap(allBytes);
    CharBuffer outputCB;
    decoder.onMalformedInput(CodingErrorAction.REPLACE);
    try {
        outputCB = decoder.decode(inputBB);
        outputCB.rewind();
        while (outputCB.hasRemaining()) {
            out.consume(outputCB.get());
        }
    } catch (CharacterCodingException e) {
        System.out.println(e);
    //                e.printStackTrace();
    }
}
Also used : CharBuffer(java.nio.CharBuffer) CharacterCodingException(java.nio.charset.CharacterCodingException) ByteBuffer(java.nio.ByteBuffer)

Example 55 with CharBuffer

use of java.nio.CharBuffer in project robovm by robovm.

the class CharsetDecoderTest method test_ByteArray_decode_with_offset.

// http://code.google.com/p/android/issues/detail?id=4237
public void test_ByteArray_decode_with_offset() throws Exception {
    CharsetDecoder decoder = Charset.forName("UTF-16").newDecoder();
    byte[] arr = encode("UTF-16", "Android");
    arr = prependByteToByteArray(arr, new Integer(1).byteValue());
    int offset = 1;
    ByteBuffer inBuffer = ByteBuffer.wrap(arr, offset, arr.length - offset).slice();
    CharBuffer outBuffer = CharBuffer.allocate(arr.length - offset);
    decoder.reset();
    CoderResult coderResult = decoder.decode(inBuffer, outBuffer, true);
    assertFalse(coderResult.toString(), coderResult.isError());
    decoder.flush(outBuffer);
    outBuffer.flip();
    assertEquals("Android", outBuffer.toString().trim());
}
Also used : CharsetDecoder(java.nio.charset.CharsetDecoder) CharBuffer(java.nio.CharBuffer) ByteBuffer(java.nio.ByteBuffer) CoderResult(java.nio.charset.CoderResult)

Aggregations

CharBuffer (java.nio.CharBuffer)401 ByteBuffer (java.nio.ByteBuffer)152 CoderResult (java.nio.charset.CoderResult)83 CharsetDecoder (java.nio.charset.CharsetDecoder)47 IOException (java.io.IOException)45 Charset (java.nio.charset.Charset)33 Test (org.junit.Test)23 CharacterCodingException (java.nio.charset.CharacterCodingException)15 CharsetEncoder (java.nio.charset.CharsetEncoder)15 FileInputStream (java.io.FileInputStream)11 IntBuffer (java.nio.IntBuffer)10 Reader (java.io.Reader)9 BufferOverflowException (java.nio.BufferOverflowException)9 DoubleBuffer (java.nio.DoubleBuffer)9 FloatBuffer (java.nio.FloatBuffer)9 LongBuffer (java.nio.LongBuffer)9 ShortBuffer (java.nio.ShortBuffer)9 BufferUnderflowException (java.nio.BufferUnderflowException)7 ValueWrapper (org.apache.geode.internal.memcached.ValueWrapper)7 InputStream (java.io.InputStream)6