FileDocCategorySizeDatePackage
BufferFillDrain.javaAPI DocExample1325Sat May 18 21:55:40 BST 2002com.ronsoft.books.nio.buffers

BufferFillDrain

public class BufferFillDrain extends Object
Buffer fill/drain example. This code uses the simplest means of filling and draining a buffer: one element at a time. Created May 2002
author
Ron Hitchens (ron@ronsoft.com)
version
$Id: BufferFillDrain.java,v 1.2 2002/05/19 04:55:41 ron Exp $

Fields Summary
private static int
index
private static String[]
strings
Constructors Summary
Methods Summary
private static voiddrainBuffer(java.nio.CharBuffer buffer)

		while (buffer.hasRemaining()) {
			System.out.print (buffer.get());
		}

		System.out.println ("");
	
private static booleanfillBuffer(java.nio.CharBuffer buffer)

		if (index >= strings.length) {
			return (false);
		}

		String string = strings [index++];

		for (int i = 0; i < string.length(); i++) {
			buffer.put (string.charAt (i));
		}

		return (true);
	
public static voidmain(java.lang.String[] argv)

		CharBuffer buffer = CharBuffer.allocate (100);

		while (fillBuffer (buffer)) {
			buffer.flip();
			drainBuffer (buffer);
			buffer.clear();
		}