aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/cache
diff options
context:
space:
mode:
authorDeepak Bhole <[email protected]>2010-12-06 15:34:01 -0500
committerDeepak Bhole <[email protected]>2010-12-06 15:34:01 -0500
commit6ca1a9a369b10703da9af8f8a1ced0f3b02ae5c2 (patch)
tree568f8e454db94fa8abc896b46ce8cac7a9f3b74d /netx/net/sourceforge/jnlp/cache
parent0d66adf24179c33bbdccaacc10d4c8a5f5e2cd54 (diff)
Fixed indentation and spacing for all .java files.
Added a new .settings directory which contains Eclipse preferences for code style.
Diffstat (limited to 'netx/net/sourceforge/jnlp/cache')
-rw-r--r--netx/net/sourceforge/jnlp/cache/CacheEntry.java13
-rw-r--r--netx/net/sourceforge/jnlp/cache/CacheUtil.java67
-rw-r--r--netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java33
-rw-r--r--netx/net/sourceforge/jnlp/cache/DownloadIndicator.java1
-rw-r--r--netx/net/sourceforge/jnlp/cache/Resource.java48
-rw-r--r--netx/net/sourceforge/jnlp/cache/ResourceTracker.java104
-rw-r--r--netx/net/sourceforge/jnlp/cache/UpdatePolicy.java3
7 files changed, 120 insertions, 149 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/CacheEntry.java b/netx/net/sourceforge/jnlp/cache/CacheEntry.java
index d442a90..9299962 100644
--- a/netx/net/sourceforge/jnlp/cache/CacheEntry.java
+++ b/netx/net/sourceforge/jnlp/cache/CacheEntry.java
@@ -14,7 +14,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
package net.sourceforge.jnlp.cache;
import static net.sourceforge.jnlp.runtime.Translator.R;
@@ -47,7 +46,6 @@ public class CacheEntry {
/** info about the cached file */
private PropertiesFile properties;
-
/**
* Create a CacheEntry for the resources specified as a remote
* URL.
@@ -60,7 +58,7 @@ public class CacheEntry {
this.version = version;
File infoFile = CacheUtil.getCacheFile(location, version);
- infoFile = new File(infoFile.getPath()+".info"); // replace with something that can't be clobbered
+ infoFile = new File(infoFile.getPath() + ".info"); // replace with something that can't be clobbered
properties = new PropertiesFile(infoFile, R("CAutoGen"));
}
@@ -91,8 +89,7 @@ public class CacheEntry {
public long getLastUpdated() {
try {
return Long.parseLong(properties.getProperty("last-updated"));
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
return 0;
}
}
@@ -127,8 +124,7 @@ public class CacheEntry {
return true;
else
return false;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
@@ -155,8 +151,7 @@ public class CacheEntry {
return false;
else
return true;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
diff --git a/netx/net/sourceforge/jnlp/cache/CacheUtil.java b/netx/net/sourceforge/jnlp/cache/CacheUtil.java
index 04b5adc..e316282 100644
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java
@@ -14,7 +14,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
package net.sourceforge.jnlp.cache;
import static net.sourceforge.jnlp.runtime.Translator.R;
@@ -49,17 +48,17 @@ public class CacheUtil {
* ie sourceforge.net and www.sourceforge.net).
*/
public static boolean urlEquals(URL u1, URL u2) {
- if (u1==u2)
+ if (u1 == u2)
return true;
- if (u1==null || u2==null)
+ if (u1 == null || u2 == null)
return false;
if (!compare(u1.getProtocol(), u2.getProtocol(), true) ||
- !compare(u1.getHost(), u2.getHost(), true) ||
- //u1.getDefaultPort() != u2.getDefaultPort() || // only in 1.4
- !compare(u1.getPath(), u2.getPath(), false) ||
- !compare(u1.getQuery(), u2.getQuery(), false) ||
- !compare(u1.getRef(), u2.getRef(), false))
+ !compare(u1.getHost(), u2.getHost(), true) ||
+ //u1.getDefaultPort() != u2.getDefaultPort() || // only in 1.4
+ !compare(u1.getPath(), u2.getPath(), false) ||
+ !compare(u1.getQuery(), u2.getQuery(), false) ||
+ !compare(u1.getRef(), u2.getRef(), false))
return false;
else
return true;
@@ -82,8 +81,7 @@ public class CacheUtil {
File f = rt.getCacheFile(location);
// TODO: Should be toURI().toURL()
return f.toURL();
- }
- catch (MalformedURLException ex) {
+ } catch (MalformedURLException ex) {
return location;
}
}
@@ -92,9 +90,9 @@ public class CacheUtil {
* Compare strings that can be null.
*/
private static boolean compare(String s1, String s2, boolean ignore) {
- if (s1==s2)
+ if (s1 == s2)
return true;
- if (s1==null || s2==null)
+ if (s1 == null || s2 == null)
return false;
if (ignore)
@@ -112,16 +110,14 @@ public class CacheUtil {
File file = CacheUtil.getCacheFile(location, version);
return new FilePermission(file.getPath(), "read");
- }
- else {
+ } else {
try {
// this is what URLClassLoader does
return location.openConnection().getPermission();
- }
- catch (java.io.IOException ioe) {
+ } catch (java.io.IOException ioe) {
// should try to figure out the permission
if (JNLPRuntime.isDebug())
- ioe.printStackTrace();
+ ioe.printStackTrace();
}
}
@@ -223,11 +219,10 @@ public class CacheUtil {
boolean result = entry.isCurrent(connection);
if (JNLPRuntime.isDebug())
- System.out.println("isCurrent: "+source+" = "+result);
+ System.out.println("isCurrent: " + source + " = " + result);
return result;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
@@ -252,7 +247,7 @@ public class CacheUtil {
boolean result = entry.isCached();
if (JNLPRuntime.isDebug())
- System.out.println("isCached: "+source+" = "+result);
+ System.out.println("isCached: " + source + " = " + result);
return result;
}
@@ -294,13 +289,12 @@ public class CacheUtil {
try {
String cacheDir = JNLPRuntime.getConfiguration()
- .getProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR);
+ .getProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR);
File localFile = urlToPath(source, cacheDir);
localFile.getParentFile().mkdirs();
return localFile;
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
@@ -343,8 +337,7 @@ public class CacheUtil {
os.write(b, 0, c);
}
- }
- finally {
+ } finally {
is.close();
os.close();
}
@@ -378,7 +371,6 @@ public class CacheUtil {
return new File(FileUtils.sanitizePath(path.toString()));
}
-
/**
* Waits until the resources are downloaded, while showing a
* progress indicator.
@@ -404,11 +396,11 @@ public class CacheUtil {
// only resources not starting out downloaded are displayed
List<URL> urlList = new ArrayList<URL>();
- for (int i=0; i < resources.length; i++) {
+ for (int i = 0; i < resources.length; i++) {
if (!tracker.checkResource(resources[i]))
urlList.add(resources[i]);
}
- URL undownloaded[] = urlList.toArray( new URL[urlList.size()] );
+ URL undownloaded[] = urlList.toArray(new URL[urlList.size()]);
listener = indicator.getListener(app, title, undownloaded);
@@ -416,35 +408,32 @@ public class CacheUtil {
long read = 0;
long total = 0;
- for (int i=0; i < undownloaded.length; i++) {
+ for (int i = 0; i < undownloaded.length; i++) {
// add in any -1's; they're insignificant
total += tracker.getTotalSize(undownloaded[i]);
read += tracker.getAmountRead(undownloaded[i]);
}
- int percent = (int)( (100*read)/Math.max(1,total) );
+ int percent = (int) ((100 * read) / Math.max(1, total));
- for (int i=0; i < undownloaded.length; i++)
+ for (int i = 0; i < undownloaded.length; i++)
listener.progress(undownloaded[i], "version",
tracker.getAmountRead(undownloaded[i]),
tracker.getTotalSize(undownloaded[i]),
percent);
- }
- while (!tracker.waitForResources(resources, indicator.getUpdateRate()));
+ } while (!tracker.waitForResources(resources, indicator.getUpdateRate()));
// make sure they read 100% until indicator closes
- for (int i=0; i < undownloaded.length; i++)
+ for (int i = 0; i < undownloaded.length; i++)
listener.progress(undownloaded[i], "version",
tracker.getTotalSize(undownloaded[i]),
tracker.getTotalSize(undownloaded[i]),
100);
- }
- catch (InterruptedException ex) {
+ } catch (InterruptedException ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
- }
- finally {
+ } finally {
if (listener != null)
indicator.disposeListener(listener);
}
diff --git a/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java b/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java
index f7c382e..7472307 100644
--- a/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java
+++ b/netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java
@@ -14,7 +14,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
package net.sourceforge.jnlp.cache;
import static net.sourceforge.jnlp.runtime.Translator.R;
@@ -100,12 +99,12 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
DownloadPanel result = new DownloadPanel(downloadName);
if (frame == null) {
- frame = new JFrame(downloading+"...");
+ frame = new JFrame(downloading + "...");
frame.getContentPane().setLayout(new GridBagLayout());
}
if (resources != null)
- for (int i=0; i < resources.length; i++)
+ for (int i = 0; i < resources.length; i++)
result.addProgressPanel(resources[i], null);
frame.getContentPane().add(result, vertical);
@@ -114,10 +113,10 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
if (!frame.isVisible()) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
- Dimension screen = new Dimension(screenSize.width - insets.left ,
+ Dimension screen = new Dimension(screenSize.width - insets.left,
screenSize.height - insets.top);
- frame.setLocation(screen.width-frame.getWidth(),
- screen.height-frame.getHeight());
+ frame.setLocation(screen.width - frame.getWidth(),
+ screen.height - frame.getHeight());
}
frame.setVisible(true);
@@ -149,8 +148,6 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
timer.start();
}
-
-
/**
* Groups the url progress in a panel.
*/
@@ -168,7 +165,6 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
/** list of ProgressPanels */
private List<ProgressPanel> panels = new ArrayList<ProgressPanel>();
-
/**
* Create a new download panel for with the specified download
* name.
@@ -226,7 +222,7 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
// don't get whole string from resource and sub in
// values because it'll be doing a MessageFormat for
// each update.
- header.setText(downloading+" "+downloadName+": "+percent+"% "+complete+".");
+ header.setText(downloading + " " + downloadName + ": " + percent + "% " + complete + ".");
}
/**
@@ -259,8 +255,6 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
};
-
-
/**
* A progress bar with the URL next to it.
*/
@@ -271,10 +265,10 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
private long readSoFar;
ProgressPanel(URL url, String version) {
- JLabel location = new JLabel(" "+url.getHost()+"/"+url.getFile());
+ JLabel location = new JLabel(" " + url.getHost() + "/" + url.getFile());
- bar.setMinimumSize(new Dimension(80,15));
- bar.setPreferredSize(new Dimension(80,15));
+ bar.setMinimumSize(new Dimension(80, 15));
+ bar.setPreferredSize(new Dimension(80, 15));
bar.setOpaque(false);
setLayout(new GridBagLayout());
@@ -308,15 +302,14 @@ public class DefaultDownloadIndicator implements DownloadIndicator {
if (readSoFar <= 0 || total <= 0) {
// make barber pole
- }
- else {
- double progress = (double)readSoFar / (double)total;
- int divide = (int)(w * progress);
+ } else {
+ double progress = (double) readSoFar / (double) total;
+ int divide = (int) (w * progress);
g.setColor(Color.white);
g.fillRect(x, y, w, h);
g.setColor(Color.blue);
- g.fillRect(x+1, y+1, divide-1, h-1);
+ g.fillRect(x + 1, y + 1, divide - 1, h - 1);
}
}
};
diff --git a/netx/net/sourceforge/jnlp/cache/DownloadIndicator.java b/netx/net/sourceforge/jnlp/cache/DownloadIndicator.java
index a6eecb8..7506392 100644
--- a/netx/net/sourceforge/jnlp/cache/DownloadIndicator.java
+++ b/netx/net/sourceforge/jnlp/cache/DownloadIndicator.java
@@ -14,7 +14,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
package net.sourceforge.jnlp.cache;
import java.awt.*;
diff --git a/netx/net/sourceforge/jnlp/cache/Resource.java b/netx/net/sourceforge/jnlp/cache/Resource.java
index 08a31fb..9818b64 100644
--- a/netx/net/sourceforge/jnlp/cache/Resource.java
+++ b/netx/net/sourceforge/jnlp/cache/Resource.java
@@ -14,7 +14,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
package net.sourceforge.jnlp.cache;
import java.io.*;
@@ -169,17 +168,26 @@ public class Resource {
private String getStatusString(int flag) {
StringBuffer result = new StringBuffer();
- if (flag == 0) result.append("<> ");
- if ((flag & CONNECT) != 0) result.append("CONNECT ");
- if ((flag & CONNECTING) != 0) result.append("CONNECTING ");
- if ((flag & CONNECTED) != 0) result.append("CONNECTED ");
- if ((flag & DOWNLOAD) != 0) result.append("DOWNLOAD ");
- if ((flag & DOWNLOADING) != 0) result.append("DOWNLOADING ");
- if ((flag & DOWNLOADED) != 0) result.append("DOWNLOADED ");
- if ((flag & ERROR) != 0) result.append("ERROR ");
- if ((flag & STARTED) != 0) result.append("STARTED ");
-
- return result.deleteCharAt(result.length()-1).toString();
+ if (flag == 0)
+ result.append("<> ");
+ if ((flag & CONNECT) != 0)
+ result.append("CONNECT ");
+ if ((flag & CONNECTING) != 0)
+ result.append("CONNECTING ");
+ if ((flag & CONNECTED) != 0)
+ result.append("CONNECTED ");
+ if ((flag & DOWNLOAD) != 0)
+ result.append("DOWNLOAD ");
+ if ((flag & DOWNLOADING) != 0)
+ result.append("DOWNLOADING ");
+ if ((flag & DOWNLOADED) != 0)
+ result.append("DOWNLOADED ");
+ if ((flag & ERROR) != 0)
+ result.append("ERROR ");
+ if ((flag & STARTED) != 0)
+ result.append("STARTED ");
+
+ return result.deleteCharAt(result.length() - 1).toString();
}
/**
@@ -190,7 +198,7 @@ public class Resource {
public void changeStatus(int clear, int add) {
int orig = 0;
- synchronized(this) {
+ synchronized (this) {
orig = status;
this.status &= ~clear;
@@ -199,12 +207,12 @@ public class Resource {
if (JNLPRuntime.isDebug())
if (status != orig) {
- System.out.print("Status: "+getStatusString(status));
+ System.out.print("Status: " + getStatusString(status));
if ((status & ~orig) != 0)
- System.out.print(" +("+getStatusString(status & ~orig)+")");
+ System.out.print(" +(" + getStatusString(status & ~orig) + ")");
if ((~status & orig) != 0)
- System.out.print(" -("+getStatusString(~status & orig)+")");
- System.out.println(" @ "+location.getPath());
+ System.out.print(" -(" + getStatusString(~status & orig) + ")");
+ System.out.println(" @ " + location.getPath());
}
}
@@ -245,7 +253,7 @@ public class Resource {
send = trackers.hardList();
}
- for (int i=0; i < send.size(); i++) {
+ for (int i = 0; i < send.size(); i++) {
ResourceTracker rt = send.get(i);
rt.fireDownloadEvent(this);
}
@@ -258,13 +266,13 @@ public class Resource {
// time spent in synchronized addResource determining if
// Resource is already in a tracker, and better for offline
// mode on some OS.
- return CacheUtil.urlEquals(location, ((Resource)other).location);
+ return CacheUtil.urlEquals(location, ((Resource) other).location);
}
return false;
}
public String toString() {
- return "location="+location.toString() + " state="+getStatusString(status);
+ return "location=" + location.toString() + " state=" + getStatusString(status);
}
}
diff --git a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
index e4d85b0..c21be39 100644
--- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
+++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
@@ -14,7 +14,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
package net.sourceforge.jnlp.cache;
import java.io.BufferedInputStream;
@@ -85,7 +84,6 @@ public class ResourceTracker {
// todo: might make a tracker be able to download more than one
// version of a resource, but probably not very useful.
-
// defines
// ResourceTracker.Downloader (download threads)
@@ -114,14 +112,14 @@ public class ResourceTracker {
/** weak list of resource trackers with resources to prefetch */
private static WeakList<ResourceTracker> prefetchTrackers =
- new WeakList<ResourceTracker>();
+ new WeakList<ResourceTracker>();
/** resources requested to be downloaded */
private static ArrayList<Resource> queue = new ArrayList<Resource>();
/** resource trackers threads are working for (used for load balancing across multi-tracker downloads) */
private static ArrayList<ResourceTracker> active =
- new ArrayList<ResourceTracker>(); //
+ new ArrayList<ResourceTracker>(); //
/** the resources known about by this resource tracker */
private List<Resource> resources = new ArrayList<Resource>();
@@ -132,7 +130,6 @@ public class ResourceTracker {
/** whether to download parts before requested */
private boolean prefetch;
-
/**
* Creates a resource tracker that does not prefetch resources.
*/
@@ -227,7 +224,7 @@ public class ResourceTracker {
// they will just 'pass through' the tracker as if they were
// never added (for example, not affecting the total download size).
synchronized (resource) {
- resource.changeStatus(0, DOWNLOADED|CONNECTED|STARTED);
+ resource.changeStatus(0, DOWNLOADED | CONNECTED | STARTED);
}
fireDownloadEvent(resource);
return true;
@@ -238,13 +235,13 @@ public class ResourceTracker {
if (entry.isCached() && !updatePolicy.shouldUpdate(entry)) {
if (JNLPRuntime.isDebug())
- System.out.println("not updating: "+resource.location);
+ System.out.println("not updating: " + resource.location);
synchronized (resource) {
resource.localFile = CacheUtil.getCacheFile(resource.location, resource.downloadVersion);
resource.size = resource.localFile.length();
resource.transferred = resource.localFile.length();
- resource.changeStatus(0, DOWNLOADED|CONNECTED|STARTED);
+ resource.changeStatus(0, DOWNLOADED | CONNECTED | STARTED);
}
fireDownloadEvent(resource);
return true;
@@ -304,8 +301,8 @@ public class ResourceTracker {
}
DownloadEvent event = new DownloadEvent(this, resource);
- for (int i=0; i < l.length; i++) {
- if (0 != ((ERROR|DOWNLOADED) & status))
+ for (int i = 0; i < l.length; i++) {
+ if (0 != ((ERROR | DOWNLOADED) & status))
l[i].downloadCompleted(event);
else if (0 != (DOWNLOADING & status))
l[i].downloadStarted(event);
@@ -333,8 +330,7 @@ public class ResourceTracker {
if (f != null)
// TODO: Should be toURI().toURL()
return f.toURL();
- }
- catch (MalformedURLException ex) {
+ } catch (MalformedURLException ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
}
@@ -358,7 +354,7 @@ public class ResourceTracker {
public File getCacheFile(URL location) {
try {
Resource resource = getResource(location);
- if (!resource.isSet(DOWNLOADED|ERROR))
+ if (!resource.isSet(DOWNLOADED | ERROR))
waitForResource(location, 0);
if (resource.isSet(ERROR))
@@ -374,8 +370,7 @@ public class ResourceTracker {
}
return null;
- }
- catch (InterruptedException ex) {
+ } catch (InterruptedException ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
@@ -398,15 +393,14 @@ public class ResourceTracker {
public InputStream getInputStream(URL location) throws IOException {
try {
Resource resource = getResource(location);
- if (!resource.isSet(DOWNLOADED|ERROR))
+ if (!resource.isSet(DOWNLOADED | ERROR))
waitForResource(location, 0);
if (resource.localFile != null)
return new FileInputStream(resource.localFile);
return resource.location.openStream();
- }
- catch (InterruptedException ex) {
+ } catch (InterruptedException ex) {
throw new IOException("wait was interrupted");
}
}
@@ -421,11 +415,11 @@ public class ResourceTracker {
* @throws IllegalArgumentException if the resource is not being tracked
*/
public boolean waitForResources(URL urls[], long timeout) throws InterruptedException {
- Resource resources[] = new Resource[ urls.length ];
+ Resource resources[] = new Resource[urls.length];
- synchronized(resources) {
+ synchronized (resources) {
// keep the lock so getResource doesn't have to aquire it each time
- for (int i=0; i < urls.length; i++)
+ for (int i = 0; i < urls.length; i++)
resources[i] = getResource(urls[i]);
}
@@ -469,7 +463,7 @@ public class ResourceTracker {
* @throws IllegalArgumentException if the resource is not being tracked
*/
public boolean checkResource(URL location) {
- return getResource(location).isSet(DOWNLOADED|ERROR); // isSet atomic
+ return getResource(location).isSet(DOWNLOADED | ERROR); // isSet atomic
}
/**
@@ -505,11 +499,11 @@ public class ResourceTracker {
enqueue = !resource.isSet(STARTED);
if (!resource.isSet(CONNECTED | CONNECTING))
- resource.changeStatus(0, CONNECT|STARTED);
+ resource.changeStatus(0, CONNECT | STARTED);
if (!resource.isSet(DOWNLOADED | DOWNLOADING))
- resource.changeStatus(0, DOWNLOAD|STARTED);
+ resource.changeStatus(0, DOWNLOAD | STARTED);
- if (!resource.isSet(DOWNLOAD|CONNECT))
+ if (!resource.isSet(DOWNLOAD | CONNECT))
enqueue = false;
}
@@ -580,8 +574,8 @@ public class ResourceTracker {
*/
private void queueResource(Resource resource) {
synchronized (lock) {
- if (!resource.isSet(CONNECT|DOWNLOAD))
- throw new IllegalArgumentException("Invalid resource state (resource: "+resource+")");
+ if (!resource.isSet(CONNECT | DOWNLOAD))
+ throw new IllegalArgumentException("Invalid resource state (resource: " + resource + ")");
queue.add(resource);
startThread();
@@ -668,7 +662,7 @@ public class ResourceTracker {
// explicitly close the URLConnection.
if (con instanceof HttpURLConnection)
- ((HttpURLConnection)con).disconnect();
+ ((HttpURLConnection) con).disconnect();
/*
* If the file was compressed, uncompress it.
@@ -709,17 +703,16 @@ public class ResourceTracker {
}
resource.changeStatus(DOWNLOADING, DOWNLOADED);
- synchronized(lock) {
+ synchronized (lock) {
lock.notifyAll(); // wake up wait's to check for completion
}
resource.fireDownloadEvent(); // fire DOWNLOADED
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
resource.changeStatus(0, ERROR);
- synchronized(lock) {
+ synchronized (lock) {
lock.notifyAll(); // wake up wait's to check for completion
}
resource.fireDownloadEvent(); // fire ERROR
@@ -743,15 +736,15 @@ public class ResourceTracker {
int size = connection.getContentLength();
boolean current = CacheUtil.isCurrent(resource.location, resource.requestVersion, connection) && resource.getUpdatePolicy() != UpdatePolicy.FORCE;
- synchronized(resource) {
+ synchronized (resource) {
resource.localFile = localFile;
// resource.connection = connection;
resource.size = size;
- resource.changeStatus(CONNECT|CONNECTING, CONNECTED);
+ resource.changeStatus(CONNECT | CONNECTING, CONNECTED);
// check if up-to-date; if so set as downloaded
if (current)
- resource.changeStatus(DOWNLOAD|DOWNLOADING, DOWNLOADED);
+ resource.changeStatus(DOWNLOAD | DOWNLOADING, DOWNLOADED);
}
// update cache entry
@@ -762,21 +755,20 @@ public class ResourceTracker {
entry.setLastUpdated(System.currentTimeMillis());
entry.store();
- synchronized(lock) {
+ synchronized (lock) {
lock.notifyAll(); // wake up wait's to check for completion
}
resource.fireDownloadEvent(); // fire CONNECTED
// explicitly close the URLConnection.
- if (connection instanceof HttpURLConnection)
- ((HttpURLConnection)connection).disconnect();
- }
- catch (Exception ex) {
+ if (connection instanceof HttpURLConnection)
+ ((HttpURLConnection) connection).disconnect();
+ } catch (Exception ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
resource.changeStatus(0, ERROR);
- synchronized(lock) {
+ synchronized (lock) {
lock.notifyAll(); // wake up wait's to check for completion
}
resource.fireDownloadEvent(); // fire ERROR
@@ -807,7 +799,6 @@ public class ResourceTracker {
return versionedURL;
}
-
/**
* Pick the next resource to download or initialize. If there
* are no more resources requested then one is taken from a
@@ -826,7 +817,7 @@ public class ResourceTracker {
// pick from queue
result = selectByFlag(queue, CONNECT, ERROR); // connect but not error
if (result == null)
- result = selectByFlag(queue, DOWNLOAD, ERROR|CONNECT|CONNECTING);
+ result = selectByFlag(queue, DOWNLOAD, ERROR | CONNECT | CONNECTING);
// remove from queue if found
if (result != null)
@@ -842,8 +833,7 @@ public class ResourceTracker {
synchronized (result) {
if (result.isSet(CONNECT)) {
result.changeStatus(CONNECT, CONNECTING);
- }
- else if (result.isSet(DOWNLOAD)) {
+ } else if (result.isSet(DOWNLOAD)) {
// only download if *not* connecting, when done connecting
// select next will pick up the download part. This makes
// all requested connects happen before any downloads, so
@@ -867,7 +857,7 @@ public class ResourceTracker {
// first find one to initialize
synchronized (prefetchTrackers) {
- for (int i=0; i < prefetchTrackers.size() && result == null; i++) {
+ for (int i = 0; i < prefetchTrackers.size() && result == null; i++) {
ResourceTracker tracker = prefetchTrackers.get(i);
if (tracker == null)
continue;
@@ -876,7 +866,7 @@ public class ResourceTracker {
result = selectByFlag(tracker.resources, UNINITIALIZED, ERROR);
if (result == null && alternate == null)
- alternate = selectByFlag(tracker.resources, CONNECTED, ERROR|DOWNLOADED|DOWNLOADING|DOWNLOAD);
+ alternate = selectByFlag(tracker.resources, CONNECTED, ERROR | DOWNLOADED | DOWNLOADING | DOWNLOAD);
}
}
}
@@ -915,7 +905,7 @@ public class ResourceTracker {
Resource result = null;
int score = Integer.MAX_VALUE;
- for (int i=0; i < source.size(); i++) {
+ for (int i = 0; i < source.size(); i++) {
Resource resource = source.get(i);
boolean selectable = false;
@@ -927,7 +917,7 @@ public class ResourceTracker {
if (selectable) {
int activeCount = 0;
- for (int j=0; j < active.size(); j++)
+ for (int j = 0; j < active.size(); j++)
if (active.get(j) == resource.getTracker())
activeCount++;
@@ -950,7 +940,7 @@ public class ResourceTracker {
*/
private Resource getResource(URL location) {
synchronized (resources) {
- for (int i=0; i < resources.size(); i++) {
+ for (int i = 0; i < resources.size(); i++) {
Resource resource = resources.get(i);
if (CacheUtil.urlEquals(resource.location, location))
@@ -974,7 +964,7 @@ public class ResourceTracker {
long startTime = System.currentTimeMillis();
// start them downloading / connecting in background
- for (int i=0; i < resources.length; i++)
+ for (int i = 0; i < resources.length; i++)
startResource(resources[i]);
// wait for completion
@@ -983,9 +973,9 @@ public class ResourceTracker {
synchronized (lock) {
// check for completion
- for (int i=0; i < resources.length; i++) {
- //NetX Deadlocking may be solved by removing this
- //synch block.
+ for (int i = 0; i < resources.length; i++) {
+ //NetX Deadlocking may be solved by removing this
+ //synch block.
synchronized (resources[i]) {
if (!resources[i].isSet(DOWNLOADED | ERROR)) {
finished = false;
@@ -1000,7 +990,7 @@ public class ResourceTracker {
long waitTime = 0;
if (timeout > 0) {
- waitTime = timeout - (System.currentTimeMillis()-startTime);
+ waitTime = timeout - (System.currentTimeMillis() - startTime);
if (waitTime <= 0)
return false;
}
@@ -1010,7 +1000,6 @@ public class ResourceTracker {
}
}
-
// inner classes
/**
@@ -1039,8 +1028,7 @@ public class ResourceTracker {
try {
processResource(resource);
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
if (JNLPRuntime.isDebug())
ex.printStackTrace();
}
diff --git a/netx/net/sourceforge/jnlp/cache/UpdatePolicy.java b/netx/net/sourceforge/jnlp/cache/UpdatePolicy.java
index 157e38c..8c069f6 100644
--- a/netx/net/sourceforge/jnlp/cache/UpdatePolicy.java
+++ b/netx/net/sourceforge/jnlp/cache/UpdatePolicy.java
@@ -14,7 +14,6 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
package net.sourceforge.jnlp.cache;
import java.io.*;
@@ -27,6 +26,7 @@ import javax.jnlp.*;
import net.sourceforge.jnlp.*;
import net.sourceforge.jnlp.runtime.*;
import net.sourceforge.jnlp.util.*;
+
/**
* A policy that determines when a resource should be checked for
* an updated version.<p>
@@ -52,7 +52,6 @@ public class UpdatePolicy {
private long timeDiff = -1;
-
/**
* Create a new update policy; this policy always updates the
* entry unless the shouldUpdate method is overridden.