Output
java.lang.IndexOutOfBoundsException: fff
at com.codegym.task.task32.task3203.Solution.main(Solution.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Can somebody explain me why we should use byte[] buffer = new byte[1024] and write throw ByteArrayOutputStream insead of while( inputStream.isAvailable() > 0) writer.write()? I hope I wrote clearly))
Hint for "Reading from a stream":
Check if variable 'is' is null, then if true return a new StringWriter() object. Else use one of the faster options to read from the stream provided on this page. Write the result to the StringWriter and return it.
These were good exercises, challenging but not impossible. Even though I wasn't able to solve them on my own, the journey helped me better understand the concepts.
GO TO FULL VERSION