in axiom-compat/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java [414:463]
public void writeTo(OutputStream out) throws StreamCopyException {
if (temporaryFile != null) {
FileInputStream in;
try {
in = new FileInputStream(temporaryFile);
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.READ, ex);
}
try {
if (out instanceof ReadFromSupport) {
((ReadFromSupport)out).readFrom(in, -1);
} else {
byte[] buf = new byte[4096];
while (true) {
int c;
try {
c = in.read(buf);
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.READ, ex);
}
if (c == -1) {
break;
}
try {
out.write(buf, 0, c);
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.WRITE, ex);
}
}
}
} finally {
try {
in.close();
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.READ, ex);
}
}
} else {
try {
for (int i=0; i<chunkIndex; i++) {
out.write(chunks[i]);
}
if (chunkOffset > 0) {
out.write(chunks[chunkIndex], 0, chunkOffset);
}
} catch (IOException ex) {
throw new StreamCopyException(StreamCopyException.WRITE, ex);
}
}
}