-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileClient2.java
More file actions
48 lines (39 loc) · 1.27 KB
/
FileClient2.java
File metadata and controls
48 lines (39 loc) · 1.27 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
import java.net.*;
import java.io.*;
import jatyc.lib.Typestate;
import jatyc.lib.Nullable;
@Typestate("FileClient2")
public class FileClient2 extends FileClient {
public String readLine() throws Exception {
StringBuilder sb = new StringBuilder();
while (lastByte != '\n' && lastByte != EOF) {
sb.append((char) lastByte);
lastByte = in.read();
}
if (lastByte == '\n') lastByte = in.read();
return sb.toString();
}
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Usage: java FileClient2 <filename>");
return;
}
String filename = args[0];
if (filename == null) {
System.out.println("Filename cannot be null!");
return;
}
FileClient2 client = new FileClient2();
if (client.start()) {
System.out.println("File client started!");
client.request(filename);
while (!client.eof()) {
String line = client.readLine();
System.out.println(line);
}
client.close();
} else {
System.out.println("Could not start client!");
}
}
}