Reel in the verbosity a bit.
Other than to disambiguate for the compiler, I don't think clarity is enhanced with twenty plus individual imports from the most commonly used packages in the JDK (java.io + java.util). We all know where HashMap and InputStream are defined. Also some of the try-with-resources expanded multiple stream wrappers into individual declarations. This doesn't make things any safer, close one and you've closed them all. I reverted them to their more compact form.
This commit is contained in:
@@ -41,25 +41,9 @@
|
||||
|
||||
package com.threerings.getdown.tools;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
|
||||
/**
|
||||
* JarDiff is able to create a jar file containing the delta between two jar files (old and new).
|
||||
@@ -221,36 +205,32 @@ public class JarDiff implements JarDiffCodes
|
||||
Map<String,String> movedMap)
|
||||
throws IOException
|
||||
{
|
||||
try (StringWriter writer = new StringWriter()) {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.write(VERSION_HEADER);
|
||||
writer.write("\r\n");
|
||||
|
||||
writer.write(VERSION_HEADER);
|
||||
// Write out entries that have been removed
|
||||
for (String name : oldEntries) {
|
||||
writer.write(REMOVE_COMMAND);
|
||||
writer.write(" ");
|
||||
writeEscapedString(writer, name);
|
||||
writer.write("\r\n");
|
||||
|
||||
// Write out entries that have been removed
|
||||
for (String name : oldEntries) {
|
||||
writer.write(REMOVE_COMMAND);
|
||||
writer.write(" ");
|
||||
writeEscapedString(writer, name);
|
||||
writer.write("\r\n");
|
||||
}
|
||||
|
||||
// And those that have moved
|
||||
for (String newName : movedMap.keySet()) {
|
||||
String oldName = movedMap.get(newName);
|
||||
writer.write(MOVE_COMMAND);
|
||||
writer.write(" ");
|
||||
writeEscapedString(writer, oldName);
|
||||
writer.write(" ");
|
||||
writeEscapedString(writer, newName);
|
||||
writer.write("\r\n");
|
||||
}
|
||||
|
||||
JarEntry je = new JarEntry(INDEX_NAME);
|
||||
byte[] bytes = writer.toString().getBytes("UTF-8");
|
||||
|
||||
jos.putNextEntry(je);
|
||||
jos.write(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
// And those that have moved
|
||||
for (String newName : movedMap.keySet()) {
|
||||
String oldName = movedMap.get(newName);
|
||||
writer.write(MOVE_COMMAND);
|
||||
writer.write(" ");
|
||||
writeEscapedString(writer, oldName);
|
||||
writer.write(" ");
|
||||
writeEscapedString(writer, newName);
|
||||
writer.write("\r\n");
|
||||
}
|
||||
|
||||
jos.putNextEntry(new JarEntry(INDEX_NAME));
|
||||
byte[] bytes = writer.toString().getBytes("UTF-8");
|
||||
jos.write(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
private static void writeEscapedString (Writer writer, String string)
|
||||
@@ -284,21 +264,12 @@ public class JarDiff implements JarDiffCodes
|
||||
throws IOException
|
||||
{
|
||||
try (InputStream data = file.getJarFile().getInputStream(entry)) {
|
||||
writeEntry(jos, entry, data);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeEntry (JarOutputStream jos, JarEntry entry, InputStream data)
|
||||
throws IOException
|
||||
{
|
||||
jos.putNextEntry(entry);
|
||||
|
||||
// Read the entry
|
||||
int size = data.read(newBytes);
|
||||
|
||||
while (size != -1) {
|
||||
jos.write(newBytes, 0, size);
|
||||
size = data.read(newBytes);
|
||||
jos.putNextEntry(entry);
|
||||
int size = data.read(newBytes);
|
||||
while (size != -1) {
|
||||
jos.write(newBytes, 0, size);
|
||||
size = data.read(newBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,7 @@ public class JarDiffPatcher implements JarDiffCodes
|
||||
|
||||
try (JarFile oldJar = new JarFile(oldFile);
|
||||
JarFile jarDiff = new JarFile(diffFile);
|
||||
FileOutputStream fos = new FileOutputStream(target);
|
||||
JarOutputStream jos = new JarOutputStream(fos)) {
|
||||
JarOutputStream jos = new JarOutputStream(new FileOutputStream(target))) {
|
||||
|
||||
Set<String> ignoreSet = new HashSet<>();
|
||||
Map<String, String> renameMap = new HashMap<>();
|
||||
@@ -259,8 +258,7 @@ public class JarDiffPatcher implements JarDiffCodes
|
||||
return sub;
|
||||
}
|
||||
|
||||
protected void writeEntry (
|
||||
JarOutputStream jos, JarEntry entry, JarFile file)
|
||||
protected void writeEntry (JarOutputStream jos, JarEntry entry, JarFile file)
|
||||
throws IOException
|
||||
{
|
||||
try (InputStream data = file.getInputStream(entry)) {
|
||||
@@ -268,8 +266,7 @@ public class JarDiffPatcher implements JarDiffCodes
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeEntry (
|
||||
JarOutputStream jos, JarEntry entry, InputStream data)
|
||||
protected void writeEntry (JarOutputStream jos, JarEntry entry, InputStream data)
|
||||
throws IOException
|
||||
{
|
||||
jos.putNextEntry(new JarEntry(entry.getName()));
|
||||
|
||||
@@ -5,24 +5,9 @@
|
||||
|
||||
package com.threerings.getdown.util;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Pack200;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import com.samskivert.io.StreamUtil;
|
||||
@@ -153,13 +138,13 @@ public class FileUtil
|
||||
*/
|
||||
public static void unpackPacked200Jar (File packedJar, File target) throws IOException
|
||||
{
|
||||
try (InputStream packedJarIn = new FileInputStream(packedJar);
|
||||
FileOutputStream extractedJarFileOut = new FileOutputStream(target);
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(extractedJarFileOut)) {
|
||||
boolean gz = (packedJar.getName().endsWith(".gz") || packedJar.getName().endsWith(".gz_new"));
|
||||
try (InputStream packedJarIn2 = (gz ? new GZIPInputStream(packedJarIn) : packedJarIn)) {
|
||||
try (InputStream packJarIn = new FileInputStream(packedJar);
|
||||
JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(target))) {
|
||||
boolean gz = (packedJar.getName().endsWith(".gz") ||
|
||||
packedJar.getName().endsWith(".gz_new"));
|
||||
try (InputStream packJarIn2 = (gz ? new GZIPInputStream(packJarIn) : packJarIn)) {
|
||||
Pack200.Unpacker unpacker = Pack200.newUnpacker();
|
||||
unpacker.unpack(packedJarIn2, jarOutputStream);
|
||||
unpacker.unpack(packJarIn2, jarOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,7 @@ public class LaunchUtil
|
||||
{
|
||||
// create the file that instructs Getdown to upgrade
|
||||
File vfile = new File(appdir, "version.txt");
|
||||
try (FileOutputStream fos = new FileOutputStream(vfile);
|
||||
PrintStream ps = new PrintStream(fos)) {
|
||||
try (PrintStream ps = new PrintStream(new FileOutputStream(vfile))) {
|
||||
ps.println(newVersion);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,8 @@ public class VersionUtil
|
||||
public static long readVersion (File vfile)
|
||||
{
|
||||
long fileVersion = -1;
|
||||
try (FileInputStream fis = new FileInputStream(vfile);
|
||||
InputStreamReader reader = new InputStreamReader(fis);
|
||||
BufferedReader bin = new BufferedReader(reader)) {
|
||||
try (BufferedReader bin =
|
||||
new BufferedReader(new InputStreamReader(new FileInputStream(vfile)))) {
|
||||
String vstr = bin.readLine();
|
||||
if (!StringUtil.isBlank(vstr)) {
|
||||
fileVersion = Long.parseLong(vstr);
|
||||
@@ -51,8 +50,7 @@ public class VersionUtil
|
||||
*/
|
||||
public static void writeVersion (File vfile, long version) throws IOException
|
||||
{
|
||||
try (FileOutputStream fos = new FileOutputStream(vfile);
|
||||
PrintStream out = new PrintStream(fos)) {
|
||||
try (PrintStream out = new PrintStream(new FileOutputStream(vfile))) {
|
||||
out.println(version);
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to write version file: " + e.getMessage());
|
||||
@@ -83,9 +81,7 @@ public class VersionUtil
|
||||
*/
|
||||
public static long readReleaseVersion (File relfile, String versRegex)
|
||||
{
|
||||
try (FileReader reader = new FileReader(relfile);
|
||||
BufferedReader in = new BufferedReader(reader)) {
|
||||
|
||||
try (BufferedReader in = new BufferedReader(new FileReader(relfile))) {
|
||||
String line = null, relvers = null;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (line.startsWith("JAVA_VERSION=")) {
|
||||
|
||||
Reference in New Issue
Block a user