-
-
Notifications
You must be signed in to change notification settings - Fork 766
Expand file tree
/
Copy pathPaasio.java
More file actions
140 lines (101 loc) · 3.13 KB
/
Copy pathPaasio.java
File metadata and controls
140 lines (101 loc) · 3.13 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import java.io.*;
public class Paasio implements Closeable {
private long bytesRead;
private long readOperationCount;
private long bytesWritten;
private long writeOperationCount;
private final InputStream inputStream;
private final OutputStream outputStream;
public Paasio(InputStream inputStream, OutputStream outputStream) {
this.inputStream = inputStream;
this.outputStream = outputStream;
}
public int read() throws IOException {
int byteData = inputStream.read();
if (byteData != -1) {
bytesRead += 1;
readOperationCount++;
}
return byteData;
}
public int read(byte[] b) throws IOException {
int totalBytesRead = inputStream.read(b);
if (totalBytesRead != -1) {
bytesRead += totalBytesRead;
readOperationCount++;
}
return totalBytesRead;
}
public int read(byte[] b, int off, int len) throws IOException {
int bytesReadIntoBuffer = inputStream.read(b, off, len);
if (bytesReadIntoBuffer != -1) {
bytesRead += bytesReadIntoBuffer;
readOperationCount++;
}
return bytesReadIntoBuffer;
}
public byte[] readAllBytes() throws IOException {
byte[] allData = this.inputStream.readAllBytes();
if (allData.length > 0) {
readOperationCount++;
bytesRead += allData.length;
}
return allData;
}
public byte[] readNBytes(int len) throws IOException {
byte[] allData = this.inputStream.readNBytes(len);
if (allData.length > 0) {
readOperationCount++;
bytesRead += allData.length;
}
return allData;
}
public void write(int b) throws IOException {
try {
this.outputStream.write(b);
writeOperationCount++;
bytesWritten++;
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
public void write(byte[] b) throws IOException {
try {
this.outputStream.write(b);
writeOperationCount++;
bytesWritten += b.length;
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
public void write(byte[] b, int off, int len) throws IOException {
try {
this.outputStream.write(b, off, len);
writeOperationCount++;
bytesWritten += len;
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
public long getBytesRead() {
return bytesRead;
}
public long getReadOperationCount() {
return readOperationCount;
}
public long getBytesWritten() {
return bytesWritten;
}
public long getWriteOperationCount() {
return writeOperationCount;
}
@Override
public void close() throws IOException {
if (this.inputStream != null) {
this.inputStream.close();
}
if (this.outputStream != null) {
this.outputStream.close();
}
}
}