-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGetData.java
More file actions
64 lines (51 loc) · 1.38 KB
/
GetData.java
File metadata and controls
64 lines (51 loc) · 1.38 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
package io;
import java.nio.*;
import java.util.*;
/**
* RUN:
* javac io/GetData.java && java io.GetData
*
* OUTPUT:
* i = 1025
* H o w d y !
* 12390
* 99471142
* 99471142
* 9.9471144E7
* 9.9471142E7
*/
public class GetData {
private static final int BSIZE = 1024;
public static void main(String[] args) {
ByteBuffer bb = ByteBuffer.allocate(BSIZE);
int i = 0;
while (i++ < bb.limit()) {
if (bb.get() != 0) {
System.out.println("nonzero");
}
}
System.out.println("i = " + i);
bb.rewind();
bb.asCharBuffer().put("Howdy!");
char c;
while ((c = bb.getChar()) != 0) {
System.out.print(c + " ");
}
System.out.println();
bb.rewind();
bb.asShortBuffer().put((short)471142);
System.out.println(bb.getShort());
bb.rewind();
bb.asIntBuffer().put(99471142);
System.out.println(bb.getInt());
bb.rewind();
bb.asLongBuffer().put(99471142);
System.out.println(bb.getLong());
bb.rewind();
bb.asFloatBuffer().put(99471142);
System.out.println(bb.getFloat());
bb.rewind();
bb.asDoubleBuffer().put(99471142);
System.out.println(bb.getDouble());
}
}