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.util.zip.ZipEntry ; 37 import java.util.zip.ZipFile ; 38 39 import com.lutris.logging.LogChannel; 40 import com.lutris.util.FatalExceptionError; 41 42 54 public class LocalZipResource extends Resource { 55 56 58 59 private ZipEntry zipEntry = null; 60 61 63 74 protected LocalZipResource(String name, ClassPathEntry location, 75 LogChannel loadLogChannel) 77 throws FileNotFoundException { 79 super(name, location, loadLogChannel); 81 ZipFile zipFile = location.getZipFile(); 83 if (zipFile == null) { 84 throw new FileNotFoundException ( "There is no zip file associated with resource: " 85 + location); 86 } 87 try { 88 zipEntry = zipFile.getEntry(name); 89 if (zipEntry == null) { 90 throw new FileNotFoundException ("Entry, " + name 91 + ", does not exist in zip " 92 + "file, " + zipFile); 93 } 94 size = zipEntry.getSize(); 95 } catch (IOException e) { 97 throw new FileNotFoundException ("Entry, " + name 98 + ", does not exist in zip file, " 99 + zipFile + ", or is " + "corrupt: " 100 + e.getMessage()); 101 } 102 } 103 104 106 113 public InputStream getInputStream() throws IOException { 114 ZipFile zipFile = location.getZipFile(); 115 if (zipFile == null) { 116 throw new FatalExceptionError(new IOException ("Failed to get zip file for location, should not be able to get here without a zip file")); 117 } 118 return zipFile.getInputStream(zipEntry); 119 } 120 121 128 public long getCurrentLastModifiedTime() throws FileNotFoundException { 129 lastModifiedTime = zipEntry.getTime(); 130 return lastModifiedTime; 131 } 133 } 134 | Popular Tags |