in src/main/java/org/apache/sling/feature/cpconverter/handlers/slinginitialcontent/SlingInitialContentBundleEntryMetaDataCollector.java [114:148]
private void extractFile(JarEntry jarEntry, JarOutputStream bundleOutput) throws IOException {
byte[] data = new byte[BUFFER];
long compressedSize = jarEntry.getCompressedSize();
try (InputStream input = new BufferedInputStream(jarFile.getInputStream(jarEntry))) {
if (jarEntryIsSlingInitialContent(context, jarEntry)) {
File targetFile = new File(contentPackage2FeatureModelConverter.getTempDirectory(), jarEntry.getName().replace('/', File.separatorChar));
String canonicalDestinationPath = targetFile.getCanonicalPath();
if (!checkIfPathStartsWithOrIsEqual(contentPackage2FeatureModelConverter.getTempDirectory().getCanonicalPath(), canonicalDestinationPath, File.separator)) {
throw new IOException("Entry is outside of the target directory " + canonicalDestinationPath);
}
targetFile.getParentFile().mkdirs();
if (!targetFile.exists() && !targetFile.createNewFile()) {
throw new IOException("Could not create placeholder file!");
}
FileOutputStream fos = new FileOutputStream(targetFile);
safelyWriteOutputStream(compressedSize, data, input, fos, true);
SlingInitialContentBundleEntryMetaData bundleEntry = createSlingInitialContentBundleEntry(context, targetFile);
collectedSlingInitialContentBundleEntries.add(bundleEntry);
} else {
//write 'normal' content out to the normal bundle output
bundleOutput.putNextEntry(jarEntry);
safelyWriteOutputStream(compressedSize, data, input, bundleOutput, false);
IOUtils.copy(input, bundleOutput);
bundleOutput.closeEntry();
}
}
}