Example usage for org.apache.commons.io.input ClosedInputStream ClosedInputStream

List of usage examples for org.apache.commons.io.input ClosedInputStream ClosedInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.input ClosedInputStream ClosedInputStream.

Prototype

ClosedInputStream

Source Link

Usage

From source file:com.lightboxtechnologies.io.IOUtilsTest.java

@Test
public void testReadClosed() throws IOException {
    final InputStream in = new ClosedInputStream();
    final byte[] buf = new byte[1];
    final int count = IOUtils.read(in, buf);

    assertEquals(-1, count);//  w ww .j  a  v  a 2 s  .com
    assertArrayEquals(new byte[1], buf);
}

From source file:com.nmote.io.ByteArrayOutputStream.java

/**
 * 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>
 * /*  w  ww .j a v a 2s  .  c o  m*/
 * @return the current contents of this output stream.
 * @see java.io.ByteArrayOutputStream#toByteArray()
 * @see #reset()
 * @since Commons IO 2.0
 */
public InputStream toBufferedInputStream() {
    int remaining = count;
    if (remaining == 0) {
        return new ClosedInputStream();
    }
    List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
    for (byte[] buf : buffers) {
        int c = Math.min(buf.length, remaining);
        list.add(new ByteArrayInputStream(buf, 0, c));
        remaining -= c;
        if (remaining == 0) {
            break;
        }
    }
    return new SequenceInputStream(Collections.enumeration(list));
}

From source file:com.norconex.commons.lang.io.ByteArrayOutputStream.java

/**
 * 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>
 * /*from   ww w.  j  a  v a2s  .com*/
 * @return the current contents of this output stream.
 * @see java.io.ByteArrayOutputStream#toByteArray()
 * @see #reset()
 */
private InputStream toBufferedInputStream() {
    int remaining = totalCount;
    if (remaining == 0) {
        return new ClosedInputStream();
    }
    List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
    for (byte[] buf : buffers) {
        int c = Math.min(buf.length, remaining);
        list.add(new ByteArrayInputStream(buf, 0, c));
        remaining -= c;
        if (remaining == 0) {
            break;
        }
    }
    return new SequenceInputStream(Collections.enumeration(list));
}

From source file:net.yacy.document.parser.xml.GenericXMLContentHandler.java

/**
 * @return an empty source to prevent the SAX parser opening an unwanted
 *         connection to resolve an external entity
 *//* w w  w  .ja v  a  2  s . co  m*/
@Override
public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException {
    return new InputSource(new ClosedInputStream());
}

From source file:org.apache.jackrabbit.core.config.RepositoryConfigTest.java

/**
 * Tests that an input stream can be used for the configuration.
 *///from  w  w  w  .ja  v  a2 s  .  c o m
public void testRepositoryConfigCreateWithInputStream() throws IOException {
    InputStream input = new FileInputStream(XML);
    try {
        RepositoryConfig.create(input, DIR.getPath());
    } catch (ConfigurationException e) {
        fail("Valid configuration input stream");
    } finally {
        input.close();
    }

    try {
        RepositoryConfig.create(new InputStream() {
            public int read() throws IOException {
                throw new IOException("invalid input stream");
            }
        }, DIR.getPath());
        fail("Invalid configuration input stream");
    } catch (ConfigurationException e) {
    }

    try {
        RepositoryConfig.create(new ClosedInputStream(), DIR.getPath());
        fail("Invalid configuration input stream");
    } catch (ConfigurationException e) {
    }
}

From source file:org.apache.jackrabbit.core.data.db.TempFileInputStream.java

@Override
public void close() throws IOException {
    in.close();
    in = new ClosedInputStream();
    file.delete();
}

From source file:org.codehaus.plexus.archiver.zip.ByteArrayOutputStream.java

/**
 * 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()/*w  w w. j  a  va  2 s . c om*/
 * @since 2.5
 */
public synchronized InputStream toInputStream() {
    int remaining = count;
    if (remaining == 0) {
        return new ClosedInputStream();
    }
    final List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(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));
}

From source file:org.exist.util.io.FastByteArrayOutputStream.java

/**
 * 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()/* w  ww  .j  a  v  a 2 s .  c  o m*/
 * @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));
}

From source file:org.exist.util.io.FastByteArrayOutputStream.java

/**
 * Similar to {@link #toInputStream()}/*  w  w  w. java  2 s. c  om*/
 * but utilises {@link FastByteArrayInputStream}
 * as opposed to {@link java.io.ByteArrayInputStream}.
 */
public /*synchronized*/ InputStream toFastByteInputStream() {
    int remaining = count;
    if (remaining == 0) {
        return new ClosedInputStream();
    }
    final List<FastByteArrayInputStream> list = new ArrayList<>(buffers.size());
    for (final byte[] buf : buffers) {
        final int c = Math.min(buf.length, remaining);
        list.add(new FastByteArrayInputStream(buf, 0, c));
        remaining -= c;
        if (remaining == 0) {
            break;
        }
    }
    reuseBuffers = false;
    return new SequenceInputStream(Collections.enumeration(list));
}

From source file:org.openflamingo.core.cmd.ByteArrayOutputStream.java

/**
 * 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()//  ww  w.  j  av  a  2s  .  c om
 * @since Commons IO 2.0
 */
private InputStream toBufferedInputStream() {
    int remaining = count;
    if (remaining == 0) {
        return new ClosedInputStream();
    }
    List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
    for (byte[] buf : buffers) {
        int c = Math.min(buf.length, remaining);
        list.add(new ByteArrayInputStream(buf, 0, c));
        remaining -= c;
        if (remaining == 0) {
            break;
        }
    }
    return new SequenceInputStream(Collections.enumeration(list));
}