A bit of tidying here and there.

This commit is contained in:
Michael Bayne
2015-06-23 07:14:28 -07:00
parent 3933fee89c
commit 7a10d9a786
4 changed files with 38 additions and 55 deletions
@@ -17,6 +17,7 @@ import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import com.samskivert.io.StreamUtil;
import com.samskivert.text.MessageUtil;
import com.samskivert.util.StringUtil;
@@ -104,8 +105,7 @@ public class Digest
StringBuilder data = new StringBuilder();
PrintWriter pout = null;
try {
pout = new PrintWriter(
new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
pout = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
// compute and append the MD5 digest of each resource in the list
for (Resource rsrc : resources) {
@@ -126,9 +126,7 @@ public class Digest
pout.println(DIGEST_FILE + " = " + StringUtil.hexlate(md.digest(contents)));
} finally {
if (pout != null) {
pout.close();
}
StreamUtil.close(pout);
}
}
@@ -82,8 +82,7 @@ public class Digester
File inputFile = new File(appdir, Digest.DIGEST_FILE);
File signatureFile = new File(appdir, Digest.DIGEST_FILE + Application.SIGNATURE_SUFFIX);
FileInputStream storeInput = null;
FileInputStream dataInput = null;
FileInputStream storeInput = null, dataInput = null;
FileOutputStream signatureOutput = null;
try {
// initialize the keystore
@@ -109,9 +108,9 @@ public class Digester
signatureOutput.write(signed.getBytes("utf8"));
} finally {
StreamUtil.close(storeInput);
StreamUtil.close(dataInput);
StreamUtil.close(signatureOutput);
StreamUtil.close(dataInput);
StreamUtil.close(storeInput);
}
}
}
@@ -25,6 +25,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import com.samskivert.io.StreamUtil;
import com.threerings.getdown.util.ProgressObserver;
/**
@@ -43,15 +44,12 @@ public class JarDiffPatcher implements JarDiffCodes
*
* @throws IOException if any problem occurs during patching.
*/
public void patchJar (String jarPath, String diffPath, File target,
ProgressObserver observer)
public void patchJar (String jarPath, String diffPath, File target, ProgressObserver observer)
throws IOException
{
File oldFile = new File(jarPath);
File diffFile = new File(diffPath);
File oldFile = new File(jarPath), diffFile = new File(diffPath);
JarOutputStream jos = null;
JarFile oldJar = null;
JarFile jarDiff = null;
JarFile oldJar = null, jarDiff = null;
try {
jos = new JarOutputStream(new FileOutputStream(target));
oldJar = new JarFile(oldFile);
@@ -163,14 +161,13 @@ public class JarDiffPatcher implements JarDiffCodes
updateObserver(observer, currentEntry, size);
} finally {
jos = closeStream(jos);
oldJar = closeFile(oldJar);
jarDiff = closeFile(jarDiff);
StreamUtil.close(jos);
closeFile(oldJar);
closeFile(jarDiff);
}
}
protected void updateObserver (ProgressObserver observer,
double currentSize, double size)
protected void updateObserver (ProgressObserver observer, double currentSize, double size)
{
if (observer != null) {
observer.progress((int)(100*currentSize/size));
@@ -289,24 +286,14 @@ public class JarDiffPatcher implements JarDiffCodes
data.close();
}
private static JarFile closeFile(JarFile jar) {
private static void closeFile (JarFile jar) {
if (jar != null) {
try {
jar.close();
} catch (IOException e) {
e.printStackTrace(System.err);
}
}
return null;
}
private static JarOutputStream closeStream(JarOutputStream jar) {
if (jar != null) {
try {
jar.close();
} catch (IOException e) {
}
}
return null;
}
protected static final int DEFAULT_READ_SIZE = 2048;
@@ -110,7 +110,6 @@ public class VersionUtil
} finally {
StreamUtil.close(in);
}
}
private static int parseInt (String str) {