in TransformCore/src/main/java/com/facebook/ads/injkit/SingleFileHandler.java [36:80]
public void process() throws IOException, AnnotationProcessingException {
File parent = inputOutputPair.getOutput().getParentFile();
if (!parent.isDirectory() && !parent.mkdirs()) {
throw new IOException(
String.format(Locale.US, "Failed to create directory '%s'", parent.getCanonicalPath()));
}
ZipRecursionHandler.handle(
inputOutputPair.getInput(),
new ZipRecursionHandler.FileConsumer() {
@Override
public void consumeFile(boolean isClass, InputStream input)
throws IOException, AnnotationProcessingException {
if (!isClass) {
// Copy only if the destination is not the source.
if (!inputOutputPair.getInput().equals(inputOutputPair.getOutput())) {
try (FileOutputStream output = new FileOutputStream(inputOutputPair.getOutput())) {
copyData(input, output);
}
}
} else {
// Transform to memory because if destination is the same as source, streaming
// won't work.
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
transform(inputOutputPair.getInput().getCanonicalPath(), input, outputBytes);
Files.write(inputOutputPair.getOutput().toPath(), outputBytes.toByteArray());
}
}
@Override
public void consumeZip(ZipRecursionHandler.ZipHandler handler)
throws IOException, AnnotationProcessingException {
File output;
if (inputOutputPair.getInput().equals(inputOutputPair.getOutput())) {
executeActionWithTempFile(
tempFile -> {
handleConsumeZip(handler, tempFile);
Files.copy(tempFile.toPath(), inputOutputPair.getOutput().toPath());
});
} else {
handleConsumeZip(handler, inputOutputPair.getOutput());
}
}
});
}