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; ...@@ -5,7 +5,6 @@ import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -66,14 +65,14 @@ public class ResContainer implements Comparable<ResContainer> { ...@@ -66,14 +65,14 @@ public class ResContainer implements Comparable<ResContainer> {
} }
return resContainer; return resContainer;
} }
public static ResContainer singleBinaryFile(String name, InputStream content) { public static ResContainer singleBinaryFile(String name, InputStream content) {
ResContainer resContainer = new ResContainer(name, Collections.emptyList()); ResContainer resContainer = new ResContainer(name, Collections.emptyList());
try { try {
// TODO: don't store binary files in memory
resContainer.binary = new ByteArrayInputStream(IOUtils.toByteArray(content)); resContainer.binary = new ByteArrayInputStream(IOUtils.toByteArray(content));
} } catch (Exception e) {
catch(IOException e) { LOG.warn("Contents of the binary resource '{}' not saved, got exception", name, e);
LOG.warn("Contents of the binary resource '{}' not saved, got exception {}", name, e);
} }
return resContainer; return resContainer;
} }
...@@ -94,7 +93,7 @@ public class ResContainer implements Comparable<ResContainer> { ...@@ -94,7 +93,7 @@ public class ResContainer implements Comparable<ResContainer> {
public CodeWriter getContent() { public CodeWriter getContent() {
return content; return content;
} }
@Nullable @Nullable
public InputStream getBinary() { public InputStream getBinary() {
return binary; return binary;
......
...@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory; ...@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
import jadx.api.ResourceFile; import jadx.api.ResourceFile;
import jadx.core.codegen.CodeWriter; import jadx.core.codegen.CodeWriter;
import jadx.core.utils.files.FileUtils;
import jadx.core.utils.files.ZipSecurity; import jadx.core.utils.files.ZipSecurity;
import static jadx.core.utils.files.FileUtils.prepareFile; import static jadx.core.utils.files.FileUtils.prepareFile;
...@@ -89,16 +90,16 @@ public class ResourcesSaver implements Runnable { ...@@ -89,16 +90,16 @@ public class ResourcesSaver implements Runnable {
return; return;
} }
InputStream binary = rc.getBinary(); InputStream binary = rc.getBinary();
if(binary != null) { if (binary != null) {
try { try {
outFile.getParentFile().mkdirs(); FileUtils.makeDirsForFile(outFile);
FileOutputStream binaryFileStream = new FileOutputStream(outFile); try (FileOutputStream binaryFileStream = new FileOutputStream(outFile)) {
IOUtils.copy(binary, binaryFileStream); IOUtils.copy(binary, binaryFileStream);
binaryFileStream.close(); } finally {
binary.close(); binary.close();
} }
catch(IOException e) { } catch (Exception e) {
LOG.warn("Resource '{}' not saved, got exception {}", rc.getName(), e); LOG.warn("Resource '{}' not saved, got exception", rc.getName(), e);
} }
return; 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