1 21 22 package org.apache.derby.impl.services.reflect; 23 24 import java.util.zip.ZipFile ; 25 import java.util.zip.ZipEntry ; 26 import java.util.zip.ZipInputStream ; 27 28 import java.io.IOException ; 29 import java.io.File ; 30 import java.io.InputStream ; 31 import java.io.ByteArrayOutputStream ; 32 import org.apache.derby.iapi.util.IdUtil; 33 import org.apache.derby.iapi.services.io.InputStreamUtil; 34 35 class JarFile { 36 final String [] name; 37 protected ZipFile zip; 38 boolean isStream; 39 40 JarFile() { 41 name = null; 42 } 43 44 JarFile(String [] name) { 45 this.name = name; 46 } 47 48 JarFile newJarFile(String [] name) { 49 return new JarFile(name); 50 } 51 52 final String getJarName() { 53 return IdUtil.mkQualifiedName(name); 54 } 55 56 57 final boolean isZip() { 58 return zip != null; 59 } 60 61 final ZipFile getZip() { 62 return zip; 63 } 64 65 void initialize(File jarFile) throws IOException { 66 zip = new ZipFile (jarFile); 67 } 68 69 final void setInvalid() { 70 if (zip != null) { 71 try { 72 zip.close(); 73 } catch (IOException ioe) { 74 } 75 zip = null; 76 77 } 78 isStream = false; 79 } 80 81 ZipEntry getEntry(String entryName) { 82 return zip.getEntry(entryName); 83 } 84 ZipInputStream getZipOnStream(InputStream in) throws IOException { 85 return new ZipInputStream (in); 86 } 87 ZipEntry getNextEntry(ZipInputStream in) throws IOException { 88 return in.getNextEntry(); 89 } 90 91 byte[] readData(ZipEntry ze, InputStream in, String className) throws IOException { 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 byte[] data = new byte[1024]; 105 ByteArrayOutputStream os = new ByteArrayOutputStream (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 [] getSigners(String className, ZipEntry ze) throws IOException { 116 return null; 117 } 118 } 119 | Popular Tags |