public Cache(File dir, int hoursChanging, int hoursStable)
throws IOException {
this.dir = dir;
- this.tooOldChanging = 1000 * 60 * 60 * hoursChanging;
- this.tooOldStable = 1000 * 60 * 60 * hoursStable;
+ this.tooOldChanging = 1000L * 60 * 60 * hoursChanging;
+ this.tooOldStable = 1000L * 60 * 60 * hoursStable;
if (dir != null && !dir.exists()) {
dir.mkdirs();
*/
private int clean(boolean onlyOld, File cacheDir) {
int num = 0;
- for (File file : cacheDir.listFiles()) {
- if (file.isDirectory()) {
- num += clean(onlyOld, file);
- } else {
- if (!onlyOld || isOld(file, true)) {
- if (file.delete()) {
- num++;
- } else {
- tracer.error("Cannot delete temporary file: "
- + file.getAbsolutePath());
+ File[] files = cacheDir.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (file.isDirectory()) {
+ num += clean(onlyOld, file);
+ } else {
+ if (!onlyOld || isOld(file, true)) {
+ if (file.delete()) {
+ num++;
+ } else {
+ tracer.error("Cannot delete temporary file: "
+ + file.getAbsolutePath());
+ }
}
}
}
}
if (requestData != null) {
- OutputStreamWriter writer = new OutputStreamWriter(
- conn.getOutputStream());
-
- writer.write(requestData.toString());
- writer.flush();
- writer.close();
+ OutputStreamWriter writer = null;
+ try {
+ writer = new OutputStreamWriter(conn.getOutputStream());
+ writer.write(requestData.toString());
+ writer.flush();
+ } finally {
+ if (writer != null) {
+ writer.close();
+ }
+ }
}
}
}
zip.putNextEntry(new ZipEntry(base + "/"));
}
- for (File file : target.listFiles()) {
- zip(zip, base, file, false);
+
+ File[] files = target.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ zip(zip, base, file, false);
+ }
}
} else {
if (base == null || base.isEmpty()) {
throws IOException {
List<File> list = deltree(target, null);
if (exception && !list.isEmpty()) {
- String slist = "";
+ StringBuilder slist = new StringBuilder();
for (File file : list) {
- slist += "\n" + file.getPath();
+ slist.append("\n").append(file.getPath());
}
throw new IOException("Cannot delete all the files from: <" //
- + target + ">:" + slist);
+ + target + ">:" + slist.toString());
}
return list.isEmpty();
* @return the Base64 representation
*/
public String toBase64() {
- return new String(Base64.encodeBytes(getData()));
+ return Base64.encodeBytes(getData());
}
/**
if (weight < min || weight > max) {
throw new RuntimeException(String.format(
"Progress object %s cannot have a weight of %f, "
- + "it is outside of its parent (%s) range (%f)",
+ + "it is outside of its parent (%s) range (%d)",
progress.name, weight, name, max));
}
name, progress.parent.name));
}
+ progress.parent = this;
+
progress.addProgressListener(new ProgressListener() {
@Override
public void progress(Progress pg, String name) {
}
}
- return builder.substring(1, builder.length() - 1).toString();
+ return builder.substring(1, builder.length() - 1);
}
}
}
} finally {
out.close();
+ out = null;
}
} finally {
in.close();
+ in = null;
}
} catch (Exception e) {
onError(e);
}
}
}
+ }
- // only return when stopped
- while (started || exiting) {
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- }
+ // return only when stopped
+ while (started || exiting) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
}
}
}
Socket s;
if (ssl) {
s = SSLSocketFactory.getDefault().createSocket(host, port);
- ((SSLSocket) s).setEnabledCipherSuites(ANON_CIPHERS);
+ if (s instanceof SSLSocket) {
+ // Should always be the case
+ ((SSLSocket) s).setEnabledCipherSuites(ANON_CIPHERS);
+ }
} else {
s = new Socket(host, port);
}
ServerSocket ss;
if (ssl) {
ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
- ((SSLServerSocket) ss).setEnabledCipherSuites(ANON_CIPHERS);
+ if (ss instanceof SSLServerSocket) {
+ // Should always be the case
+ ((SSLServerSocket) ss).setEnabledCipherSuites(ANON_CIPHERS);
+ }
} else {
ss = new ServerSocket(port);
}
* in case they differ
*/
public void assertEquals(long expected, long actual) throws AssertException {
- assertEquals(new Long(expected), new Long(actual));
+ assertEquals(Long.valueOf(expected), Long.valueOf(actual));
}
/**
*/
public void assertEquals(String errorMessage, long expected, long actual)
throws AssertException {
- assertEquals(errorMessage, new Long(expected), new Long(actual));
+ assertEquals(errorMessage, Long.valueOf(expected), Long.valueOf(actual));
}
/**
*/
public void assertEquals(boolean expected, boolean actual)
throws AssertException {
- assertEquals(new Boolean(expected), new Boolean(actual));
+ assertEquals(Boolean.valueOf(expected), Boolean.valueOf(actual));
}
/**
*/
public void assertEquals(String errorMessage, boolean expected,
boolean actual) throws AssertException {
- assertEquals(errorMessage, new Boolean(expected), new Boolean(actual));
+ assertEquals(errorMessage, Boolean.valueOf(expected),
+ Boolean.valueOf(actual));
}
/**
*/
public void assertEquals(double expected, double actual)
throws AssertException {
- assertEquals(new Double(expected), new Double(actual));
+ assertEquals(Double.valueOf(expected), Double.valueOf(actual));
}
/**
*/
public void assertEquals(String errorMessage, double expected, double actual)
throws AssertException {
- assertEquals(errorMessage, new Double(expected), new Double(actual));
+ assertEquals(errorMessage, Double.valueOf(expected),
+ Double.valueOf(actual));
}
/**
throws AssertException {
if (actual == null) {
String defaultReason = String.format("" //
- + "Assertion failed!\n" //
- + "Object should have been NULL: [%s]", actual);
+ + "Assertion failed!%n" //
+ + "Object should not have been NULL");
if (errorMessage == null) {
throw new AssertException(defaultReason);
*/
public static String generateAssertMessage(Object expected, Object actual) {
return String.format("" //
- + "Assertion failed!\n" //
- + "Expected value: [%s]\n" //
+ + "Assertion failed!%n" //
+ + "Expected value: [%s]%n" //
+ "Actual value: [%s]", expected, actual);
}
}
name = prefix(depth, false)
+ (name == null ? "" : name).replace("\t", " ");
- while (name.length() < columns - 11) {
- name += ".";
+ StringBuilder dots = new StringBuilder();
+ while ((name.length() + dots.length()) < columns - 11) {
+ dots.append('.');
}
- System.out.print(name);
+ System.out.print(name + dots.toString());
}
/**