-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathBufferedIOBase.java
More file actions
136 lines (124 loc) · 3.61 KB
/
BufferedIOBase.java
File metadata and controls
136 lines (124 loc) · 3.61 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
/* Copyright (c) 2007 Jython Developers */
package org.python.core.io;
import java.nio.ByteBuffer;
/**
* Base class for buffered I/O objects.
*
* @author Philip Jenvey
*/
public abstract class BufferedIOBase extends IOBase {
/**
* Read and return up to size bytes, contained in a ByteBuffer.
*
* ByteBuffers returned from read are already flip()'d.
*
* Returns an empty ByteBuffer on EOF
*
* @param size the number of bytes to read
* @return a ByteBuffer containing the bytes read
*/
public ByteBuffer read(int size) {
if (size < 0) {
return readall();
}
ByteBuffer bytes = ByteBuffer.allocate(size);
readinto(bytes, false);
// flip()ing here is more convenient as there's no real use
// case for appending to buffers returned from read. readinto
// doesn't/shouldn't flip()
bytes.flip();
return bytes;
}
/**
* Read until EOF.
*
* @return a ByteBuffer containing the bytes read
*/
public ByteBuffer readall() {
unsupported("readall");
return null;
}
/**
* Read up to bytes.remaining() bytes into the given ByteBuffer.
*
* Returns number of bytes read (0 for EOF).
*
* @param bytes a ByteBuffer to read bytes into
* @return the amount of data read as an int
*/
public int readinto(ByteBuffer bytes) {
unsupported("readinto");
return -1;
}
/**
* Read up to bytes.remaining() bytes into the given ByteBuffer, but control
* whether to attempt to buffer the rest of the underlying stream.
*
* Returns the number of bytes read (0 for EOF)
*
* @param bytes a ByteBuffer to read bytes into
* @param buffered whether to buffer the remaining bytes of the stream, if we can
* @return the amount of data read as an int
*/
protected int readinto(ByteBuffer bytes, boolean buffered) {
unsupported("readinto");
return -1;
}
/**
* Write the given ByteBuffer to the IO stream.
*
* Returns the number of bytes written, which may be less than
* bytes.remaining().
*
* @param bytes a ByteBuffer value
* @return the number of bytes written as an int
*/
public int write(ByteBuffer bytes) {
unsupported("write");
return -1;
}
/**
* Returns buffered bytes without advancing the position.
*
* The argument indicates a desired minimal number of bytes; we do
* at most one raw read to satisfy it. We never return more than
* the size of the underlying buffer;
*
* @param size the minimal number of bytes as an int
* @return a ByteBuffer containing the bytes read
*/
public ByteBuffer peek(int size) {
unsupported("peek");
return null;
}
/**
* Reads up to bytes.remaining() bytes.
*
* Returns up to bytes.remaining() bytes. If at least one byte is
* buffered, we only return buffered bytes. Otherwise, we do one
* raw read.
*
* @param bytes a ByteBuffer to read bytes into
* @return the amount of data read as an int
*/
public int read1(ByteBuffer bytes) {
unsupported("read1");
return -1;
}
/**
* Return true if this objects buffer contains any data.
*
* @return boolean whether or not any data is currently buffered
*/
public boolean buffered() {
unsupported("buffered");
return false;
}
/**
* Clear the read buffer if one exists.
*
*/
public void clear() {
unsupported("clear");
}
}