1 2 24 25 26 27 28 29 package com.lutris.classloader; 30 31 import java.io.FileNotFoundException ; 34 import java.io.IOException ; 35 import java.io.InputStream ; 36 import java.net.URL ; 37 import java.util.zip.ZipEntry ; 38 import java.util.zip.ZipInputStream ; 39 40 import com.lutris.logging.LogChannel; 41 import com.lutris.util.FatalExceptionError; 42 43 55 public class RemoteZipResource extends Resource { 56 57 59 URL zipFileURL = null; 60 61 63 private RemoteZipResource(String name, ClassPathEntry location, 65 LogChannel loadLogChannel) 67 throws FileNotFoundException { 69 super(name, location, loadLogChannel); 71 73 zipFileURL = location.getURL(); 75 if (zipFileURL == null) { 76 String error = "The URL for location, " + location + ", is null"; 77 logChannel.write(logLevel, error); 79 throw new FileNotFoundException (error); 81 } 82 83 ZipInputStream zipStream = null; 86 try { 87 zipStream = getZipInputStream(); 88 if (zipStream == null) { 89 String error = "URL \"" + zipFileURL + "\" does not exist, " + 90 "can not be reached, or is not a zip file; or the " + 91 "resource \"" + name + "\" is not in the zip file"; 92 logChannel.write(logLevel, error); 94 throw new FileNotFoundException (error); 96 } 97 } finally { 98 if (zipStream != null) { 99 try { 100 zipStream.close(); 101 } catch (IOException ioe) { 102 String error = ioe.toString() + ": URL zip file \"" + 104 zipFileURL + "\" is corrupt or the connection died"; 105 logChannel.write(logLevel, error); 107 throw new FatalExceptionError(new IOException (error)); 109 } 110 } 111 } 112 } 113 114 116 122 public InputStream getInputStream() throws IOException { 123 try { 124 return getZipInputStream(); 125 } catch (FileNotFoundException fnfe) { 126 String error = "URL zip file \"" + zipFileURL + 128 "\" has disappeared or can no longer be reached; or the " + 129 "resource \"" + name + "\" is no longer in the zip file"; 130 logChannel.write(logLevel, error); 132 throw new FatalExceptionError(new FileNotFoundException (error)); 134 } 135 } 136 137 private ZipInputStream getZipInputStream() throws FileNotFoundException { 139 ZipInputStream zipStream; 140 try { 141 zipStream = new ZipInputStream (zipFileURL.openStream()); 142 while (zipStream.available() > 0) { 143 ZipEntry entry = zipStream.getNextEntry(); 144 if (entry == null) { 145 logChannel.write(logLevel, "Null zip entry."); 147 throw new IOException (); 149 } 150 if (entry.getName().equals(name)) { 151 size = entry.getSize(); 152 lastModifiedTime = entry.getTime(); 153 return zipStream; 154 } 155 zipStream.closeEntry(); 156 } 157 } catch (IOException e) { 158 String error = "URL, " + zipFileURL + ", does not exist, " + 159 "can not be reached, is not a zip file, or the resource, " + 160 name + ", is not in the zip file"; 161 logChannel.write(logLevel, error); 163 throw new FileNotFoundException (error); 165 } 166 return null; 167 } 168 169 176 public long getCurrentLastModifiedTime() { 177 return -1; } 179 } 180 | Popular Tags |