package com.github.vedenin.eng.other;

import java.io.*;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;

/**
 * Created by vedenin on 15.01.16.
 */
public class IOTest {
    public static void main(String[] s) throws Exception {
        // convert String to InputStream using Apache Utils

        InputStream in = IOUtils.toInputStream("test1", StandardCharsets.UTF_8);
        // convert InputStream to String using Apache Utils
        String myString = IOUtils.toString(in, StandardCharsets.UTF_8);
        System.out.println(myString); // print test1

        // convert String to InputStream
        InputStream stream = new ByteArrayInputStream("test2".getBytes(StandardCharsets.UTF_8));

        // convert InputStream to String using Apache Utils
        StringWriter writer = new StringWriter();
        IOUtils.copy(stream, writer, StandardCharsets.UTF_8);
        String theString = writer.toString();
        System.out.println(theString); // print test2

        InputStream myInputStream = IOUtils.toInputStream("test3", "UTF-8");
        // convert InputStream to String
        InputStreamReader i = new InputStreamReader(myInputStream);
        BufferedReader str = new BufferedReader(i);
        String msg = str.readLine();
        System.out.println(msg);
    }
}

@@ -96,45 +96,256 @@
 ts;%0A
-%0Aimport org.apache.commons.io.IOUtils
+import java.util.stream.Collectors;%0A%0Aimport com.google.common.base.Charsets;%0Aimport com.google.common.io.CharSource;%0Aimport com.google.common.io.CharStreams;%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.apache.commons.io.input.ReaderInputStream
 ;%0A%0A/
@@ -470,35 +470,32 @@
 on %7B%0A       
- //
  convert
  String to I
@@ -486,50 +486,212 @@
 vert
- 
 String
- to InputStream using Apache Utils%0A
+ToOrFromInputStream();%0A    %7D%0A%0A    private static void convertStringToOrFromInputStream() throws IOException %7B%0A        /*             1. Using Apache Utils */%0A        // convert String to InputStream
 %0A   
@@ -709,16 +709,31 @@
 tream in
+putStreamApache
  = IOUti
@@ -823,35 +823,16 @@
 o String
- using Apache Utils
 %0A       
@@ -839,24 +839,28 @@
  String 
-myS
+s
 tring
+Apache
  = IOUti
@@ -873,16 +873,31 @@
 tring(in
+putStreamApache
 , Standa
@@ -946,16 +946,20 @@
 tln(
-myS
+s
 tring
+Apache
 ); /
@@ -973,16 +973,55 @@
  test1%0A%0A
+        /*             2. Using JDK */%0A
         
@@ -1073,22 +1073,30 @@
 tStream 
-s
+inputS
 tream
+JDK
  = new B
@@ -1203,148 +1203,388 @@
 ring
- using Apache Utils%0A        StringWriter writer = new StringWriter();%0A        IOUtils.copy(stream, writer, StandardCharsets.UTF_8
+%0A        BufferedReader str = new BufferedReader(new InputStreamReader(inputStreamJDK));%0A        String stringJDK = str.readLine();%0A        System.out.println(stringJDK); // print test2%0A%0A        /*             3. Using guava */%0A        // convert String to InputStream%0A        InputStream targetStreamGuava = new ReaderInputStream(CharSource.wrap(%22test3%22).openStream()
 );%0A
+%0A
         
 Stri
@@ -1583,43 +1583,147 @@
     
-String theString = writer.toString(
+// convert InputStream to String%0A        String stringGuava = CharStreams.toString(new InputStreamReader(targetStreamGuava, Charsets.UTF_8)
 );%0A 
@@ -1752,17 +1752,19 @@
 tln(
-theS
+s
 tring
+Guava
 ); /
@@ -1767,35 +1767,86 @@
 ); // print test
-2
+3%0A
 %0A%0A
+        /*             4. Using JDK and Scanner*/%0A
         InputStr
@@ -1849,19 +1849,17 @@
 tStream 
-myI
+i
 nputStre
@@ -1864,147 +1864,418 @@
 ream
- = IOUtils.toInputStream(%22test3%22, %22UTF-8%22);%0A        // convert InputStream to String%0A        InputStreamReader i = new InputStream
+ForScanner = new ReaderInputStream(CharSource.wrap(%22test4%22).openStream());%0A        // convert InputStream to String%0A        java.util.Scanner s = new java.util.Scanner(inputStreamForScanner).useDelimiter(%22%5C%5CA%22);%0A        String stringScanner = s.hasNext() ? s.next() : %22%22;%0A        System.out.println(stringScanner);%0A%0A        /*             5. Using Java 8 */%0A        InputStream inputStreamForJava8 = new 
 Reader
-(my
 Inpu
@@ -2285,98 +2285,223 @@
 ream
-);%0A        BufferedReader str = new BufferedReader(i);%0A        String msg = str.readL
+(CharSource.wrap(%22test5%22).openStream());%0A        // convert InputStream to String%0A        String stringJava8 = new BufferedReader(new InputStreamReader(inputStreamForJava8)).l
 ine
+s
 ()
+.collect(Collectors.joining(%22%5Cn%22))
 ;%0A  
@@ -2529,11 +2529,19 @@
 tln(
-msg
+stringJava8
 );%0A 

Change IOTest