-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathBufferedIOMixin.java
More file actions
117 lines (98 loc) · 2.42 KB
/
Copy pathBufferedIOMixin.java
File metadata and controls
117 lines (98 loc) · 2.42 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
/* Copyright (c) 2007 Jython Developers */
package org.python.core.io;
import java.io.InputStream;
import java.io.OutputStream;
import org.python.core.Py;
import org.python.core.PyException;
/**
* A mixin implementation of BufferedIOBase with an underlying raw
* stream.
*
* This passes most requests on to the underlying raw stream. It does
* *not* provide implementations of read(), readinto() or write().
*
* @author Philip Jenvey
*/
public abstract class BufferedIOMixin extends BufferedIOBase {
/** The underlying raw io stream */
protected RawIOBase rawIO;
/** The size of the buffer */
protected int bufferSize;
/**
* Initialize this buffer, wrapping the given RawIOBase.
*
* @param rawIO a RawIOBase to wrap
*/
public BufferedIOMixin(RawIOBase rawIO) {
this(rawIO, DEFAULT_BUFFER_SIZE);
}
/**
* Initialize this buffer, wrapping the given RawIOBase.
*
* @param rawIO a RawIOBase to wrap
* @param bufferSize the size of the buffer
*/
public BufferedIOMixin(RawIOBase rawIO, int bufferSize) {
this.rawIO = rawIO;
this.bufferSize = bufferSize;
}
@Override
public long seek(long pos, int whence) {
return rawIO.seek(pos, whence);
}
@Override
public long tell() {
return rawIO.tell();
}
@Override
public long truncate(long size) {
return rawIO.truncate(size);
}
@Override
public void flush() {
rawIO.flush();
}
@Override
public void close() {
if (closed()) {
return;
}
try {
flush();
} catch (PyException pye) {
if (!pye.match(Py.IOError)) {
throw pye;
}
// If flush() fails, just give up
}
rawIO.close();
}
@Override
public RawIOBase fileno() {
return rawIO.fileno();
}
@Override
public boolean isatty() {
return rawIO.isatty();
}
@Override
public boolean readable() {
return rawIO.readable();
}
@Override
public boolean writable() {
return rawIO.writable();
}
@Override
public boolean closed() {
return rawIO.closed();
}
@Override
public InputStream asInputStream() {
return rawIO.asInputStream();
}
@Override
public OutputStream asOutputStream() {
return rawIO.asOutputStream();
}
}