-
Notifications
You must be signed in to change notification settings - Fork 81
/
Null_IO.java
44 lines (36 loc) · 1.13 KB
/
Null_IO.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
package dev.nipafx.demo.java11.api.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
public class Null_IO {
public static void main(String[] args) throws IOException {
inputStream();
outputStream();
reader();
writer();
}
private static void inputStream() throws IOException {
InputStream input = InputStream.nullInputStream();
System.out.println("Input stream content length: " + input.readAllBytes().length);
}
private static void outputStream() throws IOException {
OutputStream output = OutputStream.nullOutputStream();
output.write("This is going nowhere...".getBytes());
}
private static void reader() throws IOException {
Reader reader = Reader.nullReader();
char[] buffer = { '_', '_', '_' };
var ended = reader.read(buffer) == -1;
System.out.print("Buffer content:");
for (char c : buffer) {
System.out.print(" " + c);
}
System.out.println("\nStream ended? " + ended);
}
private static void writer() throws IOException {
Writer writer = Writer.nullWriter();
writer.write("This is going nowhere...");
}
}