1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.services.reflect.JarFile |
4 | |
5 | Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.services.reflect; |
22 | |
23 | import java.util.zip.ZipFile; |
24 | import java.util.zip.ZipEntry; |
25 | import java.util.zip.ZipInputStream; |
26 | |
27 | import java.io.IOException; |
28 | import java.io.File; |
29 | import java.io.InputStream; |
30 | import java.io.ByteArrayOutputStream; |
31 | import org.apache.derby.iapi.util.IdUtil; |
32 | import org.apache.derby.iapi.services.io.InputStreamUtil; |
33 | |
34 | class JarFile { |
35 | final String[] name; |
36 | protected ZipFile zip; |
37 | boolean isStream; |
38 | |
39 | JarFile() { |
40 | name = null; |
41 | } |
42 | |
43 | JarFile(String[] name) { |
44 | this.name = name; |
45 | } |
46 | |
47 | JarFile newJarFile(String[] name) { |
48 | return new JarFile(name); |
49 | } |
50 | |
51 | final String getJarName() { |
52 | return IdUtil.mkQualifiedName(name); |
53 | } |
54 | |
55 | |
56 | final boolean isZip() { |
57 | return zip != null; |
58 | } |
59 | |
60 | final ZipFile getZip() { |
61 | return zip; |
62 | } |
63 | |
64 | void initialize(File jarFile) throws IOException { |
65 | zip = new ZipFile(jarFile); |
66 | } |
67 | |
68 | final void setInvalid() { |
69 | if (zip != null) { |
70 | try { |
71 | zip.close(); |
72 | } catch (IOException ioe) { |
73 | } |
74 | zip = null; |
75 | |
76 | } |
77 | isStream = false; |
78 | } |
79 | |
80 | ZipEntry getEntry(String entryName) { |
81 | return zip.getEntry(entryName); |
82 | } |
83 | ZipInputStream getZipOnStream(InputStream in) throws IOException { |
84 | return new ZipInputStream(in); |
85 | } |
86 | ZipEntry getNextEntry(ZipInputStream in) throws IOException { |
87 | return in.getNextEntry(); |
88 | } |
89 | |
90 | byte[] readData(ZipEntry ze, InputStream in, String className) throws IOException { |
91 | |
92 | int size = (int) ze.getSize(); |
93 | |
94 | if (size != -1) { |
95 | byte[] data = new byte[size]; |
96 | |
97 | InputStreamUtil.readFully(in, data, 0, size); |
98 | |
99 | return data; |
100 | } |
101 | |
102 | // unknown size |
103 | byte[] data = new byte[1024]; |
104 | ByteArrayOutputStream os = new ByteArrayOutputStream(1024); |
105 | int r; |
106 | while ((r = in.read(data)) != -1) { |
107 | os.write(data, 0, r); |
108 | } |
109 | |
110 | data = os.toByteArray(); |
111 | return data; |
112 | } |
113 | |
114 | Object[] getSigners(String className, ZipEntry ze) throws IOException { |
115 | return null; |
116 | } |
117 | } |