use of org.springframework.boot.loader.jar.JarFile in project spring-boot by spring-projects.
the class JarFileArchive method getNestedArchive.
protected Archive getNestedArchive(Entry entry) throws IOException {
JarEntry jarEntry = ((JarFileEntry) entry).getJarEntry();
if (jarEntry.getComment().startsWith(UNPACK_MARKER)) {
return getUnpackedNestedArchive(jarEntry);
}
JarFile jarFile = this.jarFile.getNestedJarFile(jarEntry);
return new JarFileArchive(jarFile);
}
use of org.springframework.boot.loader.jar.JarFile in project spring-boot by spring-projects.
the class JarFileArchiveTests method nestedZip64ArchivesAreHandledGracefully.
@Test
void nestedZip64ArchivesAreHandledGracefully() throws Exception {
File file = new File(this.tempDir, "test.jar");
try (JarOutputStream output = new JarOutputStream(new FileOutputStream(file))) {
JarEntry zip64JarEntry = new JarEntry("nested/zip64.jar");
output.putNextEntry(zip64JarEntry);
byte[] zip64JarData = writeZip64Jar();
zip64JarEntry.setSize(zip64JarData.length);
zip64JarEntry.setCompressedSize(zip64JarData.length);
zip64JarEntry.setMethod(ZipEntry.STORED);
CRC32 crc32 = new CRC32();
crc32.update(zip64JarData);
zip64JarEntry.setCrc(crc32.getValue());
output.write(zip64JarData);
output.closeEntry();
}
try (JarFile jarFile = new JarFile(file)) {
ZipEntry nestedEntry = jarFile.getEntry("nested/zip64.jar");
try (JarFile nestedJarFile = jarFile.getNestedJarFile(nestedEntry)) {
Iterator<JarEntry> iterator = nestedJarFile.iterator();
for (int i = 0; i < 65537; i++) {
assertThat(iterator.hasNext()).as(i + "nth file is present").isTrue();
iterator.next();
}
}
}
}
use of org.springframework.boot.loader.jar.JarFile in project spring-boot by spring-projects.
the class LaunchedURLClassLoaderTests method resolveFromNestedWhileThreadIsInterrupted.
@Test
void resolveFromNestedWhileThreadIsInterrupted() throws Exception {
File file = new File(this.tempDir, "test.jar");
TestJarCreator.createTestJar(file);
try (JarFile jarFile = new JarFile(file)) {
URL url = jarFile.getUrl();
try (LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, null)) {
Thread.currentThread().interrupt();
URL resource = loader.getResource("nested.jar!/3.dat");
assertThat(resource.toString()).isEqualTo(url + "nested.jar!/3.dat");
URLConnection connection = resource.openConnection();
try (InputStream input = connection.getInputStream()) {
assertThat(input.read()).isEqualTo(3);
}
((JarURLConnection) connection).getJarFile().close();
} finally {
Thread.interrupted();
}
}
}
use of org.springframework.boot.loader.jar.JarFile in project spring-boot by spring-projects.
the class PropertiesLauncherTests method loadResourceFromJarFile.
// gh-21575
@Test
void loadResourceFromJarFile() throws Exception {
File jarFile = new File(this.tempDir, "app.jar");
TestJarCreator.createTestJar(jarFile);
System.setProperty("loader.home", this.tempDir.getAbsolutePath());
System.setProperty("loader.path", "app.jar");
this.launcher = new PropertiesLauncher();
try {
this.launcher.launch(new String[0]);
} catch (Exception ex) {
// Expected ClassNotFoundException
LaunchedURLClassLoader classLoader = (LaunchedURLClassLoader) Thread.currentThread().getContextClassLoader();
classLoader.close();
}
URL resource = new URL("jar:" + jarFile.toURI() + "!/nested.jar!/3.dat");
byte[] bytes = FileCopyUtils.copyToByteArray(resource.openStream());
assertThat(bytes).isNotEmpty();
}
use of org.springframework.boot.loader.jar.JarFile in project spring-boot by spring-projects.
the class LaunchedURLClassLoaderTests method resolveFromNested.
@Test
void resolveFromNested() throws Exception {
File file = new File(this.tempDir, "test.jar");
TestJarCreator.createTestJar(file);
try (JarFile jarFile = new JarFile(file)) {
URL url = jarFile.getUrl();
try (LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url }, null)) {
URL resource = loader.getResource("nested.jar!/3.dat");
assertThat(resource.toString()).isEqualTo(url + "nested.jar!/3.dat");
try (InputStream input = resource.openConnection().getInputStream()) {
assertThat(input.read()).isEqualTo(3);
}
}
}
}
Aggregations