/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ @Override public void close() { in = new ClosedInputStream(); }
@Test public void testRead() throws Exception { final ClosedInputStream cis = new ClosedInputStream(); assertEquals("read()", -1, cis.read()); cis.close(); }
/** * Closes the underlying input stream and replaces the reference to it * with a {@link ClosedInputStream} instance. * <p> * This method is automatically called by the read methods when the end * of input has been reached. * <p> * Note that it is safe to call this method any number of times. The original * underlying input stream is closed and discarded only once when this * method is first called. * * @throws IOException if the underlying input stream can not be closed */ @Override public void close() throws IOException { in.close(); in = new ClosedInputStream(); }
/** * Gets the current contents of this byte stream as a Input Stream. The * returned stream is backed by buffers of <code>this</code> stream, * avoiding memory allocation and copy, thus saving space and time.<br> * * @return the current contents of this output stream. * @see java.io.ByteArrayOutputStream#toByteArray() * @see #reset() * @since 2.5 */ public synchronized InputStream toInputStream() { int remaining = count; if (remaining == 0) { return new ClosedInputStream(); } final List<ByteArrayInputStream> list = new ArrayList<>(buffers.size()); for (final byte[] buf : buffers) { final int c = Math.min(buf.length, remaining); list.add(new ByteArrayInputStream(buf, 0, c)); remaining -= c; if (remaining == 0) { break; } } reuseBuffers = false; return new SequenceInputStream(Collections.enumeration(list)); }
@Test public void testEmptyStream() throws IOException { final InputStream stream = new TaggedInputStream(new ClosedInputStream()); assertEquals(0, stream.available()); assertEquals(-1, stream.read()); assertEquals(-1, stream.read(new byte[1])); assertEquals(-1, stream.read(new byte[1], 0, 1)); stream.close(); }
@Test public void testOtherException() throws Exception { final IOException exception = new IOException("test exception"); final InputStream closed = new ClosedInputStream(); final TaggedInputStream stream = new TaggedInputStream(closed); assertFalse(stream.isCauseOf(exception)); assertFalse(stream.isCauseOf( new TaggedIOException(exception, UUID.randomUUID()))); stream.throwIfCauseOf(exception); stream.throwIfCauseOf( new TaggedIOException(exception, UUID.randomUUID())); stream.close(); }
if ( remaining == 0 ) return new ClosedInputStream();
/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ @Override public void close() { in = new ClosedInputStream(); }
/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ @Override public void close() { in = new ClosedInputStream(); }
/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ public void close() { in = new ClosedInputStream(); }
/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ public void close() { in = new ClosedInputStream(); }
/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ @Override public void close() { in = new ClosedInputStream(); }
/** * Replaces the underlying input stream with a {@link ClosedInputStream} * sentinel. The original input stream will remain open, but this proxy * will appear closed. */ @Override public void close() { in = new ClosedInputStream(); }
@Override public void close() throws IOException { in.close(); in = new ClosedInputStream(); file.delete(); }
@Override public void close() throws IOException { in.close(); in = new ClosedInputStream(); file.delete(); }
/** * Closes the underlying input stream and replaces the reference to it * with a {@link ClosedInputStream} instance. * <p> * This method is automatically called by the read methods when the end * of input has been reached. * <p> * Note that it is safe to call this method any number of times. The original * underlying input stream is closed and discarded only once when this * method is first called. * * @throws IOException if the underlying input stream can not be closed */ public void close() throws IOException { in.close(); in = new ClosedInputStream(); }
@Override public void close() throws IOException { in.close(); in = new ClosedInputStream(); file.delete(); }
@Override public void close() throws IOException { in.close(); in = new ClosedInputStream(); file.delete(); }
/** * Closes the underlying input stream and replaces the reference to it * with a {@link ClosedInputStream} instance. * <p> * This method is automatically called by the read methods when the end * of input has been reached. * <p> * Note that it is safe to call this method any number of times. The original * underlying input stream is closed and discarded only once when this * method is first called. * * @throws IOException if the underlying input stream can not be closed */ public void close() throws IOException { in.close(); in = new ClosedInputStream(); }
/** * Closes the underlying input stream and replaces the reference to it * with a {@link ClosedInputStream} instance. * <p> * This method is automatically called by the read methods when the end * of input has been reached. * <p> * Note that it is safe to call this method any number of times. The original * underlying input stream is closed and discarded only once when this * method is first called. * * @throws IOException if the underlying input stream can not be closed */ @Override public void close() throws IOException { in.close(); in = new ClosedInputStream(); }