[
https://issues.apache.org/jira/browse/NET-497?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13564963#comment-13564963
]
Sebb commented on NET-497:
--------------------------
Thanks for the report, however this is not a bug.
The read(byte[]) method does not guarantee that as much data as possible will
be read.
You need to call the method repeatedly until all input has been read.
This behaviour is the same as for java.io.InputStream.
As written, the read(byte[]) method won't block if there are some bytes
available.
In that case it will only read what is reported as available.
However, it does not yet know how many bare LFs will be seen, so cannot allow
for them.
This is why the method returns earlier than one might expect.
This partially non-blocking feature is not noted in the Javadoc, and it's not
clear why the code does it.
Removing the feature would allow your specific test case to work.
However there will still be cases where calling read(byte[]) does not read to
end of stream.
If you want to read to end of stream, you need to call the method repeatedly
until it returns -1.
You may find it easier to call read().
> ToNetASCIIInputStream skips LF at the end of the stream
> -------------------------------------------------------
>
> Key: NET-497
> URL: https://issues.apache.org/jira/browse/NET-497
> Project: Commons Net
> Issue Type: Bug
> Components: Telnet, TFTP
> Affects Versions: 3.1
> Reporter: Mirko Raner
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> I have the following failing test case for ToNetASCIIInputStream:
> {noformat}
> public void testToNetASCIIInputStream() throws Exception
> {
> final Charset ASCII = Charset.forName("ASCII");
> byte[] data = "Hello\nWorld\n".getBytes(ASCII);
> InputStream source = new ByteArrayInputStream(data);
> ToNetASCIIInputStream toNetASCII = new ToNetASCIIInputStream(source);
> byte[] output = new byte[512];
> int length = toNetASCII.read(output);
> byte[] result = new byte[length];
> System.arraycopy(output, 0, result, 0, length);
> assertEquals('\r', result[length-2]);
> assertEquals('\n', result[length-1]);
> }
> {noformat}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira