Search in sources :

Example 1 with ClosedInputStream

use of org.apache.commons.io.input.ClosedInputStream in project jackrabbit by apache.

the class RepositoryConfigTest method testRepositoryConfigCreateWithInputStream.

/**
 * Tests that an input stream can be used for the configuration.
 */
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) {
    }
}
Also used : ClosedInputStream(org.apache.commons.io.input.ClosedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClosedInputStream(org.apache.commons.io.input.ClosedInputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 2 with ClosedInputStream

use of org.apache.commons.io.input.ClosedInputStream in project applause by applause.

the class ByteArrayOutputStream method toBufferedInputStream.

/**
 * 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 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));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ClosedInputStream(org.apache.commons.io.input.ClosedInputStream) ArrayList(java.util.ArrayList)

Example 3 with ClosedInputStream

use of org.apache.commons.io.input.ClosedInputStream in project jackrabbit by apache.

the class TempFileInputStream method close.

@Override
public void close() throws IOException {
    in.close();
    in = new ClosedInputStream();
    file.delete();
}
Also used : ClosedInputStream(org.apache.commons.io.input.ClosedInputStream)

Aggregations

ClosedInputStream (org.apache.commons.io.input.ClosedInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 ArrayList (java.util.ArrayList)1