Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: JM Brun
Added: Aug 21, 2018 4:23 PM
Modified: Aug 22, 2018 3:54 PM
Views: 5
InputSream to String
  1.  
  2. // https://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
  3. IOUtils.toString(inputStream, encoding);
  4. String expectedContent = IOUtils.toString(this.getClass().getResourceAsStream("no_action_expected.json"), UTF_8);
  5.  
  6. // copy
  7. StringWriter writer = new StringWriter();
  8. IOUtils.copy(inputStream, writer, encoding);
  9. String theString = writer.toString();
  10.  
  11. // copy
  12. try {
  13.         StringWriter writer = new StringWriter();
  14.         IOUtils.copy(content, writer, StandardCharsets.UTF_8);
  15.         String theString = writer.toString();
  16.         } catch (IOException e) {
  17.         e.printStackTrace();
  18.         }
  19.