public long length() { resizeFileIfNeeded(); return file.getSize(); }
public long length() { resizeFileIfNeeded(); return file.getSize(); }
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 seek(final long pos) throws IOException { final int requestedChunkNumber = getChunkNumberFromPosition(pos, bufferSize); if (pos > file.getSize()) { resizeFileIfNeeded(); if (pos > file.getSize()) // check again, might be fixed by the resize throw new IOException(fileKey.getFileName() + ": seeking past end of file"); } if (requestedChunkNumber != currentChunkNumber) { storeCurrentBuffer(false); if (requestedChunkNumber != 0) { buffer = getChunkById(fileKey, requestedChunkNumber, bufferSize); } else { buffer = firstChunkBuffer; } currentChunkNumber = requestedChunkNumber; } positionInBuffer = getPositionInBuffer(pos, bufferSize); filePosition = pos; }
public void seek(final long pos) throws IOException { final int requestedChunkNumber = getChunkNumberFromPosition(pos, bufferSize); if (pos > file.getSize()) { resizeFileIfNeeded(); if (pos > file.getSize()) // check again, might be fixed by the resize throw new IOException(fileKey.getFileName() + ": seeking past end of file"); } if (requestedChunkNumber != currentChunkNumber) { storeCurrentBuffer(false); if (requestedChunkNumber != 0) { buffer = getChunkById(fileKey, requestedChunkNumber, bufferSize); } else { buffer = firstChunkBuffer; } currentChunkNumber = requestedChunkNumber; } positionInBuffer = getPositionInBuffer(pos, bufferSize); filePosition = pos; }
@Override public void seek(final long pos) throws IOException { final int requestedChunkNumber = getChunkNumberFromPosition(pos, bufferSize); if (pos > file.getSize()) { resizeFileIfNeeded(); if (pos > file.getSize()) // check again, might be fixed by the resize throw new IOException(fileKey.getFileName() + ": seeking past end of file"); } if (requestedChunkNumber != currentChunkNumber) { storeCurrentBuffer(false); if (requestedChunkNumber != 0) { buffer = getChunkById(fileKey, requestedChunkNumber, bufferSize); } else { buffer = firstChunkBuffer; } currentChunkNumber = requestedChunkNumber; } positionInBuffer = getPositionInBuffer(pos, bufferSize); filePosition = pos; }