What do you think?
package com.codegym.task.task32.task3202;
import java.io.*;
import java.util.Arrays;
/*
Reading from a stream
*/
public class Solution {
public static void main(String[] args) throws IOException {
StringWriter writer = getAllDataFromInputStream(new FileInputStream("testFile.log"));
System.out.println(writer.toString());
}
public static StringWriter getAllDataFromInputStream(InputStream is) throws IOException {
//return a stringwriter containing all data from the passed stream
//i need to transform in input stream into a stringwritre
//inputstream to string
//string to stringwriter
//convert the string into a reader
StringWriter stringWriter = new StringWriter();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)))
{
while (bufferedReader.ready()) {
stringWriter.write(bufferedReader.readLine());
}
return stringWriter;
}catch (IOException exception){ return stringWriter; }
}
}