public void write(byte[] b, int off, int len) throws IOException { if (fileOutputStream != null) { fileOutputStream.write(b, off, len); } else if (len > (chunks.length-chunkIndex)*chunkSize - chunkOffset) { // The buffer will overflow. Switch to a temporary file. fileOutputStream = switchToTempFile(); // Write the new data to the temporary file. fileOutputStream.write(b, off, len); } else { // The data will fit into the buffer. while (len > 0) { byte[] chunk = getCurrentChunk(); // Determine number of bytes that can be copied to the current chunk. int c = Math.min(len, chunkSize-chunkOffset); // Copy data to the chunk. System.arraycopy(b, off, chunk, chunkOffset, c); // Update variables. len -= c; off += c; chunkOffset += c; if (chunkOffset == chunkSize) { chunkIndex++; chunkOffset = 0; } } } }
public void write(byte[] b, int off, int len) throws IOException { if (fileOutputStream != null) { fileOutputStream.write(b, off, len); } else if (len > (chunks.length-chunkIndex)*chunkSize - chunkOffset) { // The buffer will overflow. Switch to a temporary file. fileOutputStream = switchToTempFile(); // Write the new data to the temporary file. fileOutputStream.write(b, off, len); } else { // The data will fit into the buffer. while (len > 0) { byte[] chunk = getCurrentChunk(); // Determine number of bytes that can be copied to the current chunk. int c = Math.min(len, chunkSize-chunkOffset); // Copy data to the chunk. System.arraycopy(b, off, chunk, chunkOffset, c); // Update variables. len -= c; off += c; chunkOffset += c; if (chunkOffset == chunkSize) { chunkIndex++; chunkOffset = 0; } } } }
chunkOffset = 0; if (chunkIndex == chunks.length) { FileOutputStream fileOutputStream = switchToTempFile(); IOUtils.copy(in, fileOutputStream); fileOutputStream.close();
chunkOffset = 0; if (chunkIndex == chunks.length) { FileOutputStream fileOutputStream = switchToTempFile(); IOUtils.copy(in, fileOutputStream); fileOutputStream.close();