001: /*
002:
003: Derby - Class org.apache.derby.impl.services.reflect.JarFile
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.services.reflect;
023:
024: import java.util.zip.ZipFile;
025: import java.util.zip.ZipEntry;
026: import java.util.zip.ZipInputStream;
027:
028: import java.io.IOException;
029: import java.io.File;
030: import java.io.InputStream;
031: import java.io.ByteArrayOutputStream;
032: import org.apache.derby.iapi.util.IdUtil;
033: import org.apache.derby.iapi.services.io.InputStreamUtil;
034:
035: class JarFile {
036: final String[] name;
037: protected ZipFile zip;
038: boolean isStream;
039:
040: JarFile() {
041: name = null;
042: }
043:
044: JarFile(String[] name) {
045: this .name = name;
046: }
047:
048: JarFile newJarFile(String[] name) {
049: return new JarFile(name);
050: }
051:
052: final String getJarName() {
053: return IdUtil.mkQualifiedName(name);
054: }
055:
056: final boolean isZip() {
057: return zip != null;
058: }
059:
060: final ZipFile getZip() {
061: return zip;
062: }
063:
064: void initialize(File jarFile) throws IOException {
065: zip = new ZipFile(jarFile);
066: }
067:
068: final void setInvalid() {
069: if (zip != null) {
070: try {
071: zip.close();
072: } catch (IOException ioe) {
073: }
074: zip = null;
075:
076: }
077: isStream = false;
078: }
079:
080: ZipEntry getEntry(String entryName) {
081: return zip.getEntry(entryName);
082: }
083:
084: ZipInputStream getZipOnStream(InputStream in) throws IOException {
085: return new ZipInputStream(in);
086: }
087:
088: ZipEntry getNextEntry(ZipInputStream in) throws IOException {
089: return in.getNextEntry();
090: }
091:
092: byte[] readData(ZipEntry ze, InputStream in, String className)
093: throws IOException {
094:
095: int size = (int) ze.getSize();
096:
097: if (size != -1) {
098: byte[] data = new byte[size];
099:
100: InputStreamUtil.readFully(in, data, 0, size);
101:
102: return data;
103: }
104:
105: // unknown size
106: byte[] data = new byte[1024];
107: ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
108: int r;
109: while ((r = in.read(data)) != -1) {
110: os.write(data, 0, r);
111: }
112:
113: data = os.toByteArray();
114: return data;
115: }
116:
117: Object[] getSigners(String className, ZipEntry ze)
118: throws IOException {
119: return null;
120: }
121: }
|