If you have java.io.InputStream object, how should you process that object and produce a String?
Suppose I have an InputStream that contains text data, and I want to convert this to a String. For example, so I can write the contents of the stream to a log file.
What is the easiest way to take the InputStream and convert it to a String?
public String convertStreamToString(InputStream is) {
// ???
}
A) A nice way to do this is using Apache commons IOUtils to copy the InputStream into a StringWriter… something like
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, encoding);
String theString = writer.toString();
or even
// NB: does not close inputStream, you can use IOUtils.closeQuietly for that
String theString = IOUtils.toString(inputStream, encoding);
Alternatively, you could use ByteArrayOutputStream if you don’t want to mix your Streams and Writers
Posted Date:- 2021-09-02 06:07:32
how does test and package phases implies in maven?
what is clean, default and site in maven?
Processes involved in achieving the project?
Maven differentiation with Selenium webdriver?
what is Version and Scope refereces?
what is ArtifactsId refereces?
In which way the dependencies jar files are downloaded from net.
Expain about the maven settings.xml file?
Explain about the parent pom file.
What happens when we declare dependencies under the scope provided ?
How to override the default name of the war file ?
What’s Maven Central Gradually?
What is the use of Settings XML in Maven?
What is the central repository of Maven?
What is the full name of a project?
What is the default value for the packaging element?
What is the use of Maven in Selenium?
What is the difference between Jenkins and Maven?
Difference between maven scope compile and provided for JAR packaging?
How do you get source JARs from Maven repository?
What are the methods for constructing an uber jar?
What is an uber jar? What does an uber-jar mean and what are its features/advantages?
How do you host a Maven repository on github?
How do you convert input stream into string?
What Is Difference Between Compile & Install?
What Is Target, Source & Test Folders In Maven?
What are the Maven advantages over Ant?
Where are Maven dependencies stored?
What is the use of Maven clean?
Where are Maven dependencies downloaded to?
What is meant by a goal in Maven?
How do you produce error messages in Maven?
What is the exact function of “jar:jar�
What are the ways to activate profiles?
What is the command to install the JAR file in the local repository?
What is the Maven settings.xml file?