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) {
}
}
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());
}
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);
}
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();
}
}
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());
}
Aggregations