FileDocCategorySizeDatePackage
BufferCharView.javaAPI DocExample1263Mon May 20 00:24:24 BST 2002com.ronsoft.books.nio.buffers

BufferCharView

public class BufferCharView extends Object
Test asCharBuffer view. Created May 2002
author
Ron Hitchens (ron@ronsoft.com)
version
$Id: BufferCharView.java,v 1.2 2002/05/20 07:24:24 ron Exp $

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

		ByteBuffer byteBuffer =
			ByteBuffer.allocate (7).order (ByteOrder.BIG_ENDIAN);
		CharBuffer charBuffer = byteBuffer.asCharBuffer();

		// load the ByteBuffer with some bytes
		byteBuffer.put (0, (byte)0);
		byteBuffer.put (1, (byte)'H");
		byteBuffer.put (2, (byte)0);
		byteBuffer.put (3, (byte)'i");
		byteBuffer.put (4, (byte)0);
		byteBuffer.put (5, (byte)'!");
		byteBuffer.put (6, (byte)0);

		println (byteBuffer);
		println (charBuffer);

		// now slice it differently
		byteBuffer.position (4);
		charBuffer = byteBuffer.asCharBuffer();

		println (byteBuffer);
		println (charBuffer);
	
private static voidprintln(java.nio.Buffer buffer)

		System.out.println ("pos=" + buffer.position()
			+ ", limit=" + buffer.limit()
			+ ", capacity=" + buffer.capacity()
			+ ": '" + buffer.toString() + "'");