-
Notifications
You must be signed in to change notification settings - Fork 40.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes gh-22998
- Loading branch information
Showing
8 changed files
with
385 additions
and
76 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AbstractJarFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2012-2020 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.loader.jar; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.security.Permission; | ||
|
||
/** | ||
* Base class for extended variants of {@link java.util.jar.JarFile}. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
abstract class AbstractJarFile extends java.util.jar.JarFile { | ||
|
||
/** | ||
* Create a new {@link AbstractJarFile}. | ||
* @param file the root jar file. | ||
* @throws IOException on IO error | ||
*/ | ||
AbstractJarFile(File file) throws IOException { | ||
super(file); | ||
} | ||
|
||
/** | ||
* Return a URL that can be used to access this JAR file. NOTE: the specified URL | ||
* cannot be serialized and or cloned. | ||
* @return the URL | ||
* @throws MalformedURLException if the URL is malformed | ||
*/ | ||
protected abstract URL getUrl() throws MalformedURLException; | ||
|
||
/** | ||
* Return the {@link JarFileType} of this instance. | ||
* @return the jar file type | ||
*/ | ||
protected abstract JarFileType getType(); | ||
|
||
/** | ||
* Return the security permission for this JAR. | ||
* @return the security permission. | ||
*/ | ||
protected abstract Permission getPermission(); | ||
|
||
/** | ||
* Return an {@link InputStream} for the entire jar contents. | ||
* @return the contents input stream | ||
* @throws IOException on IO error | ||
*/ | ||
protected abstract InputStream getInputStream() throws IOException; | ||
|
||
/** | ||
* The type of a {@link JarFile}. | ||
*/ | ||
enum JarFileType { | ||
|
||
DIRECT, NESTED_DIRECTORY, NESTED_JAR | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
.../spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright 2012-2020 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.loader.jar; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.security.Permission; | ||
import java.util.Enumeration; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.Manifest; | ||
import java.util.zip.ZipEntry; | ||
|
||
/** | ||
* A wrapper used to create a copy of a {@link JarFile} so that it can be safely closed | ||
* without closing the original. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
class JarFileWrapper extends AbstractJarFile { | ||
|
||
private final JarFile parent; | ||
|
||
JarFileWrapper(JarFile parent) throws IOException { | ||
super(parent.getRootJarFile().getFile()); | ||
this.parent = parent; | ||
super.close(); | ||
} | ||
|
||
@Override | ||
protected URL getUrl() throws MalformedURLException { | ||
return this.parent.getUrl(); | ||
} | ||
|
||
@Override | ||
protected JarFileType getType() { | ||
return this.parent.getType(); | ||
} | ||
|
||
@Override | ||
protected Permission getPermission() { | ||
return this.parent.getPermission(); | ||
} | ||
|
||
@Override | ||
public Manifest getManifest() throws IOException { | ||
return this.parent.getManifest(); | ||
} | ||
|
||
@Override | ||
public Enumeration<JarEntry> entries() { | ||
return this.parent.entries(); | ||
} | ||
|
||
@Override | ||
public JarEntry getJarEntry(String name) { | ||
return this.parent.getJarEntry(name); | ||
} | ||
|
||
@Override | ||
public ZipEntry getEntry(String name) { | ||
return this.parent.getEntry(name); | ||
} | ||
|
||
@Override | ||
protected InputStream getInputStream() throws IOException { | ||
return this.parent.getInputStream(); | ||
} | ||
|
||
@Override | ||
public synchronized InputStream getInputStream(ZipEntry ze) throws IOException { | ||
return this.parent.getInputStream(ze); | ||
} | ||
|
||
@Override | ||
public String getComment() { | ||
return this.parent.getComment(); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return this.parent.size(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.parent.toString(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.parent.getName(); | ||
} | ||
|
||
static JarFile unwrap(java.util.jar.JarFile jarFile) { | ||
if (jarFile instanceof JarFile) { | ||
return (JarFile) jarFile; | ||
} | ||
if (jarFile instanceof JarFileWrapper) { | ||
return unwrap(((JarFileWrapper) jarFile).parent); | ||
} | ||
throw new IllegalStateException("Not a JarFile or Wrapper"); | ||
} | ||
|
||
} |
Oops, something went wrong.