fixed exception logging
This commit is contained in:
@@ -15,7 +15,7 @@ import java.util.logging.*;
|
||||
/**
|
||||
* A placeholder class that contains a reference to the log object used by the Getdown code.
|
||||
*/
|
||||
public class Log
|
||||
public final class Log
|
||||
{
|
||||
public static class Shim {
|
||||
/**
|
||||
@@ -143,6 +143,5 @@ public class Log
|
||||
protected FieldPosition _fpos = new FieldPosition(SimpleDateFormat.DATE_FIELD);
|
||||
}
|
||||
|
||||
protected static final String DATE_FORMAT = "{0,date} {0,time}";
|
||||
protected static final Level[] LEVELS = {Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE};
|
||||
}
|
||||
|
||||
@@ -96,6 +96,6 @@ public class GarbageCollector
|
||||
private static File getCachedFile (File file)
|
||||
{
|
||||
return !isLastAccessedFile(file) ? file : new File(
|
||||
file.getParentFile(), file.getName().substring(0, file.getName().lastIndexOf(".")));
|
||||
file.getParentFile(), file.getName().substring(0, file.getName().lastIndexOf('.')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ResourceCache
|
||||
|
||||
private String getFileSuffix (File fileToCache) {
|
||||
String fileName = fileToCache.getName();
|
||||
int index = fileName.lastIndexOf(".");
|
||||
int index = fileName.lastIndexOf('.');
|
||||
|
||||
return index > -1 ? fileName.substring(index) : "";
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import static com.threerings.getdown.Log.log;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* Parses and provide access to the information contained in the <code>getdown.txt</code>
|
||||
* Parses and provide access to the information contained in the {@code getdown.txt}
|
||||
* configuration file.
|
||||
*/
|
||||
public class Application
|
||||
@@ -212,10 +212,10 @@ public class Application
|
||||
* Used by {@link #verifyMetadata} to communicate status in circumstances where it needs to
|
||||
* take network actions.
|
||||
*/
|
||||
public static interface StatusDisplay
|
||||
public interface StatusDisplay
|
||||
{
|
||||
/** Requests that the specified status message be displayed. */
|
||||
public void updateStatus (String message);
|
||||
void updateStatus (String message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +277,7 @@ public class Application
|
||||
public Proxy proxy = Proxy.NO_PROXY;
|
||||
|
||||
/**
|
||||
* Creates an application instance which records the location of the <code>getdown.txt</code>
|
||||
* Creates an application instance which records the location of the {@code getdown.txt}
|
||||
* configuration file from the supplied application directory.
|
||||
*
|
||||
*/
|
||||
@@ -406,8 +406,7 @@ public class Application
|
||||
*/
|
||||
public List<Resource> getActiveCodeResources ()
|
||||
{
|
||||
ArrayList<Resource> codes = new ArrayList<>();
|
||||
codes.addAll(getCodeResources());
|
||||
List<Resource> codes = new ArrayList<>(getCodeResources());
|
||||
for (AuxGroup aux : getAuxGroups()) {
|
||||
if (isAuxGroupActive(aux.name)) {
|
||||
codes.addAll(aux.codes);
|
||||
@@ -435,8 +434,7 @@ public class Application
|
||||
*/
|
||||
public List<Resource> getActiveResources ()
|
||||
{
|
||||
ArrayList<Resource> rsrcs = new ArrayList<>();
|
||||
rsrcs.addAll(getResources());
|
||||
List<Resource> rsrcs = new ArrayList<>(getResources());
|
||||
for (AuxGroup aux : getAuxGroups()) {
|
||||
if (isAuxGroupActive(aux.name)) {
|
||||
rsrcs.addAll(aux.rsrcs);
|
||||
@@ -609,7 +607,7 @@ public class Application
|
||||
|
||||
// make sure there's a trailing slash
|
||||
if (!_appbase.endsWith("/")) {
|
||||
_appbase = _appbase + "/";
|
||||
_appbase += "/";
|
||||
}
|
||||
|
||||
// extract our version information
|
||||
@@ -913,7 +911,7 @@ public class Application
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to redownload the <code>getdown.txt</code> file based on information parsed from a
|
||||
* Attempts to redownload the {@code getdown.txt} file based on information parsed from a
|
||||
* previous call to {@link #init}.
|
||||
*/
|
||||
public void attemptRecovery (StatusDisplay status)
|
||||
@@ -924,7 +922,7 @@ public class Application
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads and replaces the <code>getdown.txt</code> and <code>digest.txt</code> files with
|
||||
* Downloads and replaces the {@code getdown.txt} and {@code digest.txt} files with
|
||||
* those for the target version of our application.
|
||||
*/
|
||||
public void updateMetadata ()
|
||||
@@ -935,7 +933,7 @@ public class Application
|
||||
_vappbase = createVAppBase(_targetVersion);
|
||||
} catch (MalformedURLException mue) {
|
||||
String err = MessageUtil.tcompose("m.invalid_appbase", _appbase);
|
||||
throw (IOException) new IOException(err).initCause(mue);
|
||||
throw new IOException(err, mue);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -1111,7 +1109,7 @@ public class Application
|
||||
for (String jvmarg : _jvmargs) {
|
||||
if (jvmarg.startsWith("-D")) {
|
||||
jvmarg = processArg(jvmarg.substring(2));
|
||||
int eqidx = jvmarg.indexOf("=");
|
||||
int eqidx = jvmarg.indexOf('=');
|
||||
if (eqidx == -1) {
|
||||
log.warning("Bogus system property: '" + jvmarg + "'?");
|
||||
} else {
|
||||
@@ -1173,8 +1171,8 @@ public class Application
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the <code>digest.txt</code> file and verifies the contents of both that file and the
|
||||
* <code>getdown.text</code> file. Then it loads the <code>version.txt</code> and decides
|
||||
* Loads the {@code digest.txt} file and verifies the contents of both that file and the
|
||||
* {@code getdown.text} file. Then it loads the {@code version.txt} and decides
|
||||
* whether or not the application needs to be updated or whether we can proceed to verification
|
||||
* and execution.
|
||||
*
|
||||
@@ -1265,7 +1263,7 @@ public class Application
|
||||
InputStreamReader reader = new InputStreamReader(in, UTF_8);
|
||||
BufferedReader bin = new BufferedReader(reader)) {
|
||||
for (String[] pair : Config.parsePairs(bin, Config.createOpts(false))) {
|
||||
if (pair[0].equals("version")) {
|
||||
if ("version".equals(pair[0])) {
|
||||
_targetVersion = Math.max(Long.parseLong(pair[1]), _targetVersion);
|
||||
if (fileVersion != -1 && _targetVersion > fileVersion) {
|
||||
// replace the file with the newest version
|
||||
@@ -1471,7 +1469,7 @@ public class Application
|
||||
protected URL createVAppBase (long version)
|
||||
throws MalformedURLException
|
||||
{
|
||||
String url = version < 0 ? _appbase : _appbase.replace("%VERSION%", "" + version);
|
||||
String url = version < 0 ? _appbase : _appbase.replace("%VERSION%", String.valueOf(version));
|
||||
return HostWhitelist.verify(new URL(url));
|
||||
}
|
||||
|
||||
@@ -1642,7 +1640,7 @@ public class Application
|
||||
} catch (Exception e) {
|
||||
log.warning("Requested to download invalid control file",
|
||||
"appbase", _vappbase, "path", path, "error", e);
|
||||
throw (IOException) new IOException("Invalid path '" + path + "'.").initCause(e);
|
||||
throw new IOException("Invalid path '" + path + "'.", e);
|
||||
}
|
||||
|
||||
log.info("Attempting to refetch '" + path + "' from '" + targetURL + "'.");
|
||||
@@ -1679,9 +1677,7 @@ public class Application
|
||||
/** Helper function to add all values in {@code values} (if non-null) to {@code target}. */
|
||||
protected static void addAll (String[] values, List<String> target) {
|
||||
if (values != null) {
|
||||
for (String value : values) {
|
||||
target.add(value);
|
||||
}
|
||||
Collections.addAll(target, values);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import static com.threerings.getdown.Log.log;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* Manages the <code>digest.txt</code> file and the computing and processing of digests for an
|
||||
* Manages the {@code digest.txt} file and the computing and processing of digests for an
|
||||
* application.
|
||||
*/
|
||||
public class Digest
|
||||
@@ -72,8 +72,7 @@ public class Digest
|
||||
digests.put(rsrc, rsrc.computeDigest(fversion, md, null));
|
||||
completed.add(rsrc);
|
||||
} catch (Throwable t) {
|
||||
completed.add(new IOException("Error computing digest for: " + rsrc).
|
||||
initCause(t));
|
||||
completed.add(new IOException("Error computing digest for: " + rsrc, t));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -88,7 +87,7 @@ public class Digest
|
||||
if (done instanceof IOException) {
|
||||
throw (IOException)done;
|
||||
} else if (done instanceof Resource) {
|
||||
pending.remove((Resource)done);
|
||||
pending.remove(done);
|
||||
} else {
|
||||
throw new AssertionError("What is this? " + done);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public final class EnvConfig {
|
||||
|
||||
/** Used to report problems or feedback by {@link #create}. */
|
||||
public static final class Note {
|
||||
public static enum Level { INFO, WARN, ERROR };
|
||||
public enum Level { INFO, WARN, ERROR }
|
||||
public static Note info (String msg) { return new Note(Level.INFO, msg); }
|
||||
public static Note warn (String msg) { return new Note(Level.WARN, msg); }
|
||||
public static Note error (String msg) { return new Note(Level.ERROR, msg); }
|
||||
|
||||
@@ -23,7 +23,7 @@ import static com.threerings.getdown.Log.log;
|
||||
public class Resource implements Comparable<Resource>
|
||||
{
|
||||
/** Defines special attributes for resources. */
|
||||
public static enum Attr {
|
||||
public enum Attr {
|
||||
/** Indicates that the resource should be unpacked. */
|
||||
UNPACK,
|
||||
/** If present, when unpacking a resource, any directories created by the newly
|
||||
@@ -35,7 +35,7 @@ public class Resource implements Comparable<Resource>
|
||||
PRELOAD,
|
||||
/** Indicates that the resource is a jar containing native libs. */
|
||||
NATIVE
|
||||
};
|
||||
}
|
||||
|
||||
public static final EnumSet<Attr> NORMAL = EnumSet.noneOf(Attr.class);
|
||||
public static final EnumSet<Attr> UNPACK = EnumSet.of(Attr.UNPACK);
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.threerings.getdown.util.VersionUtil;
|
||||
* accessor so that it's easy to see all of the secret system property arguments that Getdown makes
|
||||
* use of.
|
||||
*/
|
||||
public class SysProps
|
||||
public final class SysProps
|
||||
{
|
||||
/** Configures the appdir (in lieu of passing it in argv). Usage: {@code -Dappdir=foo}. */
|
||||
public static String appDir () {
|
||||
|
||||
@@ -11,7 +11,7 @@ package com.threerings.getdown.spi;
|
||||
public interface ProxyAuth
|
||||
{
|
||||
/** Credentials for a proxy server. */
|
||||
public static class Credentials {
|
||||
class Credentials {
|
||||
public final String username;
|
||||
public final String password;
|
||||
public Credentials (String username, String password) {
|
||||
@@ -23,10 +23,10 @@ public interface ProxyAuth
|
||||
/**
|
||||
* Loads the credentials for the app installed in {@code appDir}.
|
||||
*/
|
||||
public Credentials loadCredentials (String appDir);
|
||||
Credentials loadCredentials (String appDir);
|
||||
|
||||
/**
|
||||
* Encrypts and saves the credentials for the app installed in {@code appDir}.
|
||||
*/
|
||||
public void saveCredentials (String appDir, String username, String password);
|
||||
void saveCredentials (String appDir, String username, String password);
|
||||
}
|
||||
|
||||
@@ -5,10 +5,17 @@
|
||||
|
||||
package com.threerings.getdown.tools;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@@ -31,8 +38,8 @@ public class Differ
|
||||
/**
|
||||
* Creates a single patch file that contains the differences between
|
||||
* the two specified application directories. The patch file will be
|
||||
* created in the <code>nvdir</code> directory with name
|
||||
* <code>patchV.dat</code> where V is the old application version.
|
||||
* created in the {@code nvdir} directory with name
|
||||
* {@code patchV.dat} where V is the old application version.
|
||||
*/
|
||||
public void createDiff (File nvdir, File ovdir, boolean verbose)
|
||||
throws IOException
|
||||
@@ -53,13 +60,13 @@ public class Differ
|
||||
|
||||
Application oapp = new Application(new EnvConfig(ovdir));
|
||||
oapp.init(false);
|
||||
ArrayList<Resource> orsrcs = new ArrayList<>();
|
||||
List<Resource> orsrcs = new ArrayList<>();
|
||||
orsrcs.addAll(oapp.getCodeResources());
|
||||
orsrcs.addAll(oapp.getResources());
|
||||
|
||||
Application napp = new Application(new EnvConfig(nvdir));
|
||||
napp.init(false);
|
||||
ArrayList<Resource> nrsrcs = new ArrayList<>();
|
||||
List<Resource> nrsrcs = new ArrayList<>();
|
||||
nrsrcs.addAll(napp.getCodeResources());
|
||||
nrsrcs.addAll(napp.getResources());
|
||||
|
||||
@@ -83,8 +90,8 @@ public class Differ
|
||||
}
|
||||
}
|
||||
|
||||
protected void createPatch (File patch, ArrayList<Resource> orsrcs,
|
||||
ArrayList<Resource> nrsrcs, boolean verbose)
|
||||
protected void createPatch (File patch, List<Resource> orsrcs,
|
||||
List<Resource> nrsrcs, boolean verbose)
|
||||
throws IOException
|
||||
{
|
||||
int version = Digest.VERSION;
|
||||
@@ -200,7 +207,7 @@ public class Differ
|
||||
Differ differ = new Differ();
|
||||
boolean verbose = false;
|
||||
int aidx = 0;
|
||||
if (args[0].equals("-verbose")) {
|
||||
if ("-verbose".equals(args[0])) {
|
||||
verbose = true;
|
||||
aidx++;
|
||||
}
|
||||
|
||||
@@ -67,15 +67,15 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
public class JarDiff implements JarDiffCodes
|
||||
{
|
||||
private static final int DEFAULT_READ_SIZE = 2048;
|
||||
private static byte[] newBytes = new byte[DEFAULT_READ_SIZE];
|
||||
private static byte[] oldBytes = new byte[DEFAULT_READ_SIZE];
|
||||
private static final byte[] newBytes = new byte[DEFAULT_READ_SIZE];
|
||||
private static final byte[] oldBytes = new byte[DEFAULT_READ_SIZE];
|
||||
|
||||
// The JARDiff.java is the stand-alone jardiff.jar tool. Thus, we do not depend on Globals.java
|
||||
// and other stuff here. Instead, we use an explicit _debug flag.
|
||||
private static boolean _debug;
|
||||
|
||||
/**
|
||||
* Creates a patch from the two passed in files, writing the result to <code>os</code>.
|
||||
* Creates a patch from the two passed in files, writing the result to {@code os}.
|
||||
*/
|
||||
public static void createPatch (String oldPath, String newPath,
|
||||
OutputStream os, boolean minimal) throws IOException
|
||||
@@ -83,10 +83,10 @@ public class JarDiff implements JarDiffCodes
|
||||
try (ZipFile2 oldArchive = new ZipFile2(oldPath);
|
||||
ZipFile2 newArchive = new ZipFile2(newPath)) {
|
||||
|
||||
HashMap<String,String> moved = new HashMap<>();
|
||||
HashSet<String> implicit = new HashSet<>();
|
||||
HashSet<String> moveSrc = new HashSet<>();
|
||||
HashSet<String> newEntries = new HashSet<>();
|
||||
Map<String,String> moved = new HashMap<>();
|
||||
Set<String> implicit = new HashSet<>();
|
||||
Set<String> moveSrc = new HashSet<>();
|
||||
Set<String> newEntries = new HashSet<>();
|
||||
|
||||
// FIRST PASS
|
||||
// Go through the entries in new archive and determine which files are candidates for
|
||||
@@ -157,7 +157,7 @@ public class JarDiff implements JarDiffCodes
|
||||
|
||||
// SECOND PASS: <deleted files> = <oldjarnames> - <implicitmoves> -
|
||||
// <source of move commands> - <new or modified entries>
|
||||
ArrayList<String> deleted = new ArrayList<>();
|
||||
List<String> deleted = new ArrayList<>();
|
||||
for (ZipEntry oldEntry : oldArchive) {
|
||||
String oldName = oldEntry.getName();
|
||||
if (!implicit.contains(oldName) && !moveSrc.contains(oldName)
|
||||
@@ -203,9 +203,9 @@ public class JarDiff implements JarDiffCodes
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the index file out to <code>jos</code>.
|
||||
* <code>oldEntries</code> gives the names of the files that were removed,
|
||||
* <code>movedMap</code> maps from the new name to the old name.
|
||||
* Writes the index file out to {@code jos}.
|
||||
* {@code oldEntries} gives the names of the files that were removed,
|
||||
* {@code movedMap} maps from the new name to the old name.
|
||||
*/
|
||||
private static void createIndex (ZipOutputStream jos, List<String> oldEntries,
|
||||
Map<String,String> movedMap)
|
||||
@@ -286,7 +286,7 @@ public class JarDiff implements JarDiffCodes
|
||||
*/
|
||||
private static class ZipFile2 implements Iterable<ZipEntry>, Closeable
|
||||
{
|
||||
private ZipFile _archive;
|
||||
private final ZipFile _archive;
|
||||
private List<ZipEntry> _entries;
|
||||
private HashMap<String,ZipEntry> _nameToEntryMap;
|
||||
private HashMap<Long,LinkedList<ZipEntry>> _crcToEntryMap;
|
||||
@@ -384,7 +384,7 @@ public class JarDiff implements JarDiffCodes
|
||||
|
||||
public String hasSameContent (ZipFile2 file, ZipEntry entry) throws IOException {
|
||||
String thisName = null;
|
||||
Long crcL = Long.valueOf(entry.getCrc());
|
||||
Long crcL = entry.getCrc();
|
||||
// check if this archive contains files with the passed in entry's crc
|
||||
if (_crcToEntryMap.containsKey(crcL)) {
|
||||
// get the Linked List with files with the crc
|
||||
@@ -419,7 +419,7 @@ public class JarDiff implements JarDiffCodes
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
long crc = entry.getCrc();
|
||||
Long crcL = Long.valueOf(crc);
|
||||
Long crcL = crc;
|
||||
if (_debug) {
|
||||
System.out.println("\t" + entry.getName() + " CRC " + crc);
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public class JarDiffPatcher implements JarDiffCodes
|
||||
{
|
||||
int index = 0;
|
||||
int length = path.length();
|
||||
ArrayList<String> sub = new ArrayList<>();
|
||||
List<String> sub = new ArrayList<>();
|
||||
|
||||
while (index < length) {
|
||||
while (index < length && Character.isWhitespace
|
||||
@@ -223,9 +223,8 @@ public class JarDiffPatcher implements JarDiffCodes
|
||||
index++;
|
||||
}
|
||||
if (index < length) {
|
||||
int start = index;
|
||||
int last = start;
|
||||
String subString = null;
|
||||
int last = index;
|
||||
StringBuilder subString = null;
|
||||
|
||||
while (index < length) {
|
||||
char aChar = path.charAt(index);
|
||||
@@ -233,9 +232,9 @@ public class JarDiffPatcher implements JarDiffCodes
|
||||
path.charAt(index + 1) == ' ') {
|
||||
|
||||
if (subString == null) {
|
||||
subString = path.substring(last, index);
|
||||
subString = new StringBuilder(path.substring(last, index));
|
||||
} else {
|
||||
subString += path.substring(last, index);
|
||||
subString.append(path, last, index);
|
||||
}
|
||||
last = ++index;
|
||||
} else if (Character.isWhitespace(aChar)) {
|
||||
@@ -245,12 +244,14 @@ public class JarDiffPatcher implements JarDiffCodes
|
||||
}
|
||||
if (last != index) {
|
||||
if (subString == null) {
|
||||
subString = path.substring(last, index);
|
||||
subString = new StringBuilder(path.substring(last, index));
|
||||
} else {
|
||||
subString += path.substring(last, index);
|
||||
subString.append(path, last, index);
|
||||
}
|
||||
}
|
||||
sub.add(subString);
|
||||
if (subString != null) {
|
||||
sub.add(subString.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return sub;
|
||||
|
||||
@@ -24,7 +24,7 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
|
||||
* href="http://www.ietf.org/rfc/rfc2045.txt">2045</a> and <a
|
||||
* href="http://www.ietf.org/rfc/rfc3548.txt">3548</a>.
|
||||
*/
|
||||
public class Base64 {
|
||||
public final class Base64 {
|
||||
/**
|
||||
* Default values for encoder/decoder flags.
|
||||
*/
|
||||
@@ -68,7 +68,7 @@ public class Base64 {
|
||||
// shared code
|
||||
// --------------------------------------------------------
|
||||
|
||||
/* package */ static abstract class Coder {
|
||||
/* package */ abstract static class Coder {
|
||||
public byte[] output;
|
||||
public int op;
|
||||
|
||||
@@ -178,7 +178,7 @@ public class Base64 {
|
||||
* Lookup table for turning bytes into their position in the
|
||||
* Base64 alphabet.
|
||||
*/
|
||||
private static final int DECODE[] = {
|
||||
private static final int[] DECODE = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
|
||||
@@ -201,7 +201,7 @@ public class Base64 {
|
||||
* Decode lookup table for the "web safe" variant (RFC 3548
|
||||
* sec. 4) where - and _ replace + and /.
|
||||
*/
|
||||
private static final int DECODE_WEBSAFE[] = {
|
||||
private static final int[] DECODE_WEBSAFE = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1,
|
||||
@@ -236,7 +236,7 @@ public class Base64 {
|
||||
private int state; // state number (0 to 6)
|
||||
private int value;
|
||||
|
||||
final private int[] alphabet;
|
||||
private final int[] alphabet;
|
||||
|
||||
public Decoder(int flags, byte[] output) {
|
||||
this.output = output;
|
||||
@@ -541,7 +541,7 @@ public class Base64 {
|
||||
* Lookup table for turning Base64 alphabet positions (6 bits)
|
||||
* into output bytes.
|
||||
*/
|
||||
private static final byte ENCODE[] = {
|
||||
private static final byte[] ENCODE = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
@@ -552,21 +552,21 @@ public class Base64 {
|
||||
* Lookup table for turning Base64 alphabet positions (6 bits)
|
||||
* into output bytes.
|
||||
*/
|
||||
private static final byte ENCODE_WEBSAFE[] = {
|
||||
private static final byte[] ENCODE_WEBSAFE = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
|
||||
};
|
||||
|
||||
final private byte[] tail;
|
||||
private final byte[] tail;
|
||||
/* package */ int tailLen;
|
||||
private int count;
|
||||
|
||||
final public boolean do_padding;
|
||||
final public boolean do_newline;
|
||||
final public boolean do_cr;
|
||||
final private byte[] alphabet;
|
||||
public final boolean do_padding;
|
||||
public final boolean do_newline;
|
||||
public final boolean do_cr;
|
||||
private final byte[] alphabet;
|
||||
|
||||
public Encoder(int flags, byte[] output) {
|
||||
this.output = output;
|
||||
@@ -618,7 +618,7 @@ public class Base64 {
|
||||
((input[p++] & 0xff) << 8) |
|
||||
(input[p++] & 0xff);
|
||||
tailLen = 0;
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
@@ -8,11 +8,11 @@ package com.threerings.getdown.util;
|
||||
/**
|
||||
* Utilities for handling ARGB colors.
|
||||
*/
|
||||
public class Color
|
||||
public final class Color
|
||||
{
|
||||
public final static int CLEAR = 0x00000000;
|
||||
public final static int WHITE = 0xFFFFFFFF;
|
||||
public final static int BLACK = 0xFF000000;
|
||||
public static final int CLEAR = 0x00000000;
|
||||
public static final int WHITE = 0xFFFFFFFF;
|
||||
public static final int BLACK = 0xFF000000;
|
||||
|
||||
public static float brightness (int argb) {
|
||||
// TODO: we're ignoring alpha here...
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Config
|
||||
*
|
||||
* @param opts options that influence the parsing. See {@link #createOpts}.
|
||||
*
|
||||
* @return a list of <code>String[]</code> instances containing the key/value pairs in the
|
||||
* @return a list of {@code String[]} instances containing the key/value pairs in the
|
||||
* order they were parsed from the file.
|
||||
*/
|
||||
public static List<String[]> parsePairs (File source, ParseOpts opts)
|
||||
@@ -83,7 +83,7 @@ public class Config
|
||||
List<String[]> pairs = new ArrayList<>();
|
||||
for (String line : FileUtil.readLines(source)) {
|
||||
// nix comments
|
||||
int cidx = line.indexOf("#");
|
||||
int cidx = line.indexOf('#');
|
||||
if (opts.strictComments ? cidx == 0 : cidx != -1) {
|
||||
line = line.substring(0, cidx);
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class Config
|
||||
// parse our key/value pair
|
||||
String[] pair = new String[2];
|
||||
// if we're biasing toward key, put all the extra = in the key rather than the value
|
||||
int eidx = opts.biasToKey ? line.lastIndexOf("=") : line.indexOf("=");
|
||||
int eidx = opts.biasToKey ? line.lastIndexOf('=') : line.indexOf('=');
|
||||
if (eidx != -1) {
|
||||
pair[0] = line.substring(0, eidx).trim();
|
||||
pair[1] = line.substring(eidx+1).trim();
|
||||
@@ -108,7 +108,7 @@ public class Config
|
||||
|
||||
// if the pair has an os qualifier, we need to process it
|
||||
if (pair[1].startsWith("[")) {
|
||||
int qidx = pair[1].indexOf("]");
|
||||
int qidx = pair[1].indexOf(']');
|
||||
if (qidx == -1) {
|
||||
log.warning("Bogus platform specifier", "key", pair[0], "value", pair[1]);
|
||||
continue; // omit the pair entirely
|
||||
@@ -351,7 +351,7 @@ public class Config
|
||||
protected static boolean checkQualifiers (String quals, String osname, String osarch)
|
||||
{
|
||||
if (quals.startsWith("!")) {
|
||||
if (quals.indexOf(",") != -1) { // sanity check
|
||||
if (quals.contains(",")) { // sanity check
|
||||
log.warning("Multiple qualifiers cannot be used when one of the qualifiers " +
|
||||
"is negative", "quals", quals);
|
||||
return false;
|
||||
@@ -371,7 +371,7 @@ public class Config
|
||||
{
|
||||
String[] bits = qual.trim().toLowerCase(Locale.ROOT).split("-");
|
||||
String os = bits[0], arch = (bits.length > 1) ? bits[1] : "";
|
||||
return (osname.indexOf(os) != -1) && (osarch.indexOf(arch) != -1);
|
||||
return (osname.contains(os)) && (osarch.contains(arch));
|
||||
}
|
||||
|
||||
private final Map<String, Object> _data;
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.threerings.getdown.data.SysProps;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public class ConnectionUtil
|
||||
public final class ConnectionUtil
|
||||
{
|
||||
/**
|
||||
* Opens a connection to a URL, setting the authentication header if user info is present.
|
||||
|
||||
@@ -17,19 +17,19 @@ import static com.threerings.getdown.Log.log;
|
||||
* Useful routines for launching Java applications from within other Java
|
||||
* applications.
|
||||
*/
|
||||
public class LaunchUtil
|
||||
public final class LaunchUtil
|
||||
{
|
||||
/** The default directory into which a local VM installation should be unpacked. */
|
||||
public static final String LOCAL_JAVA_DIR = "java_vm";
|
||||
|
||||
/**
|
||||
* Writes a <code>version.txt</code> file into the specified application directory and
|
||||
* Writes a {@code version.txt} file into the specified application directory and
|
||||
* attempts to relaunch Getdown in that directory which will cause it to upgrade to the newly
|
||||
* specified version and relaunch the application.
|
||||
*
|
||||
* @param appdir the directory in which the application is installed.
|
||||
* @param getdownJarName the name of the getdown jar file in the application directory. This is
|
||||
* probably <code>getdown-pro.jar</code> or <code>getdown-retro-pro.jar</code> if you are using
|
||||
* probably {@code getdown-pro.jar} or {@code getdown-retro-pro.jar} if you are using
|
||||
* the results of the standard build.
|
||||
* @param newVersion the new version to which Getdown will update when it is executed.
|
||||
* @param javaLocalDir the name of the directory (inside {@code appdir}) that contains a
|
||||
@@ -41,7 +41,7 @@ public class LaunchUtil
|
||||
* after making this call as it will be upgraded and restarted. If false is returned, the
|
||||
* application should tell the user that they must restart the application manually.
|
||||
*
|
||||
* @exception IOException thrown if we were unable to create the <code>version.txt</code> file
|
||||
* @exception IOException thrown if we were unable to create the {@code version.txt} file
|
||||
* in the supplied application directory. If the version.txt file cannot be created, restarting
|
||||
* Getdown will not cause the application to be upgraded, so the application will have to
|
||||
* resort to telling the user that it is in a bad way.
|
||||
@@ -177,23 +177,23 @@ public class LaunchUtil
|
||||
public static boolean mustMonitorChildren ()
|
||||
{
|
||||
String osname = System.getProperty("os.name", "").toLowerCase(Locale.ROOT);
|
||||
return (osname.indexOf("windows 98") != -1 || osname.indexOf("windows me") != -1);
|
||||
return (osname.contains("windows 98") || osname.contains("windows me"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if we're running in a JVM that identifies its operating system as Windows.
|
||||
*/
|
||||
public static final boolean isWindows () { return _isWindows; }
|
||||
public static boolean isWindows () { return _isWindows; }
|
||||
|
||||
/**
|
||||
* Returns true if we're running in a JVM that identifies its operating system as MacOS.
|
||||
*/
|
||||
public static final boolean isMacOS () { return _isMacOS; }
|
||||
public static boolean isMacOS () { return _isMacOS; }
|
||||
|
||||
/**
|
||||
* Returns true if we're running in a JVM that identifies its operating system as Linux.
|
||||
*/
|
||||
public static final boolean isLinux () { return _isLinux; }
|
||||
public static boolean isLinux () { return _isLinux; }
|
||||
|
||||
/**
|
||||
* Checks whether a Java Virtual Machine can be located in the supplied path.
|
||||
@@ -232,10 +232,9 @@ public class LaunchUtil
|
||||
try {
|
||||
String osname = System.getProperty("os.name");
|
||||
osname = (osname == null) ? "" : osname;
|
||||
_isWindows = (osname.indexOf("Windows") != -1);
|
||||
_isMacOS = (osname.indexOf("Mac OS") != -1 ||
|
||||
osname.indexOf("MacOS") != -1);
|
||||
_isLinux = (osname.indexOf("Linux") != -1);
|
||||
_isWindows = (osname.contains("Windows"));
|
||||
_isMacOS = (osname.contains("Mac OS") || osname.contains("MacOS"));
|
||||
_isLinux = (osname.contains("Linux"));
|
||||
} catch (Exception e) {
|
||||
// can't grab system properties; we'll just pretend we're not on any of these OSes
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package com.threerings.getdown.util;
|
||||
|
||||
public class MessageUtil {
|
||||
public final class MessageUtil {
|
||||
|
||||
/**
|
||||
* Returns whether or not the provided string is tainted. See {@link #taint}. Null strings
|
||||
@@ -101,11 +101,11 @@ public class MessageUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to escape single quotes so that they are not interpreted by <code>MessageFormat</code>.
|
||||
* Used to escape single quotes so that they are not interpreted by {@code MessageFormat}.
|
||||
* As we assume all single quotes are to be escaped, we cannot use the characters
|
||||
* <code>{</code> and <code>}</code> in our translation strings, but this is a small price to
|
||||
* pay to have to differentiate between messages that will and won't eventually be parsed by a
|
||||
* <code>MessageFormat</code> instance.
|
||||
* {@code MessageFormat} instance.
|
||||
*/
|
||||
public static String escape (String message)
|
||||
{
|
||||
|
||||
@@ -14,5 +14,5 @@ public interface ProgressObserver
|
||||
* Informs the observer that we have completed the specified
|
||||
* percentage of the process.
|
||||
*/
|
||||
public void progress (int percent);
|
||||
void progress (int percent);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,10 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static com.threerings.getdown.Log.log;
|
||||
|
||||
public class StreamUtil {
|
||||
public final class StreamUtil {
|
||||
/**
|
||||
* Convenient close for a stream. Use in a finally clause and love life.
|
||||
*/
|
||||
|
||||
@@ -7,14 +7,14 @@ package com.threerings.getdown.util;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class StringUtil {
|
||||
public final class StringUtil {
|
||||
|
||||
/**
|
||||
* @return true if the specified string could be a valid URL (contains no illegal characters)
|
||||
*/
|
||||
public static boolean couldBeValidUrl (String url)
|
||||
{
|
||||
return url.matches("[A-Za-z0-9\\-\\._~:/\\?#\\[\\]@!$&'\\(\\)\\*\\+,;=%]+");
|
||||
return url.matches("[A-Za-z0-9\\-._~:/?#\\[\\]@!$&'()*+,;=%]+");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +84,7 @@ public class StringUtil {
|
||||
source = source.replace(",,", "%COMMA%");
|
||||
|
||||
// count up the number of tokens
|
||||
while ((tpos = source.indexOf(",", tpos+1)) != -1) {
|
||||
while ((tpos = source.indexOf(',', tpos+1)) != -1) {
|
||||
tcount++;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class StringUtil {
|
||||
tpos = -1; tcount = 0;
|
||||
|
||||
// do the split
|
||||
while ((tpos = source.indexOf(",", tpos+1)) != -1) {
|
||||
while ((tpos = source.indexOf(',', tpos+1)) != -1) {
|
||||
tokens[tcount] = source.substring(tstart, tpos);
|
||||
tokens[tcount] = tokens[tcount].trim().replace("%COMMA%", ",");
|
||||
if (intern) {
|
||||
@@ -119,7 +119,7 @@ public class StringUtil {
|
||||
|
||||
/**
|
||||
* Generates a string from the supplied bytes that is the HEX encoded representation of those
|
||||
* bytes. Returns the empty string for a <code>null</code> or empty byte array.
|
||||
* bytes. Returns the empty string for a {@code null} or empty byte array.
|
||||
*
|
||||
* @param bytes the bytes for which we want a string representation.
|
||||
* @param count the number of bytes to stop at (which will be coerced into being {@code <=} the
|
||||
@@ -185,7 +185,7 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for the various <code>join</code> methods.
|
||||
* Helper function for the various {@code join} methods.
|
||||
*/
|
||||
protected static String join (Object[] values, String separator, boolean escape)
|
||||
{
|
||||
@@ -201,6 +201,6 @@ public class StringUtil {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/** Used by {@link #hexlate} and {@link #unhexlate}. */
|
||||
/** Used by {@link #hexlate}. */
|
||||
protected static final String XLATE = "0123456789abcdef";
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
/**
|
||||
* Version related utilities.
|
||||
*/
|
||||
public class VersionUtil
|
||||
public final class VersionUtil
|
||||
{
|
||||
/**
|
||||
* Reads a version number from a file.
|
||||
|
||||
Reference in New Issue
Block a user