/** * @param storageData * {@link IStorageData} to get the data for. * @param descriptors * List of descriptors that point to the data. * * @return Returns the newly initialized instance of the {@link ExtendedByteBufferInputStream}. * @throws IOException * if input stream can not be obtained */ public ExtendedByteBufferInputStream getExtendedByteBufferInputStream(IStorageData storageData, List<IStorageDescriptor> descriptors) throws IOException { ExtendedByteBufferInputStream stream = createExtendedByteBufferInputStream(); stream.setStorageData(storageData); stream.setDescriptors(descriptors); stream.prepare(); return stream; }
@Override public void run() { if (isCompleted()) { // add buffer to the queue getFullBuffers().add(finalByteBuffer); } else { // if is failed, return buffer to empty buffers and decrease the // total read size because we can not read that amount of bytes finalByteBuffer.clear(); getEmptyBuffers().add(finalByteBuffer); setTotalSize(getTotalSize() - getAttemptedWriteReadSize()); } } };
/** * Prepares the stream for read. Must be called before any read operation is executed. * * @throws IOException * if preparation fails due to inability to obtain defined number of byte buffers */ @Override public void prepare() throws IOException { super.prepare(); // set total size long totalSize = 0; for (IStorageDescriptor descriptor : descriptors) { totalSize += descriptor.getSize(); } setTotalSize(totalSize); executorService.execute(new ReadTask()); }
inputStream.setDescriptors(descriptors); inputStream.prepare(); int actuallyRead = inputStream.read(bytes, alreadyRead, Math.min(random.nextInt(512), readSize - alreadyRead)); alreadyRead += actuallyRead; assertThat(inputStream.hasRemaining(), is(false)); inputStream.close();
/** * Init. */ @BeforeMethod public void init() { MockitoAnnotations.initMocks(this); inputStream = new ExtendedByteBufferInputStream(storageData, null, NUMBER_OF_BUFFERS); inputStream.setByteBufferProvider(byteBufferProvider); inputStream.setReadingChannelManager(readingChannelManager); inputStream.setStorageManager(storageManager); inputStream.setExecutorService(executorService); when(storageManager.getChannelPath(eq(storageData), Matchers.<IStorageDescriptor> anyObject())).thenReturn(Paths.get("/")); }
Input input = null; try { inputStream = streamProvider.getExtendedByteBufferInputStream(localStorageData, optimizedDescriptors); input = new Input(inputStream); while (KryoUtil.hasMoreBytes(input)) {
/** * {@inheritDoc} * <p> * Releases all byte buffers that are hold. */ @Override public synchronized void close() throws IOException { if (isClosed()) { return; } super.close(); // close opened channel paths for (Path path : openedChannelPaths) { readingChannelManager.finalizeChannel(path); } }
buffer = getEmptyBuffers().take(); } catch (InterruptedException e) { Thread.interrupted(); getEmptyBuffers().add(finalByteBuffer); setReadFailed(true); break;
try (InputStream result = inputStreamProvider.getExtendedByteBufferInputStream(storageData, descriptors);) { Input input = new Input(result); while (KryoUtil.hasMoreBytes(input)) {