1 package org.apache.slide.projector.util; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.OutputStream ; 7 8 import org.apache.slide.projector.value.StreamableValue; 9 10 public class StreamHelper { 11 public static String streamToString(StreamableValue resource) throws IOException { 12 ByteArrayOutputStream outputStream = new ByteArrayOutputStream (); 13 copy(resource.getInputStream(), outputStream); 14 return outputStream.toString(resource.getCharacterEncoding()); 15 } 16 17 public static void copy(InputStream inputStream, OutputStream outputStream) throws IOException { 18 byte buffer[] = new byte[1024]; 19 int len = buffer.length; 20 while (true) { 21 len = inputStream.read(buffer); 22 if (len == -1) break; 23 outputStream.write(buffer, 0, len); 24 } 25 inputStream.close(); 26 outputStream.close(); 27 } 28 } | Popular Tags |