| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.commons.jjar; |
| 19 | |
|
| 20 | |
import java.lang.Package; |
| 21 | |
|
| 22 | |
import java.util.ArrayList; |
| 23 | |
import java.util.Iterator; |
| 24 | |
import java.util.Collection; |
| 25 | |
import java.util.Map; |
| 26 | |
import java.util.List; |
| 27 | |
import java.util.StringTokenizer; |
| 28 | |
import java.util.jar.JarFile; |
| 29 | |
import java.util.jar.Manifest; |
| 30 | |
import java.util.jar.Attributes; |
| 31 | |
import java.util.jar.JarInputStream; |
| 32 | |
|
| 33 | |
import java.io.File; |
| 34 | |
import java.io.FileOutputStream; |
| 35 | |
import java.io.BufferedInputStream; |
| 36 | |
import java.io.BufferedOutputStream; |
| 37 | |
import java.io.InputStream; |
| 38 | |
import java.io.OutputStream; |
| 39 | |
|
| 40 | |
import java.net.JarURLConnection; |
| 41 | |
import java.net.URLConnection; |
| 42 | |
import java.net.URL; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 0 | public class Transport |
| 52 | |
{ |
| 53 | |
public static boolean fetchJar( URLConnection source, String dest ) |
| 54 | |
{ |
| 55 | 0 | BufferedInputStream bis = null; |
| 56 | 0 | BufferedOutputStream bos = null; |
| 57 | |
|
| 58 | |
try |
| 59 | |
{ |
| 60 | 0 | bis = new BufferedInputStream( source.getInputStream()); |
| 61 | 0 | bos = new BufferedOutputStream( new FileOutputStream( dest ) ); |
| 62 | |
|
| 63 | 0 | return fetch( bis, bos ); |
| 64 | |
} |
| 65 | 0 | catch( Exception e ) |
| 66 | |
{ |
| 67 | 0 | System.out.println("Transport.fetchJar() : " + e ); |
| 68 | |
} |
| 69 | |
finally |
| 70 | |
{ |
| 71 | 0 | try{ |
| 72 | 0 | if (bos != null) |
| 73 | 0 | bos.close(); |
| 74 | 0 | }catch(Exception e){} |
| 75 | 0 | } |
| 76 | |
|
| 77 | 0 | return false; |
| 78 | |
} |
| 79 | |
|
| 80 | |
private static boolean fetch( InputStream is, OutputStream os ) |
| 81 | |
throws Exception |
| 82 | |
{ |
| 83 | 0 | byte[] buf = new byte[ 1024]; |
| 84 | 0 | int count = 0; |
| 85 | |
|
| 86 | |
do |
| 87 | |
{ |
| 88 | 0 | os.write( buf, 0, count); |
| 89 | 0 | count = is.read(buf, 0, buf.length); |
| 90 | 0 | } while (count != -1); |
| 91 | |
|
| 92 | 0 | return true; |
| 93 | |
} |
| 94 | |
} |