Skip to content

Commit b2ca192

Browse files
committed
DataHandle: improve javadoc
1 parent efe3223 commit b2ca192

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/main/java/org/scijava/io/DataHandle.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface DataHandle<L extends Location> extends WrapperPlugin<L>,
7070
*/
7171
void seek(long pos) throws IOException;
7272

73-
/** Returns the length of the stream. */
73+
/** Returns the length of the data in bytes. */
7474
long length() throws IOException;
7575

7676
/**
@@ -82,12 +82,31 @@ public interface DataHandle<L extends Location> extends WrapperPlugin<L>,
8282
void setLength(long length) throws IOException;
8383

8484
/**
85-
* Verifies that the handle has sufficient bytes available to read, returning
86-
* the actual number of bytes which will be possible to read, which might
87-
* be less than the requested value.
85+
* Gets the number of bytes which can be safely read from, or written to, the
86+
* data handle, bounded by the specified number of bytes.
87+
* <p>
88+
* In the case of reading, attempting to read the returned number of bytes is
89+
* guaranteed not to throw {@link EOFException}. However, be aware that the
90+
* following methods <em>might still process fewer bytes</em> than indicated
91+
* by this method:
92+
* </p>
93+
* <ul>
94+
* <li>{@link #read(ByteBuffer)}</li>
95+
* <li>{@link #read(ByteBuffer, int)}</li>
96+
* <li>{@link #read(byte[])}</li>
97+
* <li>{@link #read(byte[], int, int)}</li>
98+
* <li>{@link #skip(long)}</li>
99+
* <li>{@link #skipBytes(int)}</li>
100+
* </ul>
101+
* <p>
102+
* In the case of writing, attempting to write the returned number of bytes is
103+
* guaranteed not to expand the length of the handle; i.e., the write will
104+
* only overwrite bytes already within the handle's bounds.
105+
* </p>
88106
*
89-
* @param count Number of bytes to read.
90-
* @return The actual number of bytes available to be read.
107+
* @param count Desired number of bytes to read/write.
108+
* @return The actual number of bytes which could be safely read/written,
109+
* which might be less than the requested value.
91110
* @throws IOException If something goes wrong with the check.
92111
*/
93112
default long available(final long count) throws IOException {
@@ -108,8 +127,8 @@ default void ensureReadable(final long count) throws IOException {
108127
}
109128

110129
/**
111-
* Ensures that the handle has the correct length to be written to and extends
112-
* it as required.
130+
* Ensures that the handle has the correct length to be written to, and
131+
* extends it as required.
113132
*
114133
* @param count Number of bytes to write.
115134
* @return {@code true} if the handle's length was sufficient, or
@@ -201,15 +220,16 @@ default int read(final ByteBuffer buf, final int len) throws IOException {
201220
}
202221

203222
/**
204-
* Writes up to {@code buf.remaining()} bytes of data from the given
223+
* Writes {@code buf.remaining()} bytes of data from the given
205224
* {@link ByteBuffer} to the stream.
206225
*/
207226
default void write(final ByteBuffer buf) throws IOException {
208227
write(buf, buf.remaining());
209228
}
210229

211230
/**
212-
* Writes up to len bytes of data from the given ByteBuffer to the stream.
231+
* Writes {@code len} bytes of data from the given {@link ByteBuffer} to the
232+
* stream.
213233
*/
214234
default void write(final ByteBuffer buf, final int len)
215235
throws IOException
@@ -226,7 +246,6 @@ default void write(final ByteBuffer buf, final int len)
226246
}
227247
}
228248

229-
230249
/** Reads a string of arbitrary length, terminated by a null char. */
231250
default String readCString() throws IOException {
232251
final String line = findString("\0");

0 commit comments

Comments
 (0)