Search in sources :

Example 6 with NullInputStream

use of org.apache.commons.io.input.NullInputStream in project hudson-2.x by hudson.

the class Run method getLogInputStream.

/**
     * Returns an input stream that reads from the log file.
     * It will use a gzip-compressed log file (log.gz) if that exists.
     *
     * @throws IOException 
     * @return an input stream from the log file, or null if none exists
     * @since 1.349
     */
public InputStream getLogInputStream() throws IOException {
    File logFile = getLogFile();
    if (logFile.exists()) {
        return new FileInputStream(logFile);
    }
    File compressedLogFile = new File(logFile.getParentFile(), logFile.getName() + ".gz");
    if (compressedLogFile.exists()) {
        return new GZIPInputStream(new FileInputStream(compressedLogFile));
    }
    return new NullInputStream(0);
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) XmlFile(hudson.XmlFile) File(java.io.File) FileInputStream(java.io.FileInputStream) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 7 with NullInputStream

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

the class SQL2IndexingAggregateTest method testAsyncIndexQuery.

/**
     * checks that while text extraction runs in the background, the node is
     * available for query on any of its properties
     * 
     * see <a href="https://issues.apache.org/jira/browse/JCR-2980">JCR-2980</a>
     * 
     */
public void testAsyncIndexQuery() throws Exception {
    Node n = testRootNode.addNode("justnode", JcrConstants.NT_UNSTRUCTURED);
    n.setProperty("type", "testnode");
    n.setProperty("jcr:encoding", "UTF-8");
    n.setProperty("jcr:mimeType", "text/plain");
    n.setProperty("jcr:data", session.getValueFactory().createBinary(new NullInputStream(1024 * 40)));
    testRootNode.getSession().save();
    String sql = "SELECT * FROM [nt:unstructured] as f " + " WHERE ISCHILDNODE([" + testRoot + "]) and type = 'testnode' ";
    checkResult(qm.createQuery(sql, JCR_SQL2).execute(), 1);
}
Also used : Node(javax.jcr.Node) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 8 with NullInputStream

use of org.apache.commons.io.input.NullInputStream in project webservices-axiom by apache.

the class TestWriteToWithError method runTest.

@Override
protected void runTest(WritableBlob blob) throws Throwable {
    blob.readFrom(new NullInputStream(size));
    ExceptionOutputStream out = new ExceptionOutputStream(size / 2);
    try {
        blob.writeTo(out);
        fail("Expected StreamCopyException");
    } catch (StreamCopyException ex) {
        assertThat(ex.getOperation()).isEqualTo(StreamCopyException.WRITE);
        assertThat(ex.getCause()).isSameAs(out.getException());
    }
}
Also used : StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) ExceptionOutputStream(org.apache.axiom.testutils.io.ExceptionOutputStream) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 9 with NullInputStream

use of org.apache.commons.io.input.NullInputStream in project webservices-axiom by apache.

the class TestAvailable method runTest.

@Override
protected void runTest(WritableBlob blob) throws Throwable {
    blob.readFrom(new NullInputStream(1000));
    InputStream in = blob.getInputStream();
    try {
        IOUtils.toByteArray(in, 200);
        assertThat(in.available()).isEqualTo(800);
    } finally {
        in.close();
    }
}
Also used : NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 10 with NullInputStream

use of org.apache.commons.io.input.NullInputStream in project webservices-axiom by apache.

the class TestReadEOF method runTest.

@Override
protected void runTest(WritableBlob blob) throws Throwable {
    blob.readFrom(new NullInputStream(100));
    InputStream in = blob.getInputStream();
    try {
        IOUtils.toByteArray(in, 100);
        assertThat(in.read()).isEqualTo(-1);
        assertThat(in.read(new byte[10])).isEqualTo(-1);
    } finally {
        in.close();
    }
}
Also used : NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) NullInputStream(org.apache.commons.io.input.NullInputStream)

Aggregations

NullInputStream (org.apache.commons.io.input.NullInputStream)12 InputStream (java.io.InputStream)4 IOException (java.io.IOException)2 StreamCopyException (org.apache.axiom.ext.io.StreamCopyException)2 ByteSource (com.google.common.io.ByteSource)1 XmlFile (hudson.XmlFile)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Node (javax.jcr.Node)1 ReadFromSupport (org.apache.axiom.ext.io.ReadFromSupport)1 ExceptionInputStream (org.apache.axiom.testutils.io.ExceptionInputStream)1 ExceptionOutputStream (org.apache.axiom.testutils.io.ExceptionOutputStream)1 CountingOutputStream (org.apache.commons.io.output.CountingOutputStream)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1 IndexOutput (org.apache.lucene.store.IndexOutput)1 InputStreamDataInput (org.apache.lucene.store.InputStreamDataInput)1 Blob (org.jclouds.blobstore.domain.Blob)1 Test (org.junit.Test)1