1 28 29 package org.objectweb.util.cpp.lib; 30 31 import java.io.BufferedReader ; 32 import java.io.IOException ; 33 import java.io.InputStream ; 34 import java.io.InputStreamReader ; 35 import java.io.OutputStream ; 36 import java.io.PrintStream ; 37 import java.io.Reader ; 38 39 import org.objectweb.util.misc.api.ExceptionWrapper; 40 41 47 public class IOHelper 48 { 49 55 61 67 73 77 public static void close(InputStream input) { 78 try { 79 input.close(); 80 } catch(IOException exc) { 81 throw new ExceptionWrapper(exc); 83 } 84 } 85 86 90 public static void close(Reader input) { 91 try { 92 input.close(); 93 } catch(IOException exc) { 94 throw new ExceptionWrapper(exc); 96 } 97 } 98 99 103 public static void close(OutputStream output) { 104 try { 105 output.close(); 106 } catch(IOException exc) { 107 throw new ExceptionWrapper(exc); 109 } 110 } 111 112 117 public static void dump(Reader input, PrintStream output) { 118 BufferedReader in = new BufferedReader (input); 120 121 try { 123 String line = null; 124 while( (line = in.readLine()) != null) 125 output.println(line); 126 } catch(IOException exc) { 127 throw new ExceptionWrapper(exc); 129 } finally { 130 close(in); 132 } 133 } 134 135 140 public static void dump(InputStream input, PrintStream output) { 141 dump(new InputStreamReader (input), output); 142 } 143 } 144 | Popular Tags |