1 25 26 package org.apache.catalina.util; 27 28 import java.io.*; 29 import javax.servlet.*; 30 31 public final class ResponseUtil { 32 33 42 public static IOException copy(InputStream istream, 43 ServletOutputStream ostream) { 44 45 IOException exception = null; 46 byte buffer[] = new byte[2048]; 47 int len = buffer.length; 48 while (true) { 49 try { 50 len = istream.read(buffer); 51 if (len == -1) 52 break; 53 ostream.write(buffer, 0, len); 54 } catch (IOException e) { 55 exception = e; 56 len = -1; 57 break; 58 } 59 } 60 return exception; 61 62 } 63 64 65 74 public static IOException copy(Reader reader, PrintWriter writer) { 75 76 IOException exception = null; 77 char buffer[] = new char[2048]; 78 int len = buffer.length; 79 while (true) { 80 try { 81 len = reader.read(buffer); 82 if (len == -1) 83 break; 84 writer.write(buffer, 0, len); 85 } catch (IOException e) { 86 exception = e; 87 len = -1; 88 break; 89 } 90 } 91 return exception; 92 93 } 94 95 } 96 | Popular Tags |