CodeGym /Courses /Java Collections /Tasks | Level 2 | Lesson 4

Tasks | Level 2 | Lesson 4

Java Collections
Level 2 , Lesson 4
Available
14
Task
Java Collections, level 2, lesson 4
Locked
Reading from a stream
Implement the getAllDataFromInputStream() method. It must return a StringWriter containing all of the data from the passed stream. Under no circumstances should null be returned. The main() method is not tested.
14
Task
Java Collections, level 2, lesson 4
Locked
Writing a stack trace
Implement the getStackTrace() method, which must return the passed exception's entire stack trace as one string (a single String object). Use an appropriate method from the Throwable class. It will help you write the stack trace to a StringWriter. The main() method is not tested.
14
Task
Java Collections, level 2, lesson 4
Locked
Caesar cipher
Hi, Amigo. You know we're being followed. They're looking through our mail. So we need to encrypt our traffic. Implementing a Caesar cipher won't be hard for you. Let me remind you that this is simply a right-shift along the alphabet by the number of letters indicated by the key parameter.
Comments (7)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Hoist Level 36, San Diego, United States
11 January 2024
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)
Максим Василенко Level 44, Kiev, Ukraine
11 March 2023
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))
Skynet Level 40, USA
8 August 2021
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.
Andrei Level 41
21 June 2021
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.
Andrei Level 41
21 June 2021
P.S. Unlike some of the other exercises' solutions, these ones I could understand and made sense after reading.
Wei Cui Level 39, Newark, United States
19 March 2020
Skynet Level 40, USA
8 August 2021
As of Aug 2021, it's now the second task.