1 23 24 package com.sun.enterprise.deployment.deploy.shared; 25 26 import java.io.*; 27 import java.util.*; 28 import java.util.jar.Manifest ; 29 import java.util.zip.*; 30 import java.net.URI ; 31 32 import com.sun.enterprise.deployment.util.DOLUtils; 33 34 40 public class OutputJarArchive extends AbstractArchive { 41 42 private String archiveUri; 44 45 protected ZipOutputStream jos=null; 47 48 private Manifest manifest=null; 49 50 private Vector entries = new Vector(); 52 53 54 57 public String getArchiveUri() { 58 return archiveUri; 59 } 60 61 65 public long getArchiveSize() throws NullPointerException , SecurityException { 66 return -1; 67 } 68 69 71 public void close() throws IOException { 72 if (jos!=null) { 73 jos.flush(); 74 jos.finish(); 75 jos.close(); 76 jos=null; 77 } 78 } 79 80 83 public void create(String path) throws IOException { 84 archiveUri = path; 85 File file = new File(path); 86 if (file.exists()) { 88 file.delete(); 89 } 90 FileOutputStream fos = new FileOutputStream(file); 91 BufferedOutputStream bos = new BufferedOutputStream(fos); 92 jos = new ZipOutputStream(bos); 93 } 94 95 98 public Enumeration entries() { 99 return entries.elements(); 100 } 101 102 107 public Enumeration entries(Enumeration embeddedArchives) { 108 return entries(); 109 } 110 111 115 public InputStream getEntry(String name) throws IOException { 116 throw new UnsupportedOperationException ("Cannot read from a JAR archive open for writing"); 117 } 118 119 122 public void open(String path) throws IOException { 123 throw new UnsupportedOperationException ("Cannot read jar files"); 124 } 125 126 128 public Manifest getManifest() throws IOException { 129 if (manifest!=null) { 130 manifest = new Manifest (); 131 } 132 return manifest; 133 } 134 135 public boolean exists() { 136 throw new UnsupportedOperationException ("Cannot read from a JAR archive open for writing"); 137 } 138 139 public boolean delete() { 140 throw new UnsupportedOperationException ("Cannot read from a JAR archive open for writing"); 141 } 142 143 public boolean renameTo(String name) { 144 throw new UnsupportedOperationException ("Cannot read from a JAR archive open for writing"); 145 } 146 147 public AbstractArchive getEmbeddedArchive(String name) throws IOException { 148 OutputStream os = putNextEntry(name); 149 ZipOutputStream jos = new ZipOutputStream(os); 150 OutputJarArchive ja = new OutputJarArchive(); 151 ja.archiveUri = name; 152 ja.jos = jos; 153 return ja; 154 } 155 156 160 public void closeEntry(AbstractArchive os) throws IOException { 161 if (os instanceof OutputJarArchive) { 162 ((OutputJarArchive) os).jos.flush(); 163 ((OutputJarArchive) os).jos.finish(); 164 } 165 jos.closeEntry(); 166 } 167 168 169 173 public OutputStream putNextEntry(String name) throws java.io.IOException { 174 if (jos!=null) { 175 ZipEntry ze = new ZipEntry(name); 176 jos.putNextEntry(ze); 177 entries.add(name); 178 } 179 return jos; 180 } 181 182 183 186 public void closeEntry() throws IOException { 187 if (jos!=null) { 188 jos.flush(); 189 jos.closeEntry(); 190 } 191 } 192 193 public java.net.URI getURI() { 194 try { 195 return ArchiveFactory.prepareArchiveURI(getArchiveUri()); 196 } catch(java.net.URISyntaxException e) { 197 return null; 198 } catch (UnsupportedEncodingException uee) { 199 return null; 200 } catch (IOException ioe) { 201 return null; 202 } 203 } 204 205 206 } 207 | Popular Tags |