Search in sources :

Example 6 with StreamCopyException

use of org.apache.axiom.ext.io.StreamCopyException in project webservices-axiom by apache.

the class TestReadFromWithError method runTest.

@Override
protected void runTest(WritableBlob blob) throws Throwable {
    ExceptionInputStream in = new ExceptionInputStream(new NullInputStream(1000), 500);
    try {
        blob.readFrom(in);
        fail("Expected StreamCopyException");
    } catch (StreamCopyException ex) {
        assertThat(ex.getOperation()).isEqualTo(StreamCopyException.READ);
        assertThat(ex.getCause()).isSameAs(in.getException());
    }
}
Also used : ExceptionInputStream(org.apache.axiom.testutils.io.ExceptionInputStream) StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) NullInputStream(org.apache.commons.io.input.NullInputStream)

Example 7 with StreamCopyException

use of org.apache.axiom.ext.io.StreamCopyException in project webservices-axiom by apache.

the class MemoryBlobOutputStreamImpl method readFrom.

@Override
public long readFrom(InputStream in, long length) throws StreamCopyException {
    if (chunk == null) {
        throw new IllegalStateException();
    }
    long read = 0;
    long toRead = length == -1 ? Long.MAX_VALUE : length;
    while (toRead > 0) {
        updateChunk();
        int c;
        try {
            c = in.read(chunk.buffer, chunk.size, (int) Math.min(toRead, chunk.buffer.length - chunk.size));
        } catch (IOException ex) {
            throw new StreamCopyException(StreamCopyException.READ, ex);
        }
        if (c == -1) {
            break;
        }
        chunk.size += c;
        read += c;
        toRead -= c;
    }
    return read;
}
Also used : StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) IOException(java.io.IOException)

Example 8 with StreamCopyException

use of org.apache.axiom.ext.io.StreamCopyException 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 StreamCopyException

use of org.apache.axiom.ext.io.StreamCopyException in project webservices-axiom by apache.

the class BAAOutputStream method readFrom.

@Override
public long readFrom(InputStream is, long maxRead) throws StreamCopyException {
    if (maxRead == -1) {
        maxRead = Long.MAX_VALUE;
    }
    long bytesReceived = 0;
    // Now directly write to the buffers
    boolean done = false;
    while (!done) {
        // Don't get more than will fit in the current buffer
        int len = (int) Math.min(BUFFER_SIZE - index, maxRead - bytesReceived);
        // Now get the bytes
        int bytesRead;
        try {
            bytesRead = is.read(currBuffer, index, len);
        } catch (IOException ex) {
            throw new StreamCopyException(StreamCopyException.READ, ex);
        }
        if (bytesRead >= 0) {
            bytesReceived += bytesRead;
            index += bytesRead;
            if (index >= BUFFER_SIZE) {
                addBuffer();
            }
            if (bytesReceived >= maxRead) {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return bytesReceived;
}
Also used : StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) IOException(java.io.IOException)

Example 10 with StreamCopyException

use of org.apache.axiom.ext.io.StreamCopyException in project webservices-axiom by apache.

the class MemoryBlob method writeTo.

@Override
public void writeTo(OutputStream os) throws StreamCopyException {
    int size = (int) getLength();
    if (data != null) {
        try {
            int numBuffers = data.size();
            for (int j = 0; j < numBuffers - 1; j++) {
                os.write((byte[]) data.get(j), 0, BUFFER_SIZE);
            }
            if (numBuffers > 0) {
                int writeLimit = size - ((numBuffers - 1) * BUFFER_SIZE);
                os.write((byte[]) data.get(numBuffers - 1), 0, writeLimit);
            }
        } catch (IOException ex) {
            throw new StreamCopyException(StreamCopyException.WRITE, ex);
        }
    }
}
Also used : StreamCopyException(org.apache.axiom.ext.io.StreamCopyException) IOException(java.io.IOException)

Aggregations

StreamCopyException (org.apache.axiom.ext.io.StreamCopyException)12 IOException (java.io.IOException)10 NullInputStream (org.apache.commons.io.input.NullInputStream)2 FileOutputStream (java.io.FileOutputStream)1 MemoryBlob (org.apache.axiom.blob.MemoryBlob)1 ReadFromSupport (org.apache.axiom.ext.io.ReadFromSupport)1 OMException (org.apache.axiom.om.OMException)1 ExceptionInputStream (org.apache.axiom.testutils.io.ExceptionInputStream)1 ExceptionOutputStream (org.apache.axiom.testutils.io.ExceptionOutputStream)1