-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestRemoteBuf.java
90 lines (82 loc) · 2.65 KB
/
TestRemoteBuf.java
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
82
83
84
85
86
87
88
89
90
import org.bytedeco.javacpp.*;
import java.io.*;
import java.nio.ByteBuffer;
import ucb.remotebuf.*;
public class TestRemoteBuf {
public static void main(String[] args) {
RemoteBuf.BufferManager BM = new RemoteBuf.BufferManager();
{
RemoteBuf.Buffer B = BM.createBuffer("buf1");
if (!BM.bufferExists("buf1"))
throw new RuntimeException("buffer wasn't created");
String msg = "hihihi";
B.write(msg.getBytes(), msg.getBytes().length);
B.flush();
byte result[] = new byte[B.getSize()];
B.read(result);
String strRes = new String(result);
if (!strRes.equals(msg))
throw new RuntimeException("buffers didn't match");
}
{
RemoteBuf.Buffer B2 = BM.createBuffer("buf2");
String msg = "hello";
B2.write(msg.getBytes(), msg.getBytes().length);
msg = "there";
B2.write(msg.getBytes(), msg.getBytes().length);
B2.flush();
byte result2[] = new byte[B2.getSize()];
B2.read(result2);
String strRes2 = new String(result2);
if (!strRes2.equals("hellothere"))
throw new RuntimeException("buffers didn't match: " + strRes2);
}
{
RemoteBuf.Buffer B3 = BM.createBuffer("buf3");
String msg = "buffeeeerrrrr3";
ROutputStream OS = new ROutputStream(B3);
try {
OS.write(msg.getBytes());
OS.close();
} catch (IOException e) {
e.printStackTrace();
}
byte result3[] = new byte[B3.getSize()];
B3.read(result3);
String strRes3 = new String(result3);
if (!strRes3.equals(msg))
throw new RuntimeException("buffers didn't match: " + strRes3);
}
{
RemoteBuf.Buffer buf = BM.createBuffer("buf4");
String msg = "buffeeeerrrrr4";
RWritableByteChannel WBC = new RWritableByteChannel(buf);
ByteBuffer BB = ByteBuffer.wrap(msg.getBytes());
WBC.write(BB);
byte res[] = new byte[buf.getSize()];
buf.read(res);
String resStr = new String(res);
if (!resStr.equals(msg))
throw new RuntimeException("buffers didn't match: " + resStr);
}
{
RemoteBuf.Buffer buf = BM.createBuffer("buf5");
String msg = "holahola";
ROutputStream OS = new ROutputStream(buf);
try {
OS.write(msg.getBytes());
OS.write(msg.getBytes(), 2, 4);
} catch (IOException e) {
e.printStackTrace();
}
OS.close();
byte res[] = new byte[buf.getSize()];
buf.read(res);
msg = "hoholalahola";
String resStr = new String(res);
if (!resStr.equals(msg))
throw new RuntimeException("buffers didn't match: " + resStr);
}
System.out.println("OK");
}
}