### Question:
Stream2StreamAOImpl extends IRODSGenericAO implements Stream2StreamAO { @Override public byte[] streamFileToByte(final IRODSFile irodsFile) throws JargonException { if (irodsFile == null) { throw new IllegalArgumentException("null irodsTargetFile"); } log.info("streamFileToByte() file:{}", irodsFile); if (irodsFile.exists() && irodsFile.isFile()) { log.info("verified as an existing data object"); } else { throw new JargonException("cannot stream, does not exist or is not a file"); } InputStream is = getIRODSFileFactory().instanceIRODSFileInputStream(irodsFile); ByteArrayOutputStream bos = new ByteArrayOutputStream(); final ReadableByteChannel inputChannel = Channels.newChannel(is); final WritableByteChannel outputChannel = Channels.newChannel(bos); try { ChannelTools.fastChannelCopy(inputChannel, outputChannel, bufferSize); } catch (IOException e) { log.error("IO Exception copying buffers", e); throw new JargonException("io exception copying buffers", e); } finally { try { inputChannel.close(); outputChannel.close(); } catch (Exception e) { } } return bos.toByteArray(); } Stream2StreamAOImpl(final IRODSSession irodsSession, final IRODSAccount irodsAccount); @Override void streamBytesToIRODSFile(final byte[] bytesToStream, final IRODSFile irodsTargetFile); @Override TransferStatistics transferStreamToFileUsingIOStreams(final InputStream inputStream, final File targetFile,
			final long length, final int readBuffSize); @Override TransferStatistics streamToStreamCopyUsingStandardIO(final InputStream inputStream,
			final OutputStream outputStream); @Override void streamToStreamCopy(final InputStream inputStream, final OutputStream outputStream); @Override byte[] streamFileToByte(final IRODSFile irodsFile); @Override void streamClasspathResourceToIRODSFile(final String resourcePath, final String irodsFileAbsolutePath); static final Logger log; }### Answer:
@Test public void testStreamIRODSFileToByteArray() throws Exception { String testFileName = "testStreamIRODSFileToByteArray.txt"; String absPath = scratchFileUtils.createAndReturnAbsoluteScratchPath(IRODS_TEST_SUBDIR_PATH); String fileNameOrig = FileGenerator.generateFileOfFixedLengthGivenName(absPath, testFileName, 40); String targetIrodsCollection = testingPropertiesHelper .buildIRODSCollectionAbsolutePathFromTestProperties(testingProperties, IRODS_TEST_SUBDIR_PATH); IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); DataTransferOperations dataTransferOperationsAO = irodsFileSystem.getIRODSAccessObjectFactory() .getDataTransferOperations(irodsAccount); dataTransferOperationsAO.putOperation(fileNameOrig, targetIrodsCollection, "", null, null); IRODSFile irodsFile = irodsFileSystem.getIRODSFileFactory(irodsAccount) .instanceIRODSFile(targetIrodsCollection + "/" + testFileName); Stream2StreamAO stream2StreamAO = irodsFileSystem.getIRODSAccessObjectFactory() .getStream2StreamAO(irodsAccount); byte[] actual = stream2StreamAO.streamFileToByte(irodsFile); Assert.assertEquals("byte length and file length do not match", irodsFile.length(), actual.length); }