88 * %%
99 * Redistribution and use in source and binary forms, with or without
1010 * modification, are permitted provided that the following conditions are met:
11- *
11+ *
1212 * 1. Redistributions of source code must retain the above copyright notice,
1313 * this list of conditions and the following disclaimer.
1414 * 2. Redistributions in binary form must reproduce the above copyright notice,
1515 * this list of conditions and the following disclaimer in the documentation
1616 * and/or other materials provided with the distribution.
17- *
17+ *
1818 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1919 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3838import java .io .EOFException ;
3939import java .io .IOException ;
4040import java .io .InputStreamReader ;
41- import java .io .UTFDataFormatException ;
4241import java .nio .ByteBuffer ;
43- import java .nio .ByteOrder ;
4442
43+ import org .scijava .io .bytes .BytesOrder ;
4544import org .scijava .plugin .WrapperPlugin ;
4645
4746/**
4847 * A <em>data handle</em> is a plugin which provides both streaming and random
4948 * access to bytes at a {@link Location} (e.g., files or arrays).
50- *
49+ *
5150 * @author Curtis Rueden
5251 * @see DataHandleInputStream
5352 * @see DataHandleOutputStream
@@ -76,15 +75,15 @@ public interface DataHandle<L extends Location> extends WrapperPlugin<L>,
7675
7776 /**
7877 * Sets the new length of the handle.
79- *
78+ *
8079 * @param length New length.
8180 * @throws IOException If there is an error changing the handle's length.
8281 */
8382 void setLength (long length ) throws IOException ;
8483
8584 /**
86- * Gets the number of bytes which can be read from, or written to, the
87- * data handle, bounded by the specified number of bytes.
85+ * Gets the number of bytes which can be read from, or written to, the data
86+ * handle, bounded by the specified number of bytes.
8887 * <p>
8988 * In the case of reading, attempting to read the returned number of bytes is
9089 * guaranteed not to throw {@link EOFException}. However, be aware that the
@@ -106,8 +105,8 @@ public interface DataHandle<L extends Location> extends WrapperPlugin<L>,
106105 * </p>
107106 *
108107 * @param count Desired number of bytes to read/write.
109- * @return The actual number of bytes which could be read/written,
110- * which might be less than the requested value.
108+ * @return The actual number of bytes which could be read/written, which might
109+ * be less than the requested value.
111110 * @throws IOException If something goes wrong with the check.
112111 */
113112 default long available (final long count ) throws IOException {
@@ -123,7 +122,7 @@ default long available(final long count) throws IOException {
123122
124123 /**
125124 * Ensures that the handle has sufficient bytes available to read.
126- *
125+ *
127126 * @param count Number of bytes to read.
128127 * @see #available(long)
129128 * @throws EOFException If there are insufficient bytes available.
@@ -138,7 +137,7 @@ default void ensureReadable(final long count) throws IOException {
138137 /**
139138 * Ensures that the handle has the correct length to be written to, and
140139 * extends it as required.
141- *
140+ *
142141 * @param count Number of bytes to write.
143142 * @return {@code true} if the handle's length was sufficient, or
144143 * {@code false} if the handle's length required an extension.
@@ -157,42 +156,42 @@ default boolean ensureWritable(final long count) throws IOException {
157156 }
158157
159158 /** Returns the byte order of the stream. */
160- ByteOrder getOrder ();
159+ BytesOrder getOrder ();
161160
162161 /**
163162 * Sets the byte order of the stream.
164163 *
165164 * @param order Order to set.
166165 */
167- void setOrder (ByteOrder order );
166+ void setOrder (BytesOrder order );
168167
169168 /**
170- * Returns true iff the stream's order is {@link ByteOrder #BIG_ENDIAN}.
169+ * Returns true iff the stream's order is {@link BytesOrder #BIG_ENDIAN}.
171170 *
172171 * @see #getOrder()
173172 */
174173 default boolean isBigEndian () {
175- return getOrder () == ByteOrder .BIG_ENDIAN ;
174+ return getOrder () == BytesOrder .BIG_ENDIAN ;
176175 }
177176
178177 /**
179- * Returns true iff the stream's order is {@link ByteOrder #LITTLE_ENDIAN}.
178+ * Returns true iff the stream's order is {@link BytesOrder #LITTLE_ENDIAN}.
180179 *
181180 * @see #getOrder()
182181 */
183182 default boolean isLittleEndian () {
184- return getOrder () == ByteOrder .LITTLE_ENDIAN ;
183+ return getOrder () == BytesOrder .LITTLE_ENDIAN ;
185184 }
186185
187186 /**
188187 * Sets the endianness of the stream.
189188 *
190- * @param little If true, sets the order to {@link ByteOrder #LITTLE_ENDIAN};
191- * otherwise, sets the order to {@link ByteOrder #BIG_ENDIAN}.
192- * @see #setOrder(ByteOrder )
189+ * @param little If true, sets the order to {@link BytesOrder #LITTLE_ENDIAN};
190+ * otherwise, sets the order to {@link BytesOrder #BIG_ENDIAN}.
191+ * @see #setOrder(BytesOrder )
193192 */
194193 default void setLittleEndian (final boolean little ) {
195- setOrder (little ? ByteOrder .LITTLE_ENDIAN : ByteOrder .BIG_ENDIAN );
194+ setOrder (little ? BytesOrder .LITTLE_ENDIAN : BytesOrder .BIG_ENDIAN );
196195 }
197196
198197 /** Gets the native encoding of the stream. */
@@ -201,62 +200,6 @@ default void setLittleEndian(final boolean little) {
201200 /** Sets the native encoding of the stream. */
202201 void setEncoding (String encoding );
203202
204- /**
205- * Reads up to {@code buf.remaining()} bytes of data from the stream into a
206- * {@link ByteBuffer}.
207- */
208- default int read (final ByteBuffer buf ) throws IOException {
209- return read (buf , buf .remaining ());
210- }
211-
212- /**
213- * Reads up to {@code len} bytes of data from the stream into a
214- * {@link ByteBuffer}.
215- *
216- * @return the total number of bytes read into the buffer.
217- */
218- default int read (final ByteBuffer buf , final int len ) throws IOException {
219- final int n ;
220- if (buf .hasArray ()) {
221- // read directly into the array
222- n = read (buf .array (), buf .arrayOffset (), len );
223- }
224- else {
225- // read into a temporary array, then copy
226- final byte [] b = new byte [len ];
227- n = read (b );
228- buf .put (b , 0 , n );
229- }
230- return n ;
231- }
232-
233- /**
234- * Writes {@code buf.remaining()} bytes of data from the given
235- * {@link ByteBuffer} to the stream.
236- */
237- default void write (final ByteBuffer buf ) throws IOException {
238- write (buf , buf .remaining ());
239- }
240-
241- /**
242- * Writes {@code len} bytes of data from the given {@link ByteBuffer} to the
243- * stream.
244- */
245- default void write (final ByteBuffer buf , final int len )
246- throws IOException
247- {
248- if (buf .hasArray ()) {
249- // write directly from the buffer's array
250- write (buf .array (), buf .arrayOffset (), len );
251- }
252- else {
253- // copy into a temporary array, then write
254- final byte [] b = new byte [len ];
255- buf .get (b );
256- write (b );
257- }
258- }
259-
260203 /** Reads a string of arbitrary length, terminated by a null char. */
261204 default String readCString () throws IOException {
262205 final String line = findString ("\0 " );
@@ -273,7 +216,7 @@ default String readString(final int n) throws IOException {
273216
274217 /**
275218 * Reads a string ending with one of the characters in the given string.
276- *
219+ *
277220 * @see #findString(String...)
278221 */
279222 default String readString (final String lastChars ) throws IOException {
@@ -287,7 +230,7 @@ default String readString(final String lastChars) throws IOException {
287230
288231 /**
289232 * Reads a string ending with one of the given terminating substrings.
290- *
233+ *
291234 * @param terminators The strings for which to search.
292235 * @return The string from the initial position through the end of the
293236 * terminating sequence, or through the end of the stream if no
@@ -449,12 +392,13 @@ default int read() throws IOException {
449392 *
450393 * @return the total number of bytes read into the buffer.
451394 */
452- default int read (byte [] b ) throws IOException {
395+ default int read (final byte [] b ) throws IOException {
453396 return read (b , 0 , b .length );
454397 }
455398
456399 /**
457- * Reads up to len bytes of data from the stream into an array of bytes.
400+ * Reads up to {@code len} bytes of data from the stream into an array of
401+ * bytes.
458402 *
459403 * @return the total number of bytes read into the buffer.
460404 */
0 commit comments