/** * @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()); } } };
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("/")); }
/** * {@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;