25
25
import org .apache .hadoop .classification .InterfaceStability ;
26
26
27
27
/**
28
+ * The javadocs for this interface follows RFC 2119 rules regarding the use of
29
+ * MUST, MUST NOT, MAY, and SHALL.
30
+ * <p>
28
31
* Implementers of this interface provide a positioned read API that writes to a
29
32
* {@link ByteBuffer} rather than a {@code byte[]}.
30
- *
33
+ * <p>
34
+ * <b>Thread safety</b>
35
+ * <p>
36
+ * These operations doe not change the current offset of a stream as returned
37
+ * by {@link Seekable#getPos()} and MUST BE thread-safe.
38
+ * Implementations MAY block other readers while one read operation
39
+ * is in progress; this MAY include blocking <i>all</i> read() calls.
40
+ * <p>
41
+ * <b>Concurrent file access</b>
42
+ * <p>
43
+ * No guarantees are made as to when or whether changes made to a file
44
+ * are visible to readers of this API reading the data through an already
45
+ * open stream instance.
31
46
* @see PositionedReadable
32
47
* @see ByteBufferReadable
33
48
*/
@@ -54,12 +69,11 @@ public interface ByteBufferPositionedReadable {
54
69
* stream supports this interface, otherwise they might get a
55
70
* {@link UnsupportedOperationException}.
56
71
* <p>
57
- * Implementations should treat 0-length requests as legitimate, and must not
72
+ * Implementations MUST treat 0-length requests as legitimate, and MUST NOT
58
73
* signal an error upon their receipt.
59
- * <p>
60
- * This does not change the current offset of a file, and is thread-safe.
61
- *
62
- * @param position position within file
74
+ * The {@code position} offset MUST BE zero or positive; if negative
75
+ * an EOFException SHALL BE raised.
76
+ * @param position position within stream. This MUST be >=0.
63
77
* @param buf the ByteBuffer to receive the results of the read operation.
64
78
* @return the number of bytes read, possibly zero, or -1 if reached
65
79
* end-of-stream
@@ -78,12 +92,23 @@ public interface ByteBufferPositionedReadable {
78
92
* {@link #read(long, ByteBuffer)}, the difference is that this method is
79
93
* guaranteed to read data until the {@link ByteBuffer} is full, or until
80
94
* the end of the data stream is reached.
81
- *
82
- * @param position position within file
95
+ * <p>
96
+ * The {@code position} offset MUST BE zero or positive; if negative
97
+ * an EOFException SHALL BE raised.
98
+ * <p>
99
+ * Implementations MUST treat 0-length requests as legitimate -and, and so
100
+ * MUST NOT signal an error if the read position was valid.
101
+ * For zero-byte reads, read position greater {@code getPos()} MAY be
102
+ * considered valid; a negative position MUST always fail.
103
+ * <p>
104
+ * If the EOF was reached before the buffer was completely read -the
105
+ * state of the buffer is undefined. It may be unchanged or it may be
106
+ * partially or completely overwritten.
107
+ * @param position position within stream. This must be >=0.
83
108
* @param buf the ByteBuffer to receive the results of the read operation.
84
109
* @throws IOException if there is some error performing the read
85
110
* @throws EOFException the end of the data was reached before
86
- * the read operation completed
111
+ * the read operation completed, or the position value is negative.
87
112
* @see #read(long, ByteBuffer)
88
113
*/
89
114
void readFully (long position , ByteBuffer buf ) throws IOException ;
0 commit comments