@@ -115,15 +115,23 @@ default long available(final long count) throws IOException {
115115 return remain < count ? remain : count ;
116116 }
117117
118+ /** Gets whether reading from this handle is supported. */
119+ boolean isReadable ();
120+
121+ /** Gets whether writing to this handle is supported. */
122+ boolean isWritable ();
123+
118124 /**
119125 * Ensures that the handle has sufficient bytes available to read.
120126 *
121127 * @param count Number of bytes to read.
122128 * @see #available(long)
123129 * @throws EOFException If there are insufficient bytes available.
124- * @throws IOException If something goes wrong with the check.
130+ * @throws IOException If the handle is write-only, or something goes wrong
131+ * with the check.
125132 */
126133 default void ensureReadable (final long count ) throws IOException {
134+ if (!isReadable ()) throw new IOException ("This handle is write-only." );
127135 if (available (count ) < count ) throw new EOFException ();
128136 }
129137
@@ -134,10 +142,12 @@ default void ensureReadable(final long count) throws IOException {
134142 * @param count Number of bytes to write.
135143 * @return {@code true} if the handle's length was sufficient, or
136144 * {@code false} if the handle's length required an extension.
137- * @throws IOException If something goes wrong with the check, or there is an
138- * error changing the handle's length.
145+ * @throws IOException If the handle is read-only, or something goes wrong
146+ * with the check, or there is an error changing the handle's
147+ * length.
139148 */
140149 default boolean ensureWritable (final long count ) throws IOException {
150+ if (!isWritable ()) throw new IOException ("This handle is read-only." );
141151 final long minLength = offset () + count ;
142152 if (length () < minLength ) {
143153 setLength (minLength );
0 commit comments