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.HashMap;
import java.util.List; import java.util.List;
import com.samskivert.io.StreamUtil;
import com.samskivert.text.MessageUtil; import com.samskivert.text.MessageUtil;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
@@ -104,8 +105,7 @@ public class Digest
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
PrintWriter pout = null; PrintWriter pout = null;
try { try {
pout = new PrintWriter( pout = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
// compute and append the MD5 digest of each resource in the list // compute and append the MD5 digest of each resource in the list
for (Resource rsrc : resources) { for (Resource rsrc : resources) {
@@ -126,9 +126,7 @@ public class Digest
pout.println(DIGEST_FILE + " = " + StringUtil.hexlate(md.digest(contents))); pout.println(DIGEST_FILE + " = " + StringUtil.hexlate(md.digest(contents)));
} finally { } finally {
if (pout != null) { StreamUtil.close(pout);
pout.close();
}
} }
} }
@@ -82,8 +82,7 @@ public class Digester
File inputFile = new File(appdir, Digest.DIGEST_FILE); File inputFile = new File(appdir, Digest.DIGEST_FILE);
File signatureFile = new File(appdir, Digest.DIGEST_FILE + Application.SIGNATURE_SUFFIX); File signatureFile = new File(appdir, Digest.DIGEST_FILE + Application.SIGNATURE_SUFFIX);
FileInputStream storeInput = null; FileInputStream storeInput = null, dataInput = null;
FileInputStream dataInput = null;
FileOutputStream signatureOutput = null; FileOutputStream signatureOutput = null;
try { try {
// initialize the keystore // initialize the keystore
@@ -109,9 +108,9 @@ public class Digester
signatureOutput.write(signed.getBytes("utf8")); signatureOutput.write(signed.getBytes("utf8"));
} finally { } finally {
StreamUtil.close(storeInput);
StreamUtil.close(dataInput);
StreamUtil.close(signatureOutput); 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.JarFile;
import java.util.jar.JarOutputStream; import java.util.jar.JarOutputStream;
import com.samskivert.io.StreamUtil;
import com.threerings.getdown.util.ProgressObserver; import com.threerings.getdown.util.ProgressObserver;
/** /**
@@ -43,15 +44,12 @@ public class JarDiffPatcher implements JarDiffCodes
* *
* @throws IOException if any problem occurs during patching. * @throws IOException if any problem occurs during patching.
*/ */
public void patchJar (String jarPath, String diffPath, File target, public void patchJar (String jarPath, String diffPath, File target, ProgressObserver observer)
ProgressObserver observer)
throws IOException throws IOException
{ {
File oldFile = new File(jarPath); File oldFile = new File(jarPath), diffFile = new File(diffPath);
File diffFile = new File(diffPath);
JarOutputStream jos = null; JarOutputStream jos = null;
JarFile oldJar = null; JarFile oldJar = null, jarDiff = null;
JarFile jarDiff = null;
try { try {
jos = new JarOutputStream(new FileOutputStream(target)); jos = new JarOutputStream(new FileOutputStream(target));
oldJar = new JarFile(oldFile); oldJar = new JarFile(oldFile);
@@ -163,18 +161,17 @@ public class JarDiffPatcher implements JarDiffCodes
updateObserver(observer, currentEntry, size); updateObserver(observer, currentEntry, size);
} finally { } finally {
jos = closeStream(jos); StreamUtil.close(jos);
oldJar = closeFile(oldJar); closeFile(oldJar);
jarDiff = closeFile(jarDiff); closeFile(jarDiff);
} }
} }
protected void updateObserver (ProgressObserver observer, protected void updateObserver (ProgressObserver observer, double currentSize, double size)
double currentSize, double size)
{ {
if (observer != null) { if (observer != null) {
observer.progress((int)(100*currentSize/size)); observer.progress((int)(100*currentSize/size));
} }
} }
protected void determineNameMapping ( protected void determineNameMapping (
@@ -289,27 +286,17 @@ public class JarDiffPatcher implements JarDiffCodes
data.close(); data.close();
} }
private static JarFile closeFile(JarFile jar) { private static void closeFile (JarFile jar) {
if (jar != null) { if (jar != null) {
try { try {
jar.close(); jar.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(System.err);
} }
} }
return null;
} }
private static JarOutputStream closeStream(JarOutputStream jar) { protected static final int DEFAULT_READ_SIZE = 2048;
if (jar != null) {
try {
jar.close();
} catch (IOException e) {
}
}
return null;
}
protected static final int DEFAULT_READ_SIZE = 2048;
protected static byte[] newBytes = new byte[DEFAULT_READ_SIZE]; protected static byte[] newBytes = new byte[DEFAULT_READ_SIZE];
protected static byte[] oldBytes = new byte[DEFAULT_READ_SIZE]; protected static byte[] oldBytes = new byte[DEFAULT_READ_SIZE];
@@ -110,7 +110,6 @@ public class VersionUtil
} finally { } finally {
StreamUtil.close(in); StreamUtil.close(in);
} }
} }
private static int parseInt (String str) { private static int parseInt (String str) {