-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferView.java
More file actions
43 lines (38 loc) · 1.28 KB
/
Copy pathBufferView.java
File metadata and controls
43 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.ByteOrder;
/**
* Test asCharBuffer view.
*
* Created May 2002
* @author Ron Hitchens (ron@ronsoft.com)
*/
public class BufferView
{
public static void main (String [] argv)
throws Exception
{
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);
}
// Print info about a buffer
private static void println (Buffer buffer)
{
System.out.println ("pos=" + buffer.position( )
+ ", limit=" + buffer.limit( )
+ ", capacity=" + buffer.capacity( )
+ ": '" + buffer.toString( ) + "'");
}
}