mev-4.0.01/source/org/tigr/remote/gateway/util/ServletUtil.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: ServletUtil.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.4 $
2 26 Feb 07 jari 8  * $Date: 2006/02/23 21:00:01 $
2 26 Feb 07 jari 9  * $Author: caliente $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.remote.gateway.util;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.io.BufferedInputStream;
2 26 Feb 07 jari 15 import java.io.BufferedOutputStream;
2 26 Feb 07 jari 16 import java.io.IOException;
2 26 Feb 07 jari 17 import java.io.InputStream;
2 26 Feb 07 jari 18 import java.io.OutputStream;
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20 public class ServletUtil {
2 26 Feb 07 jari 21
2 26 Feb 07 jari 22     /**
2 26 Feb 07 jari 23      * Reads all the data from input stream and writes their into output one.
2 26 Feb 07 jari 24      */
2 26 Feb 07 jari 25     public static void readTo( InputStream in, OutputStream out ) throws IOException {
2 26 Feb 07 jari 26         int c = 0;
2 26 Feb 07 jari 27         while (( c = in.read() ) != -1) {
2 26 Feb 07 jari 28             out.write( c );
2 26 Feb 07 jari 29         }
2 26 Feb 07 jari 30         out.flush();
2 26 Feb 07 jari 31     }
2 26 Feb 07 jari 32
2 26 Feb 07 jari 33     /**
2 26 Feb 07 jari 34      * Reads all the data from the input stream.
2 26 Feb 07 jari 35      */
2 26 Feb 07 jari 36     public static void read( InputStream in ) throws IOException {
2 26 Feb 07 jari 37         int c = 0;
2 26 Feb 07 jari 38         while (( c = in.read() ) != -1);
2 26 Feb 07 jari 39     }
2 26 Feb 07 jari 40
2 26 Feb 07 jari 41     /**
2 26 Feb 07 jari 42      * Reads all the data from input stream and writes their into output one,
2 26 Feb 07 jari 43      * using buffers.
2 26 Feb 07 jari 44      */
2 26 Feb 07 jari 45     public static void bufferedReadTo( InputStream in, OutputStream out ) throws IOException {
2 26 Feb 07 jari 46         BufferedInputStream b_in = new BufferedInputStream( in );
2 26 Feb 07 jari 47         BufferedOutputStream b_out = new BufferedOutputStream( out );
2 26 Feb 07 jari 48         readTo( b_in, b_out );
2 26 Feb 07 jari 49     }
2 26 Feb 07 jari 50
2 26 Feb 07 jari 51     /**
2 26 Feb 07 jari 52      * Reads all the data from the input stream, using a buffer.
2 26 Feb 07 jari 53      */
2 26 Feb 07 jari 54     public static void bufferedRead( InputStream in ) throws IOException {
2 26 Feb 07 jari 55         BufferedInputStream b_in = new BufferedInputStream( in );
2 26 Feb 07 jari 56         read( b_in );
2 26 Feb 07 jari 57     }
2 26 Feb 07 jari 58
2 26 Feb 07 jari 59 }
2 26 Feb 07 jari 60