/** * ContainsKey implementation for chunk elements */ private Boolean containsKeyIntern(final ChunkCacheKey chunkCacheKey) throws IOException { try { final long length = directory.fileLength(chunkCacheKey.getFileName()); final int bufferSize = chunkCacheKey.getBufferSize(); final int chunkId = chunkCacheKey.getChunkId(); return Boolean.valueOf((chunkId * bufferSize) < (length + bufferSize)); } catch (FileNotFoundException nfne) { //Ok, we might check for file existence first.. but it's reasonable to be //optimistic. return Boolean.FALSE; } }
/** * ContainsKey implementation for chunk elements */ private Boolean containsKeyIntern(final ChunkCacheKey chunkCacheKey) throws IOException { try { final long length = directory.fileLength(chunkCacheKey.getFileName()); final int bufferSize = chunkCacheKey.getBufferSize(); final int chunkId = chunkCacheKey.getChunkId(); return Boolean.valueOf((chunkId * bufferSize) < (length + bufferSize)); } catch (NoSuchFileException nfne) { //Ok, we might check for file existence first.. but it's reasonable to be //optimistic. return Boolean.FALSE; } }
/** * ContainsKey implementation for chunk elements */ private Boolean containsKeyIntern(final ChunkCacheKey chunkCacheKey) throws IOException { try { final long length = directory.fileLength(chunkCacheKey.getFileName()); final int bufferSize = chunkCacheKey.getBufferSize(); final int chunkId = chunkCacheKey.getChunkId(); return Boolean.valueOf((chunkId * bufferSize) < (length + bufferSize)); } catch (NoSuchFileException nfne) { //Ok, we might check for file existence first.. but it's reasonable to be //optimistic. return Boolean.FALSE; } }
/** * Loads the actual byte array from a segment, in the range of a specific chunkSize. * Not that while the chunkSize is specified in this case, it's likely derived * from the invocations of other loading methods. */ private byte[] loadIntern(final ChunkCacheKey key) throws IOException { final String fileName = key.getFileName(); final long chunkId = key.getChunkId(); //needs to be long to upcast following operations int bufferSize = key.getBufferSize(); final long seekTo = chunkId * bufferSize; final byte[] buffer; final IndexInput input = directory.openInput(fileName); final long length = input.length(); try { if (seekTo != 0) { input.seek(seekTo); } bufferSize = (int) Math.min(length - seekTo, (long)bufferSize); buffer = new byte[bufferSize]; input.readBytes(buffer, 0, bufferSize); } finally { input.close(); } return buffer; }
/** * Loads the actual byte array from a segment, in the range of a specific chunkSize. * Not that while the chunkSize is specified in this case, it's likely derived * from the invocations of other loading methods. */ private byte[] loadIntern(final ChunkCacheKey key) throws IOException { final String fileName = key.getFileName(); final long chunkId = key.getChunkId(); //needs to be long to upcast following operations int bufferSize = key.getBufferSize(); final long seekTo = chunkId * bufferSize; final byte[] buffer; final IndexInput input = directory.openInput(fileName, IOContext.READ); final long length = input.length(); try { if (seekTo != 0) { input.seek(seekTo); } bufferSize = (int) Math.min(length - seekTo, (long)bufferSize); buffer = new byte[bufferSize]; input.readBytes(buffer, 0, bufferSize); } finally { input.close(); } return buffer; }
/** * Loads the actual byte array from a segment, in the range of a specific chunkSize. * Not that while the chunkSize is specified in this case, it's likely derived * from the invocations of other loading methods. */ private byte[] loadIntern(final ChunkCacheKey key) throws IOException { final String fileName = key.getFileName(); final long chunkId = key.getChunkId(); //needs to be long to upcast following operations int bufferSize = key.getBufferSize(); final long seekTo = chunkId * bufferSize; final byte[] buffer; final IndexInput input = directory.openInput(fileName, IOContext.READ); final long length = input.length(); try { if (seekTo != 0) { input.seek(seekTo); } bufferSize = (int) Math.min(length - seekTo, (long)bufferSize); buffer = new byte[bufferSize]; input.readBytes(buffer, 0, bufferSize); } finally { input.close(); } return buffer; }
if (key instanceof ChunkCacheKey) { ChunkCacheKey existingChunkKey = (ChunkCacheKey) key; String filename = existingChunkKey.getFileName(); assertEquals(existingChunkKey.getIndexName(), indexName);