protected void storeCurrentBuffer(final boolean isClose) { if (currentChunkNumber == 0 && ! isClose) { //we don't store the first chunk until the close operation: this way //we guarantee each chunk is written only once an minimize locking needs. return; } // size changed, apply change to file header resizeFileIfNeeded(); byte[] bufferToFlush = buffer; boolean writingOnLastChunk = isWritingOnLastChunk(); if (writingOnLastChunk) { int newBufferSize = (int) (file.getSize() % bufferSize); if (newBufferSize != 0) { bufferToFlush = new byte[newBufferSize]; System.arraycopy(buffer, 0, bufferToFlush, 0, newBufferSize); } } // add chunk to cache if ( ! writingOnLastChunk || this.positionInBuffer != 0) { // store the current chunk storeBufferAsChunk(bufferToFlush, currentChunkNumber); } }
protected void storeCurrentBuffer(final boolean isClose) { if (currentChunkNumber == 0 && ! isClose) { //we don't store the first chunk until the close operation: this way //we guarantee each chunk is written only once an minimize locking needs. return; } // size changed, apply change to file header resizeFileIfNeeded(); byte[] bufferToFlush = buffer; boolean writingOnLastChunk = isWritingOnLastChunk(); if (writingOnLastChunk) { int newBufferSize = (int) (file.getSize() % bufferSize); if (newBufferSize != 0) { bufferToFlush = new byte[newBufferSize]; System.arraycopy(buffer, 0, bufferToFlush, 0, newBufferSize); } } // add chunk to cache if ( ! writingOnLastChunk || this.positionInBuffer != 0) { // store the current chunk storeBufferAsChunk(bufferToFlush, currentChunkNumber); } }
protected void storeCurrentBuffer(final boolean isClose) { if (currentChunkNumber == 0 && ! isClose) { //we don't store the first chunk until the close operation: this way //we guarantee each chunk is written only once an minimize locking needs. return; } // size changed, apply change to file header resizeFileIfNeeded(); byte[] bufferToFlush = buffer; boolean writingOnLastChunk = isWritingOnLastChunk(); if (writingOnLastChunk) { int newBufferSize = (int) (file.getSize() % bufferSize); if (newBufferSize != 0) { bufferToFlush = new byte[newBufferSize]; System.arraycopy(buffer, 0, bufferToFlush, 0, newBufferSize); } } // add chunk to cache if ( ! writingOnLastChunk || this.positionInBuffer != 0) { // store the current chunk storeBufferAsChunk(bufferToFlush, currentChunkNumber); } }