- switch to java7 try-with-resources
 - add check in unit-tests for checking control
This commit is contained in:
Connor Tumbleson 2014-10-22 22:03:59 -05:00
parent 3e6fc8c5ef
commit 869d287aaa
2 changed files with 14 additions and 39 deletions

View File

@ -24,6 +24,7 @@ import brut.androlib.res.data.value.ResFileValue;
import brut.directory.DirUtil; import brut.directory.DirUtil;
import brut.directory.Directory; import brut.directory.Directory;
import brut.directory.DirectoryException; import brut.directory.DirectoryException;
import java.io.*; import java.io.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -106,25 +107,13 @@ public class ResFileDecoder {
public void decode(Directory inDir, String inFileName, Directory outDir, public void decode(Directory inDir, String inFileName, Directory outDir,
String outFileName, String decoder) throws AndrolibException { String outFileName, String decoder) throws AndrolibException {
InputStream in = null; try (
OutputStream out = null; InputStream in = inDir.getFileInput(inFileName);
try { OutputStream out = outDir.getFileOutput(outFileName)
in = inDir.getFileInput(inFileName); ) {
out = outDir.getFileOutput(outFileName);
mDecoders.decode(in, out, decoder); mDecoders.decode(in, out, decoder);
} catch (DirectoryException ex) { } catch (DirectoryException | IOException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ex) {
throw new AndrolibException(ex);
}
} }
} }
@ -138,29 +127,15 @@ public class ResFileDecoder {
public void decodeManifest(Directory inDir, String inFileName, public void decodeManifest(Directory inDir, String inFileName,
Directory outDir, String outFileName) throws AndrolibException { Directory outDir, String outFileName) throws AndrolibException {
InputStream in = null; try (
OutputStream out = null; InputStream in = inDir.getFileInput(inFileName);
try { OutputStream out = outDir.getFileOutput(outFileName)
in = inDir.getFileInput(inFileName); ) {
out = outDir.getFileOutput(outFileName); ((XmlPullStreamDecoder) mDecoders.getDecoder("xml")).decodeManifest(in, out);
((XmlPullStreamDecoder) mDecoders.getDecoder("xml")) } catch (DirectoryException | IOException ex) {
.decodeManifest(in, out);
} catch (DirectoryException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ex) {
throw new AndrolibException(ex);
}
} }
} }
private final static Logger LOGGER = Logger.getLogger(ResFileDecoder.class private final static Logger LOGGER = Logger.getLogger(ResFileDecoder.class.getName());
.getName());
} }

View File

@ -256,7 +256,7 @@ public class BuildAndDecodeTest {
// hacky fix - load test by changing name of control // hacky fix - load test by changing name of control
File test = new File(control.toString().replace("testapp-orig", "testapp-new")); File test = new File(control.toString().replace("testapp-orig", "testapp-new"));
if (test.isFile()) { if (test.isFile() && control.isFile()) {
if (control.hashCode() != test.hashCode()) { if (control.hashCode() != test.hashCode()) {
return false; return false;
} }