KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > reflect > JarFile


1 /*
2
3    Derby - Class org.apache.derby.impl.services.reflect.JarFile
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.reflect;
23
24 import java.util.zip.ZipFile JavaDoc;
25 import java.util.zip.ZipEntry JavaDoc;
26 import java.util.zip.ZipInputStream JavaDoc;
27
28 import java.io.IOException JavaDoc;
29 import java.io.File JavaDoc;
30 import java.io.InputStream JavaDoc;
31 import java.io.ByteArrayOutputStream JavaDoc;
32 import org.apache.derby.iapi.util.IdUtil;
33 import org.apache.derby.iapi.services.io.InputStreamUtil;
34
35 class JarFile {
36     final String JavaDoc[] name;
37     protected ZipFile JavaDoc zip;
38     boolean isStream;
39
40     JarFile() {
41         name = null;
42     }
43
44     JarFile(String JavaDoc[] name) {
45         this.name = name;
46     }
47
48     JarFile newJarFile(String JavaDoc[] name) {
49         return new JarFile(name);
50     }
51
52     final String JavaDoc getJarName() {
53         return IdUtil.mkQualifiedName(name);
54     }
55
56
57     final boolean isZip() {
58         return zip != null;
59     }
60
61     final ZipFile JavaDoc getZip() {
62         return zip;
63     }
64
65     void initialize(File JavaDoc jarFile) throws IOException JavaDoc {
66         zip = new ZipFile JavaDoc(jarFile);
67     }
68
69     final void setInvalid() {
70         if (zip != null) {
71             try {
72                 zip.close();
73             } catch (IOException JavaDoc ioe) {
74             }
75             zip = null;
76
77         }
78         isStream = false;
79     }
80
81     ZipEntry JavaDoc getEntry(String JavaDoc entryName) {
82         return zip.getEntry(entryName);
83     }
84     ZipInputStream JavaDoc getZipOnStream(InputStream JavaDoc in) throws IOException JavaDoc {
85         return new ZipInputStream JavaDoc(in);
86     }
87     ZipEntry JavaDoc getNextEntry(ZipInputStream JavaDoc in) throws IOException JavaDoc {
88         return in.getNextEntry();
89     }
90
91     byte[] readData(ZipEntry JavaDoc ze, InputStream JavaDoc in, String JavaDoc className) throws IOException JavaDoc {
92
93         int size = (int) ze.getSize();
94
95         if (size != -1) {
96             byte[] data = new byte[size];
97
98             InputStreamUtil.readFully(in, data, 0, size);
99
100             return data;
101         }
102
103         // unknown size
104
byte[] data = new byte[1024];
105         ByteArrayOutputStream JavaDoc os = new ByteArrayOutputStream JavaDoc(1024);
106         int r;
107         while ((r = in.read(data)) != -1) {
108             os.write(data, 0, r);
109         }
110
111         data = os.toByteArray();
112         return data;
113     }
114
115     Object JavaDoc[] getSigners(String JavaDoc className, ZipEntry JavaDoc ze) throws IOException JavaDoc {
116         return null;
117     }
118 }
119
Popular Tags