LoaderZipEntries Class — spring-boot Architecture
Architecture documentation for the LoaderZipEntries class in LoaderZipEntries.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LoaderZipEntries.java lines 42–137
class LoaderZipEntries {
private final @Nullable Long entryTime;
private final int dirMode;
private final int fileMode;
LoaderZipEntries(@Nullable Long entryTime, int dirMode, int fileMode) {
this.entryTime = entryTime;
this.dirMode = dirMode;
this.fileMode = fileMode;
}
WrittenEntries writeTo(ZipArchiveOutputStream out) throws IOException {
WrittenEntries written = new WrittenEntries();
try (ZipInputStream loaderJar = new ZipInputStream(
getResourceAsStream("/META-INF/loader/spring-boot-loader.jar"))) {
java.util.zip.ZipEntry entry = loaderJar.getNextEntry();
while (entry != null) {
if (entry.isDirectory() && !entry.getName().equals("META-INF/")) {
writeDirectory(new ZipArchiveEntry(entry), out);
written.addDirectory(entry);
}
else if (entry.getName().endsWith(".class") || entry.getName().startsWith("META-INF/services/")) {
writeFile(new ZipArchiveEntry(entry), loaderJar, out);
written.addFile(entry);
}
entry = loaderJar.getNextEntry();
}
}
return written;
}
private InputStream getResourceAsStream(String name) {
InputStream stream = getClass().getResourceAsStream(name);
Assert.state(stream != null, "Resource '%s not found'".formatted(name));
return stream;
}
private void writeDirectory(ZipArchiveEntry entry, ZipArchiveOutputStream out) throws IOException {
prepareEntry(entry, this.dirMode);
out.putArchiveEntry(entry);
out.closeArchiveEntry();
}
private void writeFile(ZipArchiveEntry entry, ZipInputStream in, ZipArchiveOutputStream out) throws IOException {
prepareEntry(entry, this.fileMode);
out.putArchiveEntry(entry);
copy(in, out);
out.closeArchiveEntry();
}
private void prepareEntry(ZipArchiveEntry entry, int unixMode) {
if (this.entryTime != null) {
entry.setTime(DefaultTimeZoneOffset.INSTANCE.removeFrom(this.entryTime));
}
entry.setUnixMode(unixMode);
}
private void copy(InputStream in, OutputStream out) throws IOException {
StreamUtils.copy(in, out);
}
/**
* Tracks entries that have been written.
*/
static class WrittenEntries {
private final Set<String> directories = new LinkedHashSet<>();
private final Set<String> files = new LinkedHashSet<>();
private void addDirectory(ZipEntry entry) {
this.directories.add(entry.getName());
}
private void addFile(ZipEntry entry) {
this.files.add(entry.getName());
}
boolean isWrittenDirectory(FileTreeElement element) {
String path = element.getRelativePath().getPathString();
if (element.isDirectory() && !path.endsWith(("/"))) {
path += "/";
}
return this.directories.contains(path);
}
Set<String> getFiles() {
return this.files;
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free