/** Returns the length of the underlying input stream, if it is {@linkplain MeasurableStream measurable}. * * @return the length of the underlying input stream. * @throws UnsupportedOperationException if the underlying input stream is not {@linkplain MeasurableStream measurable} and * cannot provide a {@link FileChannel}. */ @Override public long length() throws IOException { if (measurableStream != null) return measurableStream.length(); if (fileChannel != null) return fileChannel.size(); throw new UnsupportedOperationException(); }
@Override public long position() throws IOException { if (repositionableStream != null) return repositionableStream.position() + pos; else if (measurableStream != null) return measurableStream.position() + pos; else if (fileChannel != null) return fileChannel.position() + pos; else throw new UnsupportedOperationException("position() can only be called if the underlying byte stream implements the MeasurableStream or RepositionableStream interface or if the getChannel() method of the underlying byte stream exists and returns a FileChannel"); }
/** Returns the length of the underlying output stream, if it is {@linkplain MeasurableStream measurable}. * * <p>Note that this method performs a {@link #flush()} before detecting the length. * * @return the length of the underlying output stream. * @throws UnsupportedOperationException if the underlying output stream is not {@linkplain MeasurableStream measurable} and * cannot provide a {@link FileChannel}. */ @Override public long length() throws IOException { flush(); if (measurableStream != null) return measurableStream.length(); if (fileChannel != null) return fileChannel.size(); throw new UnsupportedOperationException(); } }