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); } }
public void close() { if (currentChunkNumber==0) { //store current chunk, possibly resizing it storeCurrentBuffer(true); } else { //no need to resize first chunk, just store it: storeBufferAsChunk(this.firstChunkBuffer, 0); storeCurrentBuffer(true); } buffer = null; firstChunkBuffer = null; // override existing file header with updated accesstime metadataCache.withFlags(Flag.IGNORE_RETURN_VALUES).put(fileKey, file); fileOps.addFileName(this.fileKey.getFileName()); if (trace) { log.tracef("Closed IndexOutput for %s", fileKey); } }
public void close() { if (currentChunkNumber==0) { //store current chunk, possibly resizing it storeCurrentBuffer(true); } else { //no need to resize first chunk, just store it: storeBufferAsChunk(this.firstChunkBuffer, 0); storeCurrentBuffer(true); } buffer = null; firstChunkBuffer = null; // override existing file header with updated accesstime metadataCache.withFlags(Flag.IGNORE_RETURN_VALUES).put(fileKey, file); fileOps.addFileName(this.fileKey.getFileName()); if (trace) { log.tracef("Closed IndexOutput for %s", fileKey); } }
@Override public void close() { if (currentChunkNumber==0) { //store current chunk, possibly resizing it storeCurrentBuffer(true); } else { //no need to resize first chunk, just store it: storeBufferAsChunk(this.firstChunkBuffer, 0); storeCurrentBuffer(true); } buffer = null; firstChunkBuffer = null; // override existing file header with updated accesstime file.touch(); metadataCache.withFlags(Flag.IGNORE_RETURN_VALUES).put(fileKey, file); fileOps.addFileName(this.fileKey.getFileName()); if (trace) { log.tracef("Closed IndexOutput for %s", fileKey); } }