Code example for CharBuffer

Methods: array

0
		MockCharset c1 = new MockCharset("mock", null);
		CharBuffer cb = c1.decode(ByteBuffer.wrap("abcdefg"
				.getBytes("iso8859-1")));
		assertEquals("abcdefg", new String(cb.array()));
		cb = c1.decode(ByteBuffer.wrap("".getBytes("iso8859-1")));
		assertEquals("", new String(cb.array()));
	} 
 
	/* 
	 * Test the method decode(ByteBuffer) with a malformed input. 
	 */ 
	public void testDecode_Malformed() throws Exception { 
		Charset c1 = Charset.forName("iso8859-1");
		CharBuffer cb = c1.decode(ByteBuffer.wrap("abcd\u5D14efg"
				.getBytes("iso8859-1")));
		byte[] replacement = c1.newEncoder().replacement();
		assertEquals(new String(cb.array()).trim(), "abcd" + new String(replacement, "iso8859-1")
				+ "efg"); 
	} 
 
Experience pair programming with AI  Get Codota for Java