Commit 778b9bb8 authored by Skylot's avatar Skylot

fix: resolve lint errors in resource save methods

parent 57dd9e61
......@@ -5,7 +5,6 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
......@@ -66,14 +65,14 @@ public class ResContainer implements Comparable<ResContainer> {
}
return resContainer;
}
public static ResContainer singleBinaryFile(String name, InputStream content) {
ResContainer resContainer = new ResContainer(name, Collections.emptyList());
try {
// TODO: don't store binary files in memory
resContainer.binary = new ByteArrayInputStream(IOUtils.toByteArray(content));
}
catch(IOException e) {
LOG.warn("Contents of the binary resource '{}' not saved, got exception {}", name, e);
} catch (Exception e) {
LOG.warn("Contents of the binary resource '{}' not saved, got exception", name, e);
}
return resContainer;
}
......@@ -94,7 +93,7 @@ public class ResContainer implements Comparable<ResContainer> {
public CodeWriter getContent() {
return content;
}
@Nullable
public InputStream getBinary() {
return binary;
......
......@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
import jadx.api.ResourceFile;
import jadx.core.codegen.CodeWriter;
import jadx.core.utils.files.FileUtils;
import jadx.core.utils.files.ZipSecurity;
import static jadx.core.utils.files.FileUtils.prepareFile;
......@@ -89,16 +90,16 @@ public class ResourcesSaver implements Runnable {
return;
}
InputStream binary = rc.getBinary();
if(binary != null) {
if (binary != null) {
try {
outFile.getParentFile().mkdirs();
FileOutputStream binaryFileStream = new FileOutputStream(outFile);
IOUtils.copy(binary, binaryFileStream);
binaryFileStream.close();
binary.close();
}
catch(IOException e) {
LOG.warn("Resource '{}' not saved, got exception {}", rc.getName(), e);
FileUtils.makeDirsForFile(outFile);
try (FileOutputStream binaryFileStream = new FileOutputStream(outFile)) {
IOUtils.copy(binary, binaryFileStream);
} finally {
binary.close();
}
} catch (Exception e) {
LOG.warn("Resource '{}' not saved, got exception", rc.getName(), e);
}
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment