1 16 17 package org.apache.jetspeed.util; 18 19 import java.io.*; 20 import java.net.URL ; 21 22 30 31 public class FileCopy { 32 33 public static final int BUFFER_SIZE = 4096; 34 35 42 public static final void copy(String source, String destination) 43 throws IOException 44 { 45 byte[] buffer = new byte[BUFFER_SIZE]; 46 BufferedInputStream input; 47 BufferedOutputStream output; 48 49 input = new BufferedInputStream(new FileInputStream(source)); 50 output = new BufferedOutputStream(new FileOutputStream(destination)); 51 52 copyStream(input, output, buffer); 53 54 input.close(); 55 output.close(); 56 } 57 58 65 public static final void copyFromURL(String source, String destination) 66 throws IOException 67 { 68 byte[] buffer = new byte[BUFFER_SIZE]; 69 URL url = new URL (source); 70 BufferedInputStream input; 71 BufferedOutputStream output; 72 73 74 input = new BufferedInputStream(new DataInputStream(url.openStream())); 75 output = new BufferedOutputStream(new FileOutputStream(destination)); 76 77 copyStream(input, output, buffer); 78 79 input.close(); 80 output.close(); 81 } 82 83 91 public static final void copyStream(InputStream input, 92 OutputStream output, 93 byte[] buffer) 94 throws IOException 95 { 96 int bytesRead; 97 98 while((bytesRead = input.read(buffer)) != -1) 99 output.write(buffer, 0, bytesRead); 100 } 101 102 } 103 | Popular Tags |