-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathViewBuffers.java
More file actions
81 lines (69 loc) · 2.3 KB
/
ViewBuffers.java
File metadata and controls
81 lines (69 loc) · 2.3 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package io;
import java.nio.*;
import java.util.*;
/**
* RUN:
* javac io/ViewBuffers.java && java io.ViewBuffers
*
* OUTPUT:
* Byte BUffer: 0->0 1->0 2->0 3->0 4->0 5->0 6->0 7->97
* Char BUffer: 0-> 1-> 2-> 3->a
* Float BUffer: 0->0.0 1->1.36E-43
* Int BUffer: 0->0 1->97
* Long BUffer: 0->97
* Short BUffer: 0->0 1->0 2->0 3->97
* Double BUffer: 0->4.8E-322
*/
public class ViewBuffers {
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.wrap(new byte[]{0,0,0,0,0,0,0,'a'});
bb.rewind();
System.out.print("Byte BUffer: ");
while (bb.hasRemaining()) {
System.out.print(bb.position() + "->" + bb.get() + " ");
}
System.out.println();
bb.rewind();
CharBuffer cb = bb.asCharBuffer();
System.out.print("Char BUffer: ");
while (cb.hasRemaining()) {
System.out.print(cb.position() + "->" + cb.get() + " ");
}
System.out.println();
bb.rewind();
FloatBuffer fb = bb.asFloatBuffer();
System.out.print("Float BUffer: ");
while (fb.hasRemaining()) {
System.out.print(fb.position() + "->" + fb.get() + " ");
}
System.out.println();
bb.rewind();
IntBuffer ib = bb.asIntBuffer();
System.out.print("Int BUffer: ");
while (ib.hasRemaining()) {
System.out.print(ib.position() + "->" + ib.get() + " ");
}
System.out.println();
bb.rewind();
LongBuffer lb = bb.asLongBuffer();
System.out.print("Long BUffer: ");
while (lb.hasRemaining()) {
System.out.print(lb.position() + "->" + lb.get() + " ");
}
System.out.println();
bb.rewind();
ShortBuffer sb = bb.asShortBuffer();
System.out.print("Short BUffer: ");
while (sb.hasRemaining()) {
System.out.print(sb.position() + "->" + sb.get() + " ");
}
System.out.println();
bb.rewind();
DoubleBuffer db = bb.asDoubleBuffer();
System.out.print("Double BUffer: ");
while (db.hasRemaining()) {
System.out.print(db.position() + "->" + db.get() + " ");
}
System.out.println();
}
}