in src/main/java/com/microsoft/azure/datalake/store/ADLFileOutputStream.java [86:123]
public void write(byte[] b, int off, int len) throws IOException {
if (streamClosed) throw new IOException("attempting to write to a closed stream;");
if (b == null) {
throw new NullPointerException();
}
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
}
if (len == 0) {
return;
}
if (off > b.length || len > (b.length - off)) throw new IllegalArgumentException("array offset and length are > array size");
if (log.isTraceEnabled()) {
log.trace("Stream write of size {} for client {} for file {}", len, client.getClientId(), filename);
}
if (buffer == null) buffer = new byte[blocksize];
// if len > 4MB, then we force-break the write into 4MB chunks
while (len > blocksize) {
flush(SyncFlag.DATA); // flush first, because we want to preserve record
// boundary of last append
addToBuffer(b, off, blocksize);
off += blocksize;
len -= blocksize;
}
// now len == the remaining length
//if adding this to buffer would overflow buffer, then flush buffer first
if (len > buffer.length - cursor) {
flush(SyncFlag.DATA);
}
// now we know b will fit in remaining buffer, so just add it in
addToBuffer(b, off, len);
}