1 4 package com.zerog.ia.customcode.util.fileutils; 5 6 import java.io.*; 7 8 public class OtherUtils 9 { 10 private static final int BUFFER_SIZE = 64 * 1024; 11 private static byte [] BUFFER = null; 12 13 19 public static long bufStreamCopy(InputStream is, OutputStream os, int bufferSizeInBytes ) 20 throws IOException 21 { 22 byte[] b = new byte[bufferSizeInBytes]; 23 24 return bufStreamCopy( is, os, b ); 25 } 26 27 32 public static long bufStreamCopy(InputStream is, OutputStream os) 33 throws IOException 34 { 35 36 if ( BUFFER == null ) 37 { 38 BUFFER = new byte[BUFFER_SIZE]; 39 } 40 41 synchronized ( BUFFER ) 42 { 43 return bufStreamCopy( is, os, BUFFER ); 44 } 45 } 46 47 53 public static long bufStreamCopy(InputStream is, OutputStream os, byte [] b ) 54 throws IOException 55 { 56 long bytes = 0; 57 58 int read = is.read( b, 0, b.length ); 59 while ( read != -1 ) 60 { 61 os.write( b, 0, read ); 62 bytes += read; 63 read = is.read( b, 0, b.length ); 64 } 65 66 os.flush(); 67 68 return bytes; 69 } 70 } 71 | Popular Tags |