1 17 package org.apache.catalina.util; 18 19 import java.io.InputStream ; 20 import java.io.IOException ; 21 import java.io.OutputStream ; 22 import java.io.Reader ; 23 import java.io.Writer ; 24 25 26 31 public class IOTools { 32 protected final static int DEFAULT_BUFFER_SIZE=4*1024; 34 private IOTools() { 36 } 37 38 46 public static void flow( Reader reader, Writer writer, char[] buf ) 47 throws IOException { 48 int numRead; 49 while ( (numRead = reader.read(buf) ) >= 0) { 50 writer.write(buf, 0, numRead); 51 } 52 } 53 54 57 public static void flow( Reader reader, Writer writer ) 58 throws IOException { 59 char[] buf = new char[DEFAULT_BUFFER_SIZE]; 60 flow( reader, writer, buf ); 61 } 62 63 71 public static void flow( InputStream is, OutputStream os, byte[] buf ) 72 throws IOException { 73 int numRead; 74 while ( (numRead = is.read(buf) ) >= 0) { 75 os.write(buf, 0, numRead); 76 } 77 } 78 79 82 public static void flow( InputStream is, OutputStream os ) 83 throws IOException { 84 byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; 85 flow( is, os, buf ); 86 } 87 } 88 | Popular Tags |