Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
60 lines (47 loc) · 1.53 KB

File metadata and controls

60 lines (47 loc) · 1.53 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package com.example.newio;
import java.nio.ByteBuffer;
/**
* Created by riven_chris on 15/8/8.
*/
public class GetData {
private static final int SIZE = 1024;
public static void main(String[] args) {
ByteBuffer buffer = ByteBuffer.allocate(SIZE);
//Allocation automatically zeroes the ByteBuffer
int i = 0;
while (i++ < buffer.limit()) {
if (buffer.get() != 0)
System.out.println("nonZero");
}
System.out.println("i = " + i);
buffer.rewind();
//store and read a char array;
buffer.asCharBuffer().put("Howdy!");
char c;
while ((c = buffer.getChar()) != 0) {
System.out.print(c + " ");
}
System.out.println();
buffer.rewind();
//store and read a short
buffer.asShortBuffer().put((short) 471142);
System.out.println(buffer.getShort());
buffer.rewind();
//store and read a int
buffer.asIntBuffer().put(2147483647);
System.out.println(buffer.getInt());
buffer.rewind();
//store and read a long
buffer.asLongBuffer().put(2147483647);
System.out.println(buffer.getLong());
buffer.rewind();
//store and read a float
buffer.asFloatBuffer().put(2147483647);
System.out.println(buffer.getFloat());
buffer.rewind();
//store and read a double
buffer.asDoubleBuffer().put(2147483647);
System.out.println(buffer.getDouble());
buffer.rewind();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.