169 /** 170 * Constructs a {@code JmodFile} from a given path. 171 */ 172 public JmodFile(Path file) throws IOException { 173 checkMagic(file); 174 this.file = file; 175 this.zipfile = new ZipFile(file.toFile()); 176 } 177 178 public static void writeMagicNumber(OutputStream os) throws IOException { 179 os.write(JMOD_MAGIC_NUMBER); 180 } 181 182 /** 183 * Returns the {@code Entry} for a resource in a JMOD file section 184 * or {@code null} if not found. 185 */ 186 public Entry getEntry(Section section, String name) { 187 String entry = section.jmodDir() + "/" + name; 188 ZipEntry ze = zipfile.getEntry(entry); 189 return (ze != null) ? new Entry(ze) : null; 190 } 191 192 /** 193 * Opens an {@code InputStream} for reading the named entry of the given 194 * section in this jmod file. 195 * 196 * @throws IOException if the named entry is not found, or I/O error 197 * occurs when reading it 198 */ 199 public InputStream getInputStream(Section section, String name) 200 throws IOException 201 { 202 String entry = section.jmodDir() + "/" + name; 203 ZipEntry e = zipfile.getEntry(entry); 204 if (e == null) { 205 throw new IOException(name + " not found: " + file); 206 } 207 return zipfile.getInputStream(e); 208 } 209 210 /** 211 * Opens an {@code InputStream} for reading an entry in the JMOD file. 212 * 213 * @throws IOException if an I/O error occurs 214 */ 215 public InputStream getInputStream(Entry entry) throws IOException { 216 return zipfile.getInputStream(entry.zipEntry()); 217 } 218 219 /** 220 * Returns a stream of non-directory entries in this jmod file. 221 */ 222 public Stream<Entry> stream() { 223 return zipfile.stream() 224 .filter(e -> !e.isDirectory()) | 169 /** 170 * Constructs a {@code JmodFile} from a given path. 171 */ 172 public JmodFile(Path file) throws IOException { 173 checkMagic(file); 174 this.file = file; 175 this.zipfile = new ZipFile(file.toFile()); 176 } 177 178 public static void writeMagicNumber(OutputStream os) throws IOException { 179 os.write(JMOD_MAGIC_NUMBER); 180 } 181 182 /** 183 * Returns the {@code Entry} for a resource in a JMOD file section 184 * or {@code null} if not found. 185 */ 186 public Entry getEntry(Section section, String name) { 187 String entry = section.jmodDir() + "/" + name; 188 ZipEntry ze = zipfile.getEntry(entry); 189 return (ze == null || ze.isDirectory()) ? null : new Entry(ze); 190 } 191 192 /** 193 * Opens an {@code InputStream} for reading the named entry of the given 194 * section in this jmod file. 195 * 196 * @throws IOException if the named entry is not found, or I/O error 197 * occurs when reading it 198 */ 199 public InputStream getInputStream(Section section, String name) 200 throws IOException 201 { 202 String entry = section.jmodDir() + "/" + name; 203 ZipEntry e = zipfile.getEntry(entry); 204 if (e == null || e.isDirectory()) { 205 throw new IOException(name + " not found: " + file); 206 } 207 return zipfile.getInputStream(e); 208 } 209 210 /** 211 * Opens an {@code InputStream} for reading an entry in the JMOD file. 212 * 213 * @throws IOException if an I/O error occurs 214 */ 215 public InputStream getInputStream(Entry entry) throws IOException { 216 return zipfile.getInputStream(entry.zipEntry()); 217 } 218 219 /** 220 * Returns a stream of non-directory entries in this jmod file. 221 */ 222 public Stream<Entry> stream() { 223 return zipfile.stream() 224 .filter(e -> !e.isDirectory()) |