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());
}
}
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;
}
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());
}
}
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;
}
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);
}
}
}
Aggregations