00001 package net.threebit.utils.sosc;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 import java.io.*;
00023 import java.util.*;
00024 import java.util.logging.*;
00025
00030 public class StreamTool {
00031
00033 Logger logger = Logger.getLogger("net.threebit.utils.sosc");
00034
00036 public static int DUMP_STREAM_BUFFER_SIZE = 32*1024;
00037
00044 public static long dumpStream (InputStream in, OutputStream out) throws Exception {
00045 return dumpStream(in,out,DUMP_STREAM_BUFFER_SIZE);
00046 }
00047
00058 public static long dumpStream (InputStream in, OutputStream out, int bufferSize) throws Exception {
00059 if (bufferSize <= 0) { throw new RuntimeException("Invalid buffer size: " + bufferSize); }
00060 if (in == null) { return 0; }
00061 if (out == null) { throw new RuntimeException("Outputstream is null"); }
00062 int i = 0;
00063 long bytes = 0;
00064 byte[] buffer = new byte[bufferSize];
00065 while ((i = in.read(buffer,0,buffer.length)) != -1) {
00066 out.write(buffer,0,i);
00067 bytes += i;
00068 }
00069 return bytes;
00070 }
00071
00072 }