@@ -71,7 +71,7 @@ public interface DataHandle<L extends Location> extends WrapperPlugin<L>,
7171 */
7272 void seek (long pos ) throws IOException ;
7373
74- /** Returns the length of the stream . */
74+ /** Returns the length of the data in bytes . */
7575 long length () throws IOException ;
7676
7777 /**
@@ -83,12 +83,31 @@ public interface DataHandle<L extends Location> extends WrapperPlugin<L>,
8383 void setLength (long length ) throws IOException ;
8484
8585 /**
86- * Verifies that the handle has sufficient bytes available to read, returning
87- * the actual number of bytes which will be possible to read, which might
88- * be less than the requested value.
86+ * Gets the number of bytes which can be safely read from, or written to, the
87+ * data handle, bounded by the specified number of bytes.
88+ * <p>
89+ * In the case of reading, attempting to read the returned number of bytes is
90+ * guaranteed not to throw {@link EOFException}. However, be aware that the
91+ * following methods <em>might still process fewer bytes</em> than indicated
92+ * by this method:
93+ * </p>
94+ * <ul>
95+ * <li>{@link #read(ByteBuffer)}</li>
96+ * <li>{@link #read(ByteBuffer, int)}</li>
97+ * <li>{@link #read(byte[])}</li>
98+ * <li>{@link #read(byte[], int, int)}</li>
99+ * <li>{@link #skip(long)}</li>
100+ * <li>{@link #skipBytes(int)}</li>
101+ * </ul>
102+ * <p>
103+ * In the case of writing, attempting to write the returned number of bytes is
104+ * guaranteed not to expand the length of the handle; i.e., the write will
105+ * only overwrite bytes already within the handle's bounds.
106+ * </p>
89107 *
90- * @param count Number of bytes to read.
91- * @return The actual number of bytes available to be read.
108+ * @param count Desired number of bytes to read/write.
109+ * @return The actual number of bytes which could be safely read/written,
110+ * which might be less than the requested value.
92111 * @throws IOException If something goes wrong with the check.
93112 */
94113 default long available (final long count ) throws IOException {
@@ -109,8 +128,8 @@ default void ensureReadable(final long count) throws IOException {
109128 }
110129
111130 /**
112- * Ensures that the handle has the correct length to be written to and extends
113- * it as required.
131+ * Ensures that the handle has the correct length to be written to, and
132+ * extends it as required.
114133 *
115134 * @param count Number of bytes to write.
116135 * @return {@code true} if the handle's length was sufficient, or
@@ -202,15 +221,16 @@ default int read(final ByteBuffer buf, final int len) throws IOException {
202221 }
203222
204223 /**
205- * Writes up to {@code buf.remaining()} bytes of data from the given
224+ * Writes {@code buf.remaining()} bytes of data from the given
206225 * {@link ByteBuffer} to the stream.
207226 */
208227 default void write (final ByteBuffer buf ) throws IOException {
209228 write (buf , buf .remaining ());
210229 }
211230
212231 /**
213- * Writes up to len bytes of data from the given ByteBuffer to the stream.
232+ * Writes {@code len} bytes of data from the given {@link ByteBuffer} to the
233+ * stream.
214234 */
215235 default void write (final ByteBuffer buf , final int len )
216236 throws IOException
@@ -227,7 +247,6 @@ default void write(final ByteBuffer buf, final int len)
227247 }
228248 }
229249
230-
231250 /** Reads a string of arbitrary length, terminated by a null char. */
232251 default String readCString () throws IOException {
233252 final String line = findString ("\0 " );
0 commit comments