in components/blob/src/main/java/org/apache/axiom/blob/OverflowableBlobImpl.java [279:327]
long readFrom(InputStream in, long length, boolean commit) throws StreamCopyException {
if (state == State.COMMITTED) {
throw new IllegalStateException();
}
long read = 0;
long toRead = length == -1 ? Long.MAX_VALUE : length;
while (toRead > 0) {
if (overflowOutputStream != null) {
read += IOUtils.copy(in, overflowOutputStream, toRead);
break;
} else if (chunkIndex == chunks.length) {
try {
switchToOverflowBlob();
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.WRITE, ex);
}
} else {
int c;
try {
int len = chunkSize - chunkOffset;
if (len > toRead) {
len = (int) toRead;
}
c = in.read(getCurrentChunk(), chunkOffset, len);
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.READ, ex);
}
if (c == -1) {
break;
}
read += c;
toRead -= c;
chunkOffset += c;
if (chunkOffset == chunkSize) {
chunkIndex++;
chunkOffset = 0;
}
}
}
if (commit && overflowOutputStream != null) {
try {
overflowOutputStream.close();
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.WRITE, ex);
}
}
state = commit ? State.COMMITTED : State.UNCOMMITTED;
return read;
}