in src/main/java/org/apache/tomcat/jakartaee/Migration.java [347:378]
private void migrateArchiveInMemory(InputStream src, OutputStream dest) throws IOException {
// Read the source into memory
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(src, baos);
baos.flush();
SeekableInMemoryByteChannel srcByteChannel = new SeekableInMemoryByteChannel(baos.toByteArray());
// Create the destination in memory
SeekableInMemoryByteChannel destByteChannel = new SeekableInMemoryByteChannel();
try (ZipFile srcZipFile = ZipFile.builder().setSeekableByteChannel(srcByteChannel).get();
ZipArchiveOutputStream destZipStream = new ZipArchiveOutputStream(destByteChannel)) {
Enumeration<ZipArchiveEntry> entries = srcZipFile.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry srcZipEntry = entries.nextElement();
String srcName = srcZipEntry.getName();
if (isSignatureFile(srcName)) {
logger.log(Level.WARNING, sm.getString("migration.skipSignatureFile", srcName));
continue;
}
String destName = profile.convert(srcName);
MigrationZipArchiveEntry destZipEntry = new MigrationZipArchiveEntry(srcZipEntry);
destZipEntry.setName(destName);
destZipStream.putArchiveEntry(destZipEntry);
migrateStream(srcName, srcZipFile.getInputStream(srcZipEntry), destZipStream);
destZipStream.closeArchiveEntry();
}
}
// Write the destination back to the stream
ByteArrayInputStream bais = new ByteArrayInputStream(destByteChannel.array(), 0, (int) destByteChannel.size());
IOUtils.copy(bais, dest);
}