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 public class Transport
52 {
53 public static boolean fetchJar( URLConnection source, String dest )
54 {
55 BufferedInputStream bis = null;
56 BufferedOutputStream bos = null;
57
58 try
59 {
60 bis = new BufferedInputStream( source.getInputStream());
61 bos = new BufferedOutputStream( new FileOutputStream( dest ) );
62
63 return fetch( bis, bos );
64 }
65 catch( Exception e )
66 {
67 System.out.println("Transport.fetchJar() : " + e );
68 }
69 finally
70 {
71 try{
72 if (bos != null)
73 bos.close();
74 }catch(Exception e){}
75 }
76
77 return false;
78 }
79
80 private static boolean fetch( InputStream is, OutputStream os )
81 throws Exception
82 {
83 byte[] buf = new byte[ 1024];
84 int count = 0;
85
86 do
87 {
88 os.write( buf, 0, count);
89 count = is.read(buf, 0, buf.length);
90 } while (count != -1);
91
92 return true;
93 }
94 }