Skip to content

Commit e9aab1e

Browse files
author
Phillip Webb
committed
Drop JarEntryFilters from constructor and methods
Drop JarEntryFilter arguments from the JarFile constructor and the getNestedJarFile methods. Filtered JarFiles can still be obtained by using the getFilteredJarFile() method. This helps simplify the code a little and will make it easier to add caching. See gh-1119
1 parent 378d38e commit e9aab1e

File tree

1 file changed

+21
-30
lines changed
  • spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar

1 file changed

+21
-30
lines changed

spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@
4343
* Extended variant of {@link java.util.jar.JarFile} that behaves in the same way but
4444
* offers the following additional functionality.
4545
* <ul>
46-
* <li>Jar entries can be {@link JarEntryFilter filtered} during construction and new
47-
* filtered files can be {@link #getFilteredJarFile(JarEntryFilter...) created} from
48-
* existing files.</li>
49-
* <li>A nested {@link JarFile} can be
50-
* {@link #getNestedJarFile(ZipEntry, JarEntryFilter...) obtained} based on any directory
51-
* entry.</li>
52-
* <li>A nested {@link JarFile} can be
53-
* {@link #getNestedJarFile(ZipEntry, JarEntryFilter...) obtained} for embedded JAR files
54-
* (as long as their entry is not compressed).</li>
46+
* <li>New filtered files can be {@link #getFilteredJarFile(JarEntryFilter...) created}
47+
* from existing files.</li>
48+
* <li>A nested {@link JarFile} can be {@link #getNestedJarFile(ZipEntry) obtained} based
49+
* on any directory entry.</li>
50+
* <li>A nested {@link JarFile} can be {@link #getNestedJarFile(ZipEntry) obtained} for
51+
* embedded JAR files (as long as their entry is not compressed).</li>
5552
* <li>Entry data can be accessed as {@link RandomAccessData}.</li>
5653
* </ul>
5754
*
@@ -90,21 +87,19 @@ public class JarFile extends java.util.jar.JarFile implements Iterable<JarEntryD
9087
/**
9188
* Create a new {@link JarFile} backed by the specified file.
9289
* @param file the root jar file
93-
* @param filters an optional set of jar entry filters
9490
* @throws IOException
9591
*/
96-
public JarFile(File file, JarEntryFilter... filters) throws IOException {
97-
this(new RandomAccessDataFile(file), filters);
92+
public JarFile(File file) throws IOException {
93+
this(new RandomAccessDataFile(file));
9894
}
9995

10096
/**
10197
* Create a new {@link JarFile} backed by the specified file.
10298
* @param file the root jar file
103-
* @param filters an optional set of jar entry filters
10499
* @throws IOException
105100
*/
106-
JarFile(RandomAccessDataFile file, JarEntryFilter... filters) throws IOException {
107-
this(file, file.getFile().getAbsolutePath(), file, filters);
101+
JarFile(RandomAccessDataFile file) throws IOException {
102+
this(file, file.getFile().getAbsolutePath(), file);
108103
}
109104

110105
/**
@@ -297,41 +292,37 @@ public synchronized InputStream getInputStream(ZipEntry ze) throws IOException {
297292
/**
298293
* Return a nested {@link JarFile} loaded from the specified entry.
299294
* @param ze the zip entry
300-
* @param filters an optional set of jar entry filters to be applied
301295
* @return a {@link JarFile} for the entry
302296
* @throws IOException
303297
*/
304-
public synchronized JarFile getNestedJarFile(final ZipEntry ze,
305-
JarEntryFilter... filters) throws IOException {
298+
public synchronized JarFile getNestedJarFile(final ZipEntry ze) throws IOException {
306299
return getNestedJarFile(getContainedEntry(ze).getSource());
307300
}
308301

309302
/**
310303
* Return a nested {@link JarFile} loaded from the specified entry.
311304
* @param sourceEntry the zip entry
312-
* @param filters an optional set of jar entry filters to be applied
313305
* @return a {@link JarFile} for the entry
314306
* @throws IOException
315307
*/
316-
public synchronized JarFile getNestedJarFile(final JarEntryData sourceEntry,
317-
JarEntryFilter... filters) throws IOException {
308+
public synchronized JarFile getNestedJarFile(final JarEntryData sourceEntry)
309+
throws IOException {
318310
try {
319311
if (sourceEntry.isDirectory()) {
320-
return getNestedJarFileFromDirectoryEntry(sourceEntry, filters);
312+
return getNestedJarFileFromDirectoryEntry(sourceEntry);
321313
}
322-
return getNestedJarFileFromFileEntry(sourceEntry, filters);
314+
return getNestedJarFileFromFileEntry(sourceEntry);
323315
}
324316
catch (IOException ex) {
325317
throw new IOException("Unable to open nested jar file '"
326318
+ sourceEntry.getName() + "'", ex);
327319
}
328320
}
329321

330-
private JarFile getNestedJarFileFromDirectoryEntry(JarEntryData sourceEntry,
331-
JarEntryFilter... filters) throws IOException {
322+
private JarFile getNestedJarFileFromDirectoryEntry(JarEntryData sourceEntry)
323+
throws IOException {
332324
final AsciiBytes sourceName = sourceEntry.getName();
333-
JarEntryFilter[] filtersToUse = new JarEntryFilter[filters.length + 1];
334-
System.arraycopy(filters, 0, filtersToUse, 1, filters.length);
325+
JarEntryFilter[] filtersToUse = new JarEntryFilter[1];
335326
filtersToUse[0] = new JarEntryFilter() {
336327
@Override
337328
public AsciiBytes apply(AsciiBytes name, JarEntryData entryData) {
@@ -346,14 +337,14 @@ public AsciiBytes apply(AsciiBytes name, JarEntryData entryData) {
346337
filtersToUse);
347338
}
348339

349-
private JarFile getNestedJarFileFromFileEntry(JarEntryData sourceEntry,
350-
JarEntryFilter... filters) throws IOException {
340+
private JarFile getNestedJarFileFromFileEntry(JarEntryData sourceEntry)
341+
throws IOException {
351342
if (sourceEntry.getMethod() != ZipEntry.STORED) {
352343
throw new IllegalStateException("Unable to open nested compressed entry "
353344
+ sourceEntry.getName());
354345
}
355346
return new JarFile(this.rootFile, getName() + "!/" + sourceEntry.getName(),
356-
sourceEntry.getData(), filters);
347+
sourceEntry.getData());
357348
}
358349

359350
/**

0 commit comments

Comments
 (0)