### Question:
RemoteExecutionBinaryResultInputStream extends InputStream { @Override public int read(final byte[] b, final int off, final int len) throws IOException { try { log.info("stream read for fd: {}", fileDescriptor); if (fileDescriptor <= 0) { throw new IllegalArgumentException("invalid file descriptor"); } if (len < 0) { throw new IllegalArgumentException("invalid len"); } FileReadInp fileReadInp = FileReadInp.instanceForReadStream(fileDescriptor, len); Tag message = irodsCommands.irodsFunction(fileReadInp); if (message == null) { log.warn("null response from iRODS on send of command, treat as eof"); return -1; } int buffLength = message.getTag(IRODSConstants.MsgHeader_PI).getTag(IRODSConstants.bsLen).getIntValue(); int read = irodsCommands.read(b, off, buffLength); if (read != message.getTag(IRODSConstants.MsgHeader_PI).getTag(IRODSConstants.intInfo).getIntValue()) { log.error("did not read length equal to response length, expected" + buffLength + " bytes actually read:" + read); throw new IOException("Bytes read mismatch"); } if (read < 0) { return -1; } return read; } catch (JargonException e) { log.error("JargonException in read is converted to IOException for method contract", e); throw new IOException(e); } } RemoteExecutionBinaryResultInputStream(final IRODSMidLevelProtocol irodsCommands, final int fileDescriptor); int getFileDescriptor(); @Override int available(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); @Override int read(final byte[] b, final int off, final int len); @Override int read(final byte[] b); @Override void reset(); @Override long skip(final long n); @Override int read(); static final Logger log; }### Answer:
@Test public void testRead() throws Exception { if (!testingPropertiesHelper.isTestRemoteExecStream(testingProperties)) { return; } int testLen = 1597152; String cmd = "test_execstream.py"; String args = String.valueOf(testLen); String host = ""; IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); IRODSFileSystem irodsFileSystem = IRODSFileSystem.instance(); EnvironmentalInfoAO environmentalInfoAO = irodsFileSystem.getIRODSAccessObjectFactory() .getEnvironmentalInfoAO(irodsAccount); IRODSServerProperties props = environmentalInfoAO.getIRODSServerPropertiesFromIRODSServer(); if (!props.isTheIrodsServerAtLeastAtTheGivenReleaseVersion(RemoteExecuteServiceImpl.STREAMING_API_CUTOFF)) { irodsFileSystem.closeAndEatExceptions(); return; } if (props.isAtLeastIrods410()) { return; } CollectionAO collectionAO = irodsFileSystem.getIRODSAccessObjectFactory().getCollectionAO(irodsAccount); CollectionAOImpl collectionAOImpl = (CollectionAOImpl) collectionAO; IRODSMidLevelProtocol irodsCommands = collectionAOImpl.getIRODSProtocol(); RemoteExecutionService remoteExecuteService = RemoteExecuteServiceImpl.instance(irodsCommands, cmd, args, host); InputStream inputStream = remoteExecuteService.executeAndStream(); int totalRead = 0; while ((inputStream.read()) > -1 && totalRead < 100) { totalRead++; } inputStream.close(); irodsFileSystem.close(); Assert.assertEquals("did not get expected data length", 100, totalRead); }