Author: j16sdiz
Date: 2008-08-17 11:35:49 +0000 (Sun, 17 Aug 2008)
New Revision: 21953
Added:
branches/saltedhashstore/freenet/test/freenet/support/io/
branches/saltedhashstore/freenet/test/freenet/support/io/LineReadingInputStreamTest.java
Removed:
branches/saltedhashstore/freenet/src/freenet/crypt/DigestFactory.java
branches/saltedhashstore/freenet/src/freenet/crypt/SHA1Factory.java
Modified:
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClient.java
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
branches/saltedhashstore/freenet/src/freenet/clients/http/StatisticsToadlet.java
branches/saltedhashstore/freenet/src/freenet/clients/http/Toadlet.java
branches/saltedhashstore/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
branches/saltedhashstore/freenet/src/freenet/io/NetworkInterface.java
branches/saltedhashstore/freenet/src/freenet/io/comm/UdpSocketHandler.java
branches/saltedhashstore/freenet/src/freenet/l10n/L10n.java
branches/saltedhashstore/freenet/src/freenet/node/FailureTable.java
branches/saltedhashstore/freenet/src/freenet/node/GlobalProbe.java
branches/saltedhashstore/freenet/src/freenet/node/NodeClientCore.java
branches/saltedhashstore/freenet/src/freenet/node/NodeCrypto.java
branches/saltedhashstore/freenet/src/freenet/node/NodeInitException.java
branches/saltedhashstore/freenet/src/freenet/node/PeerNode.java
branches/saltedhashstore/freenet/src/freenet/node/Version.java
branches/saltedhashstore/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
branches/saltedhashstore/freenet/src/freenet/store/RAMFreenetStore.java
branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedList.java
branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedListImpl.java
branches/saltedhashstore/freenet/src/freenet/support/FileLoggerHook.java
branches/saltedhashstore/freenet/src/freenet/support/HTMLEncoder.java
branches/saltedhashstore/freenet/src/freenet/support/HTMLNode.java
branches/saltedhashstore/freenet/src/freenet/support/LRUHashtable.java
branches/saltedhashstore/freenet/src/freenet/support/OOMHandler.java
branches/saltedhashstore/freenet/src/freenet/support/SimpleFieldSet.java
branches/saltedhashstore/freenet/src/freenet/support/SortedLongSet.java
branches/saltedhashstore/freenet/src/freenet/support/WeakHashSet.java
branches/saltedhashstore/freenet/src/freenet/support/io/Closer.java
branches/saltedhashstore/freenet/src/freenet/support/io/LineReadingInputStream.java
branches/saltedhashstore/freenet/src/freenet/support/io/RandomAccessThing.java
branches/saltedhashstore/freenet/test/freenet/support/BufferTest.java
branches/saltedhashstore/freenet/test/freenet/support/ByteArrayWrapperTest.java
branches/saltedhashstore/freenet/test/freenet/support/MultiValueTableTest.java
Log:
Merge build 1156 (r21939) into saltedhashstore
Modified:
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClient.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClient.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClient.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -7,6 +7,8 @@
import java.util.Set;
import freenet.client.async.ClientCallback;
+import freenet.client.async.ClientGetter;
+import freenet.client.async.ClientPutter;
import freenet.client.events.ClientEventListener;
import freenet.keys.FreenetURI;
@@ -41,7 +43,7 @@
/**
* Non-blocking fetch of a URI with a configurable max-size, context
object, callback and context.
*/
- public void fetch(FreenetURI uri, long maxSize, Object context,
ClientCallback callback, FetchContext fctx) throws FetchException;
+ public ClientGetter fetch(FreenetURI uri, long maxSize, Object context,
ClientCallback callback, FetchContext fctx) throws FetchException;
/**
* Blocking insert.
@@ -53,7 +55,7 @@
/**
* Non-blocking insert.
*/
- public void insert(InsertBlock insert, boolean getCHKOnly, String
filenameHint, boolean isMetadata, InsertContext ctx, ClientCallback cb) throws
InsertException;
+ public ClientPutter insert(InsertBlock insert, boolean getCHKOnly,
String filenameHint, boolean isMetadata, InsertContext ctx, ClientCallback cb)
throws InsertException;
/**
* Blocking insert of a redirect.
Modified:
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/client/HighLevelSimpleClientImpl.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -136,10 +136,11 @@
return fw.waitForCompletion();
}
- public void fetch(FreenetURI uri, long maxSize, Object context,
ClientCallback callback, FetchContext fctx) throws FetchException {
+ public ClientGetter fetch(FreenetURI uri, long maxSize, Object context,
ClientCallback callback, FetchContext fctx) throws FetchException {
if(uri == null) throw new NullPointerException();
ClientGetter get = new ClientGetter(callback,
core.requestStarters.chkFetchScheduler, core.requestStarters.sskFetchScheduler,
uri, fctx, priorityClass, context, null, null);
get.start();
+ return get;
}
public FreenetURI insert(InsertBlock insert, boolean getCHKOnly, String
filenameHint) throws InsertException {
@@ -156,11 +157,12 @@
return pw.waitForCompletion();
}
- public void insert(InsertBlock insert, boolean getCHKOnly, String
filenameHint, boolean isMetadata, InsertContext ctx, ClientCallback cb) throws
InsertException {
+ public ClientPutter insert(InsertBlock insert, boolean getCHKOnly,
String filenameHint, boolean isMetadata, InsertContext ctx, ClientCallback cb)
throws InsertException {
ClientPutter put = new ClientPutter(cb, insert.getData(),
insert.desiredURI, insert.clientMetadata,
ctx, core.requestStarters.chkPutScheduler,
core.requestStarters.sskPutScheduler, priorityClass,
getCHKOnly, isMetadata, this, null,
filenameHint, false);
put.start(false);
+ return put;
}
public FreenetURI insertRedirect(FreenetURI insertURI, FreenetURI
targetURI) throws InsertException {
Modified:
branches/saltedhashstore/freenet/src/freenet/clients/http/StatisticsToadlet.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/clients/http/StatisticsToadlet.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/clients/http/StatisticsToadlet.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -1118,6 +1118,7 @@
strength = 1 - ((double) age / MAX_CIRCLE_AGE_THRESHOLD
);
histogramIndex = (int)
(Math.floor(location.doubleValue() * HISTOGRAM_LENGTH));
histogram[histogramIndex]++;
+
nodeCircleInfoboxContent.addChild("span", new String[]
{ "style", "class" }, new String[] {
generatePeerCircleStyleString(location.doubleValue(), false, strength),
"connected" }, "x");
}
nodeCircleInfoboxContent.addChild("span", new String[] {
"style", "class" }, new String[] { generatePeerCircleStyleString(myLocation,
true, 1.0), "me" }, "x");
@@ -1127,9 +1128,10 @@
nodeHistogramLegendCell =
nodeHistogramLegendTableRow.addChild("td");
nodeHistogramGraphCell =
nodeHistogramGraphTableRow.addChild("td", "style", "height: 100px;");
nodeHistogramLegendCell.addChild("div", "class",
"histogramLabel").addChild("#", fix1p1.format(((double) i) / HISTOGRAM_LENGTH
));
- //
histogramPercent = ((double) histogram[ i ] ) /
nodeCount;
- nodeHistogramGraphCell.addChild("div", new String[] {
"class", "style" }, new String[] { "histogramConnected", "height: " +
fix3pctUS.format(histogramPercent) + "; width: 100%;" }, "\u00a0");
+
+ // Don't use HTMLNode here to speed things up
+ nodeHistogramGraphCell.addChild("%", "<div
class=\"histogramConnected\" style=\"height: " +
fix3pctUS.format(histogramPercent) + "; width: 100%;\">\u00a0</div>");
}
}
Modified: branches/saltedhashstore/freenet/src/freenet/clients/http/Toadlet.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/clients/http/Toadlet.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/clients/http/Toadlet.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -82,7 +82,7 @@
MultiValueTable hdrtbl = new MultiValueTable();
hdrtbl.put("Allow", this.supportedMethods());
- StringBuffer pageBuffer = new StringBuffer();
+ StringBuilder pageBuffer = new StringBuilder();
pageNode.generate(pageBuffer);
toadletContext.sendReplyHeaders(405, "Operation not Supported",
hdrtbl, "text/html; charset=utf-8", pageBuffer.length());
toadletContext.writeData(pageBuffer.toString().getBytes("UTF-8"));
Modified:
branches/saltedhashstore/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
2008-08-17 11:35:49 UTC (rev 21953)
@@ -7,19 +7,19 @@
BookmarkCategory0.Content.Bookmark0.Name=The Ultimate FreeNet Index
BookmarkCategory0.Content.Bookmark0.Description=A new one-page index with a
menu including categories
BookmarkCategory0.Content.Bookmark0.hasAnActivelink=true
-BookmarkCategory0.Content.Bookmark0.URI=USK at
0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/Ultimate-Freenet-Index/25/
+BookmarkCategory0.Content.Bookmark0.URI=USK at
0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/Ultimate-Freenet-Index/28/
BookmarkCategory0.Content.Bookmark3.Name=Index des sites Fran?ais
BookmarkCategory0.Content.Bookmark3.Description=A small French index with
descriptions
BookmarkCategory0.Content.Bookmark3.hasAnActivelink=true
-BookmarkCategory0.Content.Bookmark3.URI=USK at
RJnh1EnvOSPwOWVRS2nyhC4eIQkKoNE5hcTv7~yY-sM,pOloLxnKWM~AL24iDMHOAvTvCqMlB-p2BO9zK96TOZA,AQACAAE/index_fr/54/
+BookmarkCategory0.Content.Bookmark3.URI=USK at
RJnh1EnvOSPwOWVRS2nyhC4eIQkKoNE5hcTv7~yY-sM,pOloLxnKWM~AL24iDMHOAvTvCqMlB-p2BO9zK96TOZA,AQACAAE/index_fr/61/
BookmarkCategory0.Content.Bookmark2.Name=Freenet Activelink Index (SLOW:
graphical index, preloads all the sites, so takes *ages* to load)
BookmarkCategory0.Content.Bookmark2.hasAnActivelink=true
BookmarkCategory0.Content.Bookmark2.Description=A graphical freenet index
(this will take a long time to load as it preloads the sites)
-BookmarkCategory0.Content.Bookmark2.URI=USK at
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index/67/
+BookmarkCategory0.Content.Bookmark2.URI=USK at
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index/78/
BookmarkCategory0.Content.Bookmark1.Name=Freenet Activelink Index Text Version
(a quick-loading non-graphical index site, no porn)
BookmarkCategory0.Content.Bookmark1.hasAnActivelink=true
BookmarkCategory0.Content.Bookmark1.Description=Text version of the Activelink
Index
-BookmarkCategory0.Content.Bookmark1.URI=USK at
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index-text/30/
+BookmarkCategory0.Content.Bookmark1.URI=USK at
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index-text/39/
BookmarkCategory1.Name=Freenet devel's flogs
BookmarkCategory1.Content.BookmarkCategory=0
BookmarkCategory1.Content.Bookmark=5
@@ -34,7 +34,7 @@
BookmarkCategory1.Content.Bookmark2.Name=Bombe
BookmarkCategory1.Content.Bookmark2.Description=Bombe's flog
BookmarkCategory1.Content.Bookmark2.hasAnActivelink=true
-BookmarkCategory1.Content.Bookmark2.URI=USK at
e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/bombe/41/
+BookmarkCategory1.Content.Bookmark2.URI=USK at
e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/bombe/42/
BookmarkCategory1.Content.Bookmark1.Name=Nextgen$
BookmarkCategory1.Content.Bookmark1.Description=NextGen$' flog
BookmarkCategory1.Content.Bookmark1.hasAnActivelink=true
@@ -49,7 +49,7 @@
BookmarkCategory2.Content.Bookmark0.Name=Freenet Message System
BookmarkCategory2.Content.Bookmark0.Description=The official freesite of FMS,
a spam resistant message board system for Freenet
BookmarkCategory2.Content.Bookmark0.hasAnActivelink=true
-BookmarkCategory2.Content.Bookmark0.URI=USK at
0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/62/
+BookmarkCategory2.Content.Bookmark0.URI=USK at
0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/78/
BookmarkCategory2.Content.Bookmark1.Name=Freemail
BookmarkCategory2.Content.Bookmark1.Description=The official site for Freemail
- email over Freenet
BookmarkCategory2.Content.Bookmark1.hasAnActivelink=true
Deleted: branches/saltedhashstore/freenet/src/freenet/crypt/DigestFactory.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/crypt/DigestFactory.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/crypt/DigestFactory.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -1,15 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.crypt;
-
-/*
- * @deprecated Digests should be able to reinitialize themselves instead
- * Re-precated since I need to create many digests at the same time for the
- * serial hash.
- **/
-public interface DigestFactory {
-
- public Digest getInstance();
-
-}
Deleted: branches/saltedhashstore/freenet/src/freenet/crypt/SHA1Factory.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/crypt/SHA1Factory.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/crypt/SHA1Factory.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -1,12 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.crypt;
-
-public class SHA1Factory implements DigestFactory {
-
- public Digest getInstance() {
- return SHA1.getInstance();
- }
-
-}
Modified: branches/saltedhashstore/freenet/src/freenet/io/NetworkInterface.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/io/NetworkInterface.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/io/NetworkInterface.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -16,6 +16,7 @@
package freenet.io;
+import java.io.Closeable;
import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
@@ -40,7 +41,7 @@
* @author David Roden <droden at gmail.com>
* @version $Id$
*/
-public class NetworkInterface {
+public class NetworkInterface implements Closeable {
public static final String DEFAULT_BIND_TO =
"127.0.0.1,0:0:0:0:0:0:0:1";
Modified:
branches/saltedhashstore/freenet/src/freenet/io/comm/UdpSocketHandler.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/io/comm/UdpSocketHandler.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/io/comm/UdpSocketHandler.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -159,7 +159,6 @@
private void realRun(DatagramPacket packet) {
// Single receiving thread
- logDEBUG = Logger.shouldLog(Logger.MINOR, this);
boolean gotPacket = getPacket(packet);
long now = System.currentTimeMillis();
if (gotPacket) {
Modified: branches/saltedhashstore/freenet/src/freenet/l10n/L10n.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/l10n/L10n.java 2008-08-17
10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/l10n/L10n.java 2008-08-17
11:35:49 UTC (rev 21953)
@@ -290,7 +290,7 @@
private static String quoteReplacement(String s) {
if ((s.indexOf('\\') == -1) && (s.indexOf('$') == -1))
return s;
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for (int i=0; i<s.length(); i++) {
char c = s.charAt(i);
if (c == '\\') {
Modified: branches/saltedhashstore/freenet/src/freenet/node/FailureTable.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/FailureTable.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/node/FailureTable.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -98,12 +98,9 @@
FailureTableEntry entry;
synchronized(this) {
entry = (FailureTableEntry) entriesByKey.get(key);
- if(entry == null) {
+ if(entry == null)
entry = new FailureTableEntry(key);
- entriesByKey.push(key, entry);
- } else {
- entriesByKey.push(key, entry);
- }
+ entriesByKey.push(key, entry);
trimEntries(now);
}
entry.failedTo(routedTo, timeout, now, htl);
@@ -115,12 +112,10 @@
FailureTableEntry entry;
synchronized(this) {
entry = (FailureTableEntry) entriesByKey.get(key);
- if(entry == null) {
+ if(entry == null)
entry = new FailureTableEntry(key);
- entriesByKey.push(key, entry);
- } else {
- entriesByKey.push(key, entry);
- }
+ entriesByKey.push(key, entry);
+
trimEntries(now);
}
if(routedTo != null)
Modified: branches/saltedhashstore/freenet/src/freenet/node/GlobalProbe.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/GlobalProbe.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/node/GlobalProbe.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -11,13 +11,13 @@
double lastLocation = 0.0;
long lastTime;
int lastHops;
- boolean doneSomething = false;
+ private boolean doneSomething = false;
final ProbeCallback cb;
final Node node;
int ctr;
final int probeType;
- GlobalProbe(Node n, int probeType) {
+ public GlobalProbe(Node n, int probeType) {
this.node = n;
this.probeType = probeType;
cb = new ProbeCallback() {
@@ -100,13 +100,11 @@
private void output(double loc, int hops) {
double estimatedNodes = ((double) (ctr+1)) / loc;
Logger.error(this, "LOCATION "+ctr+": " + loc+" - estimated
nodes: "+estimatedNodes+" ("+hops+" hops)");
- System.out.println("LOCATION "+ctr+": " + loc+" - estimated
nodes: "+estimatedNodes+" ("+hops+" hops)");
+ System.err.println("LOCATION "+ctr+": " + loc+" - estimated
nodes: "+estimatedNodes+" ("+hops+" hops)");
}
private void error(String string) {
Logger.error(this, string);
- System.out.println("GlobalProbe error: "+string);
+ System.err.println("GlobalProbe error: "+string);
}
-
-
}
Modified: branches/saltedhashstore/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/NodeClientCore.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/node/NodeClientCore.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -209,7 +209,7 @@
throw new
NodeInitException(NodeInitException.EXIT_BAD_TEMP_DIR, msg);
}
- nodeConfig.register("maxRAMBucketSize", "128KiB", sortOrder++,
true, false, "NodeClientCore.maxRAMBucketSize",
"NodeClientCore.maxRAMBucketSizeLong", new LongCallback() {
+ nodeConfig.register("maxRAMBucketSize", "32KiB", sortOrder++,
true, false, "NodeClientCore.maxRAMBucketSize",
"NodeClientCore.maxRAMBucketSizeLong", new LongCallback() {
public Long get() {
return (tempBucketFactory == null ? 0 :
tempBucketFactory.getMaxRAMBucketSize());
Modified: branches/saltedhashstore/freenet/src/freenet/node/NodeCrypto.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/NodeCrypto.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/node/NodeCrypto.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -352,9 +352,8 @@
BigInteger m = new BigInteger(1, SHA256.digest(ref));
if(logMINOR) Logger.minor(this, "m = "+m.toString(16));
DSASignature _signature = DSA.sign(cryptoGroup,
privKey, m, random);
- // FIXME remove this ... eventually
- if(!DSA.verify(pubKey, _signature, m, false))
- Logger.error(this, "Signature failed!");
+ if(logMINOR && !DSA.verify(pubKey, _signature, m,
false))
+ throw new
NodeInitException(NodeInitException.EXIT_EXCEPTION_TO_DEBUG, mySignedReference);
return _signature;
} catch(UnsupportedEncodingException e){
//duh ?
Modified:
branches/saltedhashstore/freenet/src/freenet/node/NodeInitException.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/NodeInitException.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/node/NodeInitException.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -36,6 +36,7 @@
public static final int EXIT_STORE_FILE_NOT_FOUND = 1;
public static final int EXIT_NODE_UPPER_LIMIT = 1024;
public static final int EXIT_BROKE_WRAPPER_CONF = 28;
+ public static final int EXIT_EXCEPTION_TO_DEBUG = 1023;
private static final long serialVersionUID = -1;
NodeInitException(int exitCode, String msg) {
Modified: branches/saltedhashstore/freenet/src/freenet/node/PeerNode.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/PeerNode.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/node/PeerNode.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -988,7 +988,6 @@
* PeerManager in e.g. verified.
*/
public boolean isRoutable() {
- //FIXME: isConnected() is redundant if 'isRoutable', right? ...
currentLocation>1.0 is impossible.
return isConnected() && isRoutingCompatible() &&
!(currentLocation < 0.0 || currentLocation > 1.0);
}
@@ -3984,8 +3983,9 @@
}
public SortedSet<Long> getNumberOfSelections() {
+ // FIXME: returning a copy is not an option: find a smarter way
of dealing with the synchronization
synchronized(numberOfSelectionsSync) {
- return new TreeSet<Long>(numberOfSelections);
+ return numberOfSelections;
}
}
Modified: branches/saltedhashstore/freenet/src/freenet/node/Version.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/node/Version.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/node/Version.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -24,7 +24,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 1155;
+ private static final int buildNumber = 1156;
/** Oldest build of Fred we will talk to */
private static final int oldLastGoodBuild = 1154;
Modified:
branches/saltedhashstore/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/node/fcp/FCPConnectionHandler.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -1,6 +1,7 @@
package freenet.node.fcp;
import java.io.BufferedOutputStream;
+import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -16,7 +17,7 @@
import freenet.support.io.Closer;
import freenet.support.io.FileUtil;
-public class FCPConnectionHandler {
+public class FCPConnectionHandler implements Closeable {
private static final class DirectoryAccess {
final boolean canWrite;
final boolean canRead;
Modified:
branches/saltedhashstore/freenet/src/freenet/store/RAMFreenetStore.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/store/RAMFreenetStore.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/store/RAMFreenetStore.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -17,7 +17,7 @@
byte[] fullKey;
}
- private final LRUHashtable blocksByRoutingKey;
+ private final LRUHashtable<ByteArrayWrapper, Block> blocksByRoutingKey;
private final StoreCallback callback;
@@ -29,7 +29,7 @@
public RAMFreenetStore(StoreCallback callback, int maxKeys) {
this.callback = callback;
- this.blocksByRoutingKey = new LRUHashtable();
+ this.blocksByRoutingKey = new LRUHashtable<ByteArrayWrapper,
Block>();
this.maxKeys = maxKeys;
callback.setStore(this);
}
@@ -37,7 +37,7 @@
public synchronized StorableBlock fetch(byte[] routingKey, byte[]
fullKey,
boolean dontPromote) throws IOException {
ByteArrayWrapper key = new ByteArrayWrapper(routingKey);
- Block block = (Block) blocksByRoutingKey.get(key);
+ Block block = blocksByRoutingKey.get(key);
if(block == null) {
misses++;
return null;
@@ -77,7 +77,7 @@
KeyCollisionException {
writes++;
ByteArrayWrapper key = new ByteArrayWrapper(routingkey);
- Block oldBlock = (Block) blocksByRoutingKey.get(key);
+ Block oldBlock = blocksByRoutingKey.get(key);
boolean storeFullKeys = callback.storeFullKeys();
if(oldBlock != null) {
if(callback.collisionPossible()) {
Modified:
branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedList.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedList.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedList.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -6,36 +6,36 @@
* Framework for managing a doubly linked list.
* @author tavin
*/
-public interface DoublyLinkedList {
- public abstract Object clone();
+public interface DoublyLinkedList<T> {
+ public abstract DoublyLinkedList<T> clone();
/**
* List element
*/
- public interface Item {
+ public interface Item<T> {
/**
* Get next {@link Item}. May or may not return
* <code>null</code> if this is the last <code>Item</code>.
*
* @see DoublyLinkedList#hasNext()
*/
- Item getNext();
+ DoublyLinkedList.Item<T> getNext();
/** Set next {@link Item} */
- Item setNext(Item i);
+ DoublyLinkedList.Item<T> setNext(DoublyLinkedList.Item<T> i);
/**
* Get previous {@link Item}. May or may not return <code>null</code>
* if this is the first <code>Item</code>.
*
* @see DoublyLinkedList#hasNext()
*/
- Item getPrev();
+ Item<T> getPrev();
/** Get previous {@link Item} */
- Item setPrev(Item i);
+ Item<T> setPrev(DoublyLinkedList.Item<T> i);
/** Return the contained list. <strong>For sanity checking
only.</strong> */
- DoublyLinkedList getParent();
+ DoublyLinkedList<T> getParent();
/** Set the contained list. <strong>For sanity checking
only.</strong>*/
- DoublyLinkedList setParent(DoublyLinkedList l);
+ DoublyLinkedList<T> setParent(DoublyLinkedList<T> l);
}
/** Clear this list */
@@ -61,11 +61,11 @@
/**
* Puts the item before the first item.
*/
- void unshift(Item i);
+ void unshift(DoublyLinkedList.Item<T> i);
/**
* Put all items in the specified list before the first item.
*/
- void unshift(DoublyLinkedList l);
+ void unshift(DoublyLinkedList<T> l);
/**
* Removes and returns the first item.
*/
@@ -73,16 +73,16 @@
/**
* Remove <tt>n</tt> elements from head and return them as a
<code>DoublyLinkedList</code>.
*/
- DoublyLinkedList shift(int n);
+ DoublyLinkedList<T> shift(int n);
/**
* Puts the item after the last item.
*/
- void push(Item i);
+ void push(DoublyLinkedList.Item<T> i);
/**
* Puts all items in the specified list after the last item.
*/
- void push(DoublyLinkedList l);
+ void push(DoublyLinkedList<T> l);
/**
* Removes and returns the last item.
*/
@@ -93,34 +93,34 @@
DoublyLinkedList pop(int n);
/** @return <code>true</code> if <code>i</code> has next item. (ie. not
the last item); <code>false</code> otherwise */
- boolean hasNext(Item i);
+ boolean hasNext(DoublyLinkedList.Item<T> i);
/** @return <code>true</code> if <code>i</code> has previous item. (ie.
not the first item); <code>false</code> otherwise */
- boolean hasPrev(Item i);
+ boolean hasPrev(DoublyLinkedList.Item<T> i);
/** @return next item of <code>i</code>. If this is the last element,
return <code>null</code> */
- Item next(Item i);
+ Item next(DoublyLinkedList.Item<T> i);
/** @return previous item of <code>i</code>. If this is the first element,
return <code>null</code> */
- Item prev(Item i);
+ Item prev(DoublyLinkedList.Item<T> i);
/** Remove and return a element
* @return this item, or <code>null</code> if the item was not in the list
*/
- Item remove(Item i);
+ Item remove(DoublyLinkedList.Item<T> i);
/**
* Inserts item <code>j</code> before item <code>i</code>.
*/
- void insertPrev(Item i, Item j);
+ void insertPrev(DoublyLinkedList.Item<T> i, DoublyLinkedList.Item<T> j);
/**
* Inserts the entire {@link DoublyLinkedList} <code>l</code> before item
<code>i</code>.
*/
- void insertPrev(Item i, DoublyLinkedList l);
+ void insertPrev(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l);
/**
* Inserts item <code>j</code> after item <code>i</code.
*/
- void insertNext(Item i, Item j);
+ void insertNext(DoublyLinkedList.Item<T> i, DoublyLinkedList.Item<T> j);
/**
* Inserts the entire {@link DoublyLinkedList} <code>l</code> after item
<code>i</code>.
*/
- void insertNext(Item i, DoublyLinkedList l);
+ void insertNext(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l);
}
Modified:
branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedListImpl.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedListImpl.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/support/DoublyLinkedListImpl.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -10,27 +10,28 @@
* TODO: there are still some unimplemented methods
* -- it remains to be seen if they are needed at all
*/
-public class DoublyLinkedListImpl implements DoublyLinkedList {
+public class DoublyLinkedListImpl<T> implements DoublyLinkedList<T>{
protected int size;
- protected Item _headptr, _tailptr;
+ protected DoublyLinkedListImpl.Item<T> _headptr, _tailptr;
- public final Object clone() {
- return new DoublyLinkedListImpl(this);
+ @Override
+ public final DoublyLinkedListImpl<T> clone() {
+ return new DoublyLinkedListImpl<T>(this);
}
/**
* A new list with no items.
*/
public DoublyLinkedListImpl() {
- _headptr = new Item();
- _tailptr = new Item();
+ _headptr = new Item<T>();
+ _tailptr = new Item<T>();
_headptr.setParent(this);
_tailptr.setParent(this);
clear();
}
- protected DoublyLinkedListImpl(Item _h, Item _t, int size) {
+ protected DoublyLinkedListImpl(DoublyLinkedListImpl.Item<T> _h,
DoublyLinkedListImpl.Item<T> _t, int size) {
_headptr = _h;
_tailptr = _t;
_headptr.setParent(this);
@@ -44,11 +45,11 @@
*/
protected DoublyLinkedListImpl(DoublyLinkedListImpl impl) {
this();
- Enumeration e = impl.forwardElements();
+ Enumeration<DoublyLinkedListImpl.Item<T>> e = impl.forwardElements();
boolean checked = false;
for(;e.hasMoreElements();) {
- Item oi = (Item)e.nextElement();
- Item i = (Item) oi.clone();
+ DoublyLinkedListImpl.Item<T> oi = e.nextElement();
+ DoublyLinkedList.Item<T> i = oi.clone();
if(!checked) {
checked = true;
if(!i.getClass().getName().equals(oi.getClass().getName())) {
@@ -69,8 +70,8 @@
// Help to detect removal after clear().
// The check in remove() is enough, strictly,
// as long as people don't add elements afterwards.
- DoublyLinkedList.Item pos = _headptr.next;
- DoublyLinkedList.Item opos = _headptr;
+ DoublyLinkedList.Item<T> pos = _headptr.next;
+ DoublyLinkedList.Item<T> opos = _headptr;
while(true) {
if(pos == _tailptr) break;
if(pos == null) break;
@@ -103,21 +104,21 @@
* {@inheritDoc}
* @see #forwardElements()
*/
- public final Enumeration elements() {
+ public final Enumeration<DoublyLinkedList.Item<T>> elements() {
return forwardElements();
}
/**
* {@inheritDoc}
*/
- public final DoublyLinkedList.Item head() {
+ public final DoublyLinkedList.Item<T> head() {
return size == 0 ? null : _headptr.next;
}
/**
* {@inheritDoc}
*/
- public final DoublyLinkedList.Item tail() {
+ public final DoublyLinkedList.Item<T> tail() {
return size == 0 ? null : _tailptr.prev;
}
@@ -126,7 +127,7 @@
/**
* {@inheritDoc}
*/
- public final void unshift(DoublyLinkedList.Item i) {
+ public final void unshift(DoublyLinkedList.Item<T> i) {
insertNext(_headptr, i);
}
@@ -134,30 +135,30 @@
* {@inheritDoc}
* FIXME: unimplemented
*/
- public void unshift(DoublyLinkedList l) {
+ public void unshift(DoublyLinkedList<T> l) {
throw new RuntimeException("function currently unimplemented because i
am a lazy sod");
}
/**
* {@inheritDoc}
*/
- public final DoublyLinkedList.Item shift() {
+ public final DoublyLinkedList.Item<T> shift() {
return size == 0 ? null : remove(_headptr.next);
}
/**
* {@inheritDoc}
*/
- public DoublyLinkedList shift(int n) {
+ public DoublyLinkedList<T> shift(int n) {
if (n > size) n = size;
- if (n < 1) return new DoublyLinkedListImpl();
+ if (n < 1) return new DoublyLinkedListImpl<T>();
- DoublyLinkedList.Item i = _headptr;
+ DoublyLinkedList.Item<T> i = _headptr;
for (int m=0; m<n; ++m)
i = i.getNext();
- DoublyLinkedList.Item j = i.getNext();
- Item newheadptr = new Item();
- Item newtailptr = new Item();
+ DoublyLinkedList.Item<T> j = i.getNext();
+ Item<T> newheadptr = new Item<T>();
+ Item<T> newtailptr = new Item<T>();
j.setPrev(newheadptr);
newheadptr.setNext(j);
@@ -165,7 +166,7 @@
i.setNext(newtailptr);
newtailptr.setPrev(i);
- DoublyLinkedList newlist = new DoublyLinkedListImpl(_headptr,
newtailptr, n);
+ DoublyLinkedList<T> newlist = new DoublyLinkedListImpl<T>(_headptr,
newtailptr, n);
_headptr = newheadptr;
_headptr.setParent(this);
size -= n;
@@ -178,37 +179,37 @@
/**
* {@inheritDoc}
*/
- public final void push(DoublyLinkedList.Item i) {
+ public final void push(DoublyLinkedList.Item<T> i) {
insertPrev(_tailptr, i);
}
/**
* {@inheritDoc}
* FIXME: unimplemented
*/
- public void push(DoublyLinkedList l) {
+ public void push(DoublyLinkedList<T> l) {
throw new RuntimeException("function currently unimplemented because i
am a lazy sod");
}
/**
* {@inheritDoc}
*/
- public final DoublyLinkedList.Item pop() {
+ public final DoublyLinkedList.Item<T> pop() {
return size == 0 ? null : remove(_tailptr.prev);
}
/**
* {@inheritDoc}
*/
- public DoublyLinkedList pop(int n) {
+ public DoublyLinkedList<T> pop(int n) {
if (n > size) n = size;
- if (n < 1) return new DoublyLinkedListImpl();
+ if (n < 1) return new DoublyLinkedListImpl<T>();
- DoublyLinkedList.Item i = _tailptr;
+ DoublyLinkedList.Item<T> i = _tailptr;
for (int m=0; m<n; ++m)
i = i.getPrev();
- DoublyLinkedList.Item j = i.getPrev();
- Item newtailptr = new Item();
- Item newheadptr = new Item();
+ DoublyLinkedList.Item<T> j = i.getPrev();
+ DoublyLinkedListImpl.Item<T> newtailptr = new Item<T>();
+ DoublyLinkedListImpl.Item<T> newheadptr = new Item<T>();
j.setNext(newtailptr);
newtailptr.setPrev(j);
@@ -217,7 +218,7 @@
i.setPrev(newheadptr);
newheadptr.setNext(i);
- DoublyLinkedList newlist = new DoublyLinkedListImpl(newheadptr,
_tailptr, n);
+ DoublyLinkedList<T> newlist = new DoublyLinkedListImpl<T>(newheadptr,
_tailptr, n);
_tailptr = newtailptr;
size -= n;
@@ -229,29 +230,29 @@
/**
* {@inheritDoc}
*/
- public final boolean hasNext(DoublyLinkedList.Item i) {
- DoublyLinkedList.Item next = i.getNext();
+ public final boolean hasNext(DoublyLinkedList.Item<T> i) {
+ DoublyLinkedList.Item<T> next = i.getNext();
return (next != null) && (next != _tailptr);
}
/**
* {@inheritDoc}
*/
- public final boolean hasPrev(DoublyLinkedList.Item i) {
- DoublyLinkedList.Item prev = i.getPrev();
+ public final boolean hasPrev(DoublyLinkedList.Item<T> i) {
+ DoublyLinkedList.Item<T> prev = i.getPrev();
return (prev != null) && (prev != _headptr);
}
/**
* {@inheritDoc}
*/
- public final DoublyLinkedList.Item next(DoublyLinkedList.Item i) {
- DoublyLinkedList.Item next = i.getNext();
+ public final DoublyLinkedList.Item<T> next(DoublyLinkedList.Item<T> i) {
+ DoublyLinkedList.Item<T> next = i.getNext();
return next == _tailptr ? null : next;
}
/**
* {@inheritDoc}
*/
- public final DoublyLinkedList.Item prev(DoublyLinkedList.Item i) {
- DoublyLinkedList.Item prev = i.getPrev();
+ public final DoublyLinkedList.Item<T> prev(DoublyLinkedList.Item<T> i) {
+ DoublyLinkedList.Item<T> prev = i.getPrev();
return prev == _headptr ? null : prev;
}
@@ -261,7 +262,7 @@
/**
* {@inheritDoc}
*/
- public DoublyLinkedList.Item remove(DoublyLinkedList.Item i) {
+ public DoublyLinkedList.Item<T> remove(DoublyLinkedList.Item<T> i) {
if (i.getParent() == null) return null; // not in list
if(isEmpty()) {
Logger.error(this, "Illegal ERROR: Removing from an empty
list!!");
@@ -269,7 +270,7 @@
}
if (i.getParent() != this)
throw new PromiscuousItemException(i, i.getParent());
- DoublyLinkedList.Item next = i.getNext(), prev = i.getPrev();
+ DoublyLinkedList.Item<T> next = i.getNext(), prev = i.getPrev();
if ((next == null) && (prev == null)) return null; // not in the list
if ((next == null) || (prev == null))
throw new NullPointerException("next="+next+", prev="+prev); //
partially in the list?!
@@ -290,7 +291,7 @@
/**
* {@inheritDoc}
*/
- public void insertPrev(DoublyLinkedList.Item i, DoublyLinkedList.Item j) {
+ public void insertPrev(DoublyLinkedList.Item<T> i,
DoublyLinkedList.Item<T> j) {
if (i.getParent() == null)
throw new PromiscuousItemException(i, i.getParent()); //
different trace to make easier debugging
if (i.getParent() != this)
@@ -299,7 +300,7 @@
throw new PromiscuousItemException(j, j.getParent());
if ((j.getNext() != null) || (j.getPrev() != null))
throw new PromiscuousItemException(j);
- DoublyLinkedList.Item prev = i.getPrev();
+ DoublyLinkedList.Item<T> prev = i.getPrev();
if (prev == null)
throw new VirginItemException(i);
prev.setNext(j);
@@ -314,14 +315,14 @@
* {@inheritDoc}
* FIXME: unimplemented
*/
- public void insertPrev(DoublyLinkedList.Item i, DoublyLinkedList l) {
+ public void insertPrev(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l) {
throw new RuntimeException("function currently unimplemented because i
am a lazy sod");
}
/**
* {@inheritDoc}
*/
- public void insertNext(DoublyLinkedList.Item i, DoublyLinkedList.Item j) {
+ public void insertNext(DoublyLinkedList.Item<T> i,
DoublyLinkedList.Item<T> j) {
if (i.getParent() != this)
throw new PromiscuousItemException(i, i.getParent());
if (j.getParent() != null)
@@ -343,7 +344,7 @@
* {@inheritDoc}
* FIXME: unimplemented
*/
- public void insertNext(DoublyLinkedList.Item i, DoublyLinkedList l) {
+ public void insertNext(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l) {
throw new RuntimeException("function currently unimplemented because i
am a lazy sod");
}
@@ -353,54 +354,54 @@
/**
* @return an Enumeration of list elements from head to tail
*/
- private Enumeration forwardElements() {
+ private Enumeration<DoublyLinkedList.Item<T>> forwardElements() {
return new ForwardWalker();
}
/**
* @return an Enumeration of list elements from tail to head
*/
- protected Enumeration reverseElements() {
+ protected Enumeration<DoublyLinkedList.Item<T>> reverseElements() {
return new ReverseWalker();
}
- private class ForwardWalker implements Enumeration {
- protected DoublyLinkedList.Item next;
+ private class ForwardWalker<T extends DoublyLinkedListImpl.Item<T>>
implements Enumeration<DoublyLinkedList.Item<T>> {
+ protected DoublyLinkedList.Item<T> next;
protected ForwardWalker() {
next = _headptr.getNext();
}
- protected ForwardWalker(DoublyLinkedList.Item startAt,
+ protected ForwardWalker(DoublyLinkedList.Item<T> startAt,
boolean inclusive) {
next = (inclusive ? startAt : startAt.getNext());
}
public final boolean hasMoreElements() {
return next != _tailptr;
}
- public Object nextElement() {
+ public DoublyLinkedList.Item<T> nextElement() {
if (next == _tailptr)
throw new NoSuchElementException();
- DoublyLinkedList.Item result = next;
+ DoublyLinkedList.Item<T> result = next;
next = next.getNext();
return result;
}
}
- private class ReverseWalker implements Enumeration {
- protected DoublyLinkedList.Item next;
+ private class ReverseWalker<T extends DoublyLinkedList.Item<T>> implements
Enumeration<DoublyLinkedList.Item<T>> {
+ protected DoublyLinkedList.Item<T> next;
protected ReverseWalker() {
next = _tailptr.getPrev();
}
- protected ReverseWalker(DoublyLinkedList.Item startAt,
+ protected ReverseWalker(DoublyLinkedList.Item<T> startAt,
boolean inclusive) {
next = (inclusive ? startAt : startAt.getPrev());
}
public final boolean hasMoreElements() {
return next != _headptr;
}
- public Object nextElement() {
+ public DoublyLinkedList.Item<T> nextElement() {
if (next == _headptr)
throw new NoSuchElementException();
- DoublyLinkedList.Item result = next;
+ DoublyLinkedList.Item<T> result = next;
if(next == null) throw new IllegalStateException("next==null");
next = next.getPrev();
return result;
@@ -410,35 +411,36 @@
//=== list element ====================================================
- public static class Item implements DoublyLinkedList.Item {
- private DoublyLinkedList.Item prev;
- private DoublyLinkedList.Item next;
+ public static class Item<T> implements DoublyLinkedList.Item<T> {
+ private DoublyLinkedList.Item<T> prev;
+ private DoublyLinkedList.Item<T> next;
private DoublyLinkedList list;
- public Object clone() {
+ @Override
+ public DoublyLinkedList.Item<T> clone() {
if(getClass() != Item.class)
throw new RuntimeException("Must implement clone() for
"+getClass());
- return new Item();
+ return new Item<T>();
}
public final DoublyLinkedList.Item getNext() {
return next;
}
- public final DoublyLinkedList.Item setNext(DoublyLinkedList.Item i) {
- DoublyLinkedList.Item old = next;
+ public final DoublyLinkedList.Item setNext(DoublyLinkedList.Item<T> i)
{
+ DoublyLinkedList.Item<T> old = next;
next = i;
return old;
}
public final DoublyLinkedList.Item getPrev() {
return prev;
}
- public final DoublyLinkedList.Item setPrev(DoublyLinkedList.Item i) {
- DoublyLinkedList.Item old = prev;
+ public final DoublyLinkedList.Item setPrev(DoublyLinkedList.Item<T> i)
{
+ DoublyLinkedList.Item<T> old = prev;
prev = i;
return old;
}
public DoublyLinkedList getParent() {
return list;
}
- public DoublyLinkedList setParent(DoublyLinkedList l) {
+ public DoublyLinkedList setParent(DoublyLinkedList<T> l) {
DoublyLinkedList old = list;
list = l;
return old;
Modified:
branches/saltedhashstore/freenet/src/freenet/support/FileLoggerHook.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/FileLoggerHook.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/FileLoggerHook.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -1,6 +1,7 @@
package freenet.support;
import java.io.BufferedOutputStream;
+import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -32,7 +33,7 @@
*
* @author oskar
*/
-public class FileLoggerHook extends LoggerHook {
+public class FileLoggerHook extends LoggerHook implements Closeable {
/** Verbosity types */
public static final int DATE = 1,
Modified: branches/saltedhashstore/freenet/src/freenet/support/HTMLEncoder.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/HTMLEncoder.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/HTMLEncoder.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -18,16 +18,16 @@
public static String encode(String s) {
int n = s.length();
- StringBuffer sb = new StringBuffer(n);
+ StringBuilder sb = new StringBuilder(n);
encodeToBuffer(n, s, sb);
return sb.toString();
}
- public static void encodeToBuffer(String s, StringBuffer sb) {
+ public static void encodeToBuffer(String s, StringBuilder sb) {
encodeToBuffer(s.length(), s, sb);
}
- private static void encodeToBuffer(int n, String s, StringBuffer sb) {
+ private static void encodeToBuffer(int n, String s, StringBuilder sb) {
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
if(Character.isLetterOrDigit(c)){ //only special
characters need checking
@@ -48,7 +48,7 @@
private String[] strings;
private int modulo = 0;
- public CharTable(HashMap map){
+ public CharTable(HashMap<Character, String> map){
int[] keys = new int[map.size()];
int keyIndex = 0;
@@ -84,7 +84,7 @@
character = ((Character)it.next());
keyIndex = character.charValue()%modulo;
chars[keyIndex] = character.charValue();
- strings[keyIndex] = (String) map.get(character);
+ strings[keyIndex] = map.get(character);
}
if (chars[0] == 0 && strings[0] != null) chars[0] = 1;
}
Modified: branches/saltedhashstore/freenet/src/freenet/support/HTMLNode.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/HTMLNode.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/HTMLNode.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -19,9 +19,9 @@
private final String content;
- private final Map attributes = new HashMap();
+ private final Map<String, String> attributes = new HashMap<String,
String>();
- protected final List children = new ArrayList();
+ protected final List<HTMLNode> children = new ArrayList<HTMLNode>();
public HTMLNode(String name) {
this(name, null);
@@ -61,7 +61,7 @@
}
}
this.name = name.toLowerCase(Locale.ENGLISH);
- if (content != null && !name.equals("#") && !name.equals("%")) {
+ if (content != null && !("#").equals(name)&&
!("%").equals(name)) {
addChild(new HTMLNode("#", content));
this.content = null;
} else
@@ -83,12 +83,12 @@
attributes.put(attributeName, attributeValue);
}
- public Map getAttributes() {
+ public Map<String, String> getAttributes() {
return Collections.unmodifiableMap(attributes);
}
public String getAttribute(String attributeName) {
- return (String) attributes.get(attributeName);
+ return attributes.get(attributeName);
}
public HTMLNode addChild(HTMLNode childNode) {
@@ -142,11 +142,11 @@
* "real" tag could be found
*/
public String getFirstTag() {
- if (!name.equals("#")) {
+ if (!"#".equals(name)) {
return name;
}
for (int childIndex = 0, childCount = children.size();
childIndex < childCount; childIndex++) {
- HTMLNode childNode = (HTMLNode)
children.get(childIndex);
+ HTMLNode childNode = children.get(childIndex);
String tag = childNode.getFirstTag();
if (tag != null) {
return tag;
@@ -156,28 +156,29 @@
}
public String generate() {
- StringBuffer tagBuffer = new StringBuffer();
+ StringBuilder tagBuffer = new StringBuilder();
return generate(tagBuffer).toString();
}
- public StringBuffer generate(StringBuffer tagBuffer) {
- if (name.equals("#") && (content != null)) {
- HTMLEncoder.encodeToBuffer(content, tagBuffer);
+ public StringBuilder generate(StringBuilder tagBuffer) {
+ if("#".equals(name)) {
+ if(content != null) {
+ HTMLEncoder.encodeToBuffer(content, tagBuffer);
+ return tagBuffer;
+ }
+
+ for(int childIndex = 0, childCount = children.size();
childIndex < childCount; childIndex++) {
+ HTMLNode childNode = children.get(childIndex);
+ childNode.generate(tagBuffer);
+ }
return tagBuffer;
}
// Perhaps this should be something else, but since I don't
know if '#' was not just arbitrary chosen, I'll just pick '%'
// This allows non-encoded text to be appended to the tag buffer
- if (name.equals("%")) {
+ if ("%".equals(name)) {
tagBuffer.append(content);
return tagBuffer;
}
- if (name.equals("#")) {
- for (int childIndex = 0, childCount = children.size();
childIndex < childCount; childIndex++) {
- HTMLNode childNode = (HTMLNode)
children.get(childIndex);
- childNode.generate(tagBuffer);
- }
- return tagBuffer;
- }
tagBuffer.append('<').append(name);
Set attributeSet = attributes.entrySet();
for (Iterator attributeIterator = attributeSet.iterator();
attributeIterator.hasNext();) {
@@ -188,25 +189,25 @@
HTMLEncoder.encodeToBuffer(attributeName, tagBuffer);
tagBuffer.append("=\"");
HTMLEncoder.encodeToBuffer(attributeValue, tagBuffer);
- tagBuffer.append('"');;
+ tagBuffer.append('"');
}
if (children.size() == 0) {
- if (name.equals("textarea") || name.equals("div") ||
name.equals("a")) {
- tagBuffer.append("></").append(name).append('>');
+ if ("textarea".equals(name) || ("div").equals(name) ||
("a").equals(name)) {
+
tagBuffer.append("></").append(name).append('>');
} else {
tagBuffer.append(" />");
}
} else {
tagBuffer.append('>');
- if(name.equals("div") || name.equals("form") ||
name.equals("input") || name.equals("script") || name.equals("table") ||
name.equals("tr") || name.equals("td")) {
+ if(("div").equals(name) || ("form").equals(name) ||
("input").equals(name) || ("script").equals(name) || ("table").equals(name) ||
("tr").equals(name) || ("td").equals(name)) {
tagBuffer.append('\n');
}
for (int childIndex = 0, childCount = children.size();
childIndex < childCount; childIndex++) {
- HTMLNode childNode = (HTMLNode)
children.get(childIndex);
+ HTMLNode childNode = children.get(childIndex);
childNode.generate(tagBuffer);
}
tagBuffer.append("</").append(name).append('>');
- if(name.equals("div") || name.equals("form") ||
name.equals("input") || name.equals("li") || name.equals("option") ||
name.equals("script") || name.equals("table") || name.equals("tr") ||
name.equals("td")) {
+ if(("div").equals(name)|| ("form").equals(name)||
("input").equals(name)|| ("li").equals(name)|| ("option").equals(name)||
("script").equals(name)|| ("table").equals(name)|| ("tr").equals(name)||
("td").equals(name)) {
tagBuffer.append('\n');
}
}
@@ -236,12 +237,13 @@
/**
* @see
freenet.support.HTMLNode#generate(java.lang.StringBuffer)
*/
- public StringBuffer generate(StringBuffer tagBuffer) {
+ @Override
+ public StringBuilder generate(StringBuilder tagBuffer) {
tagBuffer.append("<!DOCTYPE ").append(name).append("
PUBLIC \"").append(systemUri).append("\">\n");
//TODO A meaningful exception should be raised
// when trying to call the method for a HTMLDoctype
// with number of child != 1
- return ((HTMLNode) children.get(0)).generate(tagBuffer);
+ return children.get(0).generate(tagBuffer);
}
}
Modified: branches/saltedhashstore/freenet/src/freenet/support/LRUHashtable.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/LRUHashtable.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/LRUHashtable.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -3,7 +3,7 @@
import java.util.Enumeration;
import java.util.Hashtable;
-public class LRUHashtable {
+public class LRUHashtable<K, V> {
/*
* I've just converted this to using the DLList and Hashtable
@@ -12,8 +12,8 @@
* push is by far the most done operation, this should be an
* overall improvement.
*/
- private final DoublyLinkedListImpl list = new DoublyLinkedListImpl();
- private final Hashtable hash = new Hashtable();
+ private final DoublyLinkedListImpl<V> list = new DoublyLinkedListImpl<V>();
+ private final Hashtable<K, QItem<K, V>> hash = new Hashtable<K, QItem<K,
V>>();
/**
* push()ing an object that is already in
@@ -21,10 +21,10 @@
* recently used position, but doesn't add
* a duplicate entry in the queue.
*/
- public final synchronized void push(Object key, Object value) {
- QItem insert = (QItem)hash.get(key);
+ public final synchronized void push(K key, V value) {
+ QItem<K,V> insert = hash.get(key);
if (insert == null) {
- insert = new QItem(key, value);
+ insert = new QItem<K, V>(key, value);
hash.put(key,insert);
} else {
insert.value = value;
@@ -41,7 +41,7 @@
*/
public final synchronized Object popKey() {
if ( list.size() > 0 ) {
- return ((QItem)hash.remove(((QItem)list.pop()).obj)).obj;
+ return ( hash.remove(((QItem) list.pop()).obj)).obj;
} else {
return null;
}
@@ -52,7 +52,7 @@
*/
public final synchronized Object popValue() {
if ( list.size() > 0 ) {
- return ((QItem)hash.remove(((QItem)list.pop()).obj)).value;
+ return ( hash.remove(((QItem) list.pop()).obj)).value;
} else {
return null;
}
@@ -60,7 +60,7 @@
public final synchronized Object peekValue() {
if ( list.size() > 0 ) {
- return ((QItem)hash.get(((QItem)list.tail()).obj)).value;
+ return ( hash.get(((QItem) list.tail()).obj)).value;
} else {
return null;
}
@@ -70,8 +70,8 @@
return list.size();
}
- public final synchronized boolean removeKey(Object key) {
- QItem i = (QItem)(hash.remove(key));
+ public final synchronized boolean removeKey(K key) {
+ QItem<K,V> i = (hash.remove(key));
if(i != null) {
list.remove(i);
return true;
@@ -85,7 +85,7 @@
* @param obj Object to match
* @return true if this queue contains obj.
*/
- public final synchronized boolean containsKey(Object key) {
+ public final synchronized boolean containsKey(K key) {
return hash.containsKey(key);
}
@@ -93,8 +93,8 @@
* Note that this does not automatically promote the key. You have
* to do that by hand with push(key, value).
*/
- public final synchronized Object get(Object key) {
- QItem q = (QItem) hash.get(key);
+ public final synchronized V get(K key) {
+ QItem<K,V> q = hash.get(key);
if(q == null) return null;
return q.value;
}
@@ -131,15 +131,16 @@
}
}
- private static class QItem extends DoublyLinkedListImpl.Item {
- public Object obj;
- public Object value;
+ public static class QItem<K, V> extends DoublyLinkedListImpl.Item<V> {
+ public K obj;
+ public V value;
- public QItem(Object key, Object val) {
+ public QItem(K key, V val) {
this.obj = key;
this.value = val;
}
+ @Override
public String toString() {
return super.toString()+": "+obj+ ' ' +value;
}
@@ -155,8 +156,8 @@
* @param entries
* @return
*/
- public synchronized void valuesToArray(Object[] entries) {
- Enumeration values = values();
+ public synchronized void valuesToArray(V[] entries) {
+ Enumeration<V> values = values();
int i=0;
while(values.hasMoreElements())
entries[i++] = values.nextElement();
Modified: branches/saltedhashstore/freenet/src/freenet/support/OOMHandler.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/OOMHandler.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/OOMHandler.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -8,8 +8,6 @@
import org.tanukisoftware.wrapper.WrapperManager;
-import freenet.support.Logger;
-
/**
* Do this processing as a standard response to an OutOfMemoryError
*/
@@ -25,7 +23,7 @@
/**
* List of {@link OOMHook}s
*/
- private static Set oomHooks = new WeakHashSet();
+ private static Set<OOMHook> oomHooks = new WeakHashSet<OOMHook>();
public static void addOOMHook(OOMHook hook) {
synchronized (oomHooks) {
@@ -41,9 +39,9 @@
System.runFinalization();
// iterate all oom hooks
- Iterator it = oomHooks.iterator();
+ Iterator<OOMHook> it = oomHooks.iterator();
while (it.hasNext()) {
- OOMHook hook = ((OOMHook) it.next());
+ OOMHook hook = it.next();
if (hook != null) {
try {
hook.handleLowMemory();
@@ -77,9 +75,9 @@
System.runFinalization();
// iterate all oom hooks
- Iterator it = oomHooks.iterator();
+ Iterator<OOMHook> it = oomHooks.iterator();
while (it.hasNext()) {
- OOMHook hook = ((OOMHook) it.next());
+ OOMHook hook = it.next();
if (hook != null) {
try {
hook.handleOutOfMemory();
Modified:
branches/saltedhashstore/freenet/src/freenet/support/SimpleFieldSet.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/SimpleFieldSet.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/SimpleFieldSet.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -33,8 +33,8 @@
*/
public class SimpleFieldSet {
- private final Map values;
- private Map subsets;
+ private final Map<String, String> values;
+ private Map<String, SimpleFieldSet> subsets;
private String endMarker;
private final boolean shortLived;
static public final char MULTI_LEVEL_CHAR = '.';
@@ -49,7 +49,7 @@
* small.
*/
public SimpleFieldSet(boolean shortLived) {
- values = new HashMap();
+ values = new HashMap<String, String>();
subsets = null;
this.shortLived = shortLived;
}
@@ -71,9 +71,9 @@
}
public SimpleFieldSet(SimpleFieldSet sfs){
- values = new HashMap(sfs.values);
+ values = new HashMap<String, String>(sfs.values);
if(sfs.subsets != null)
- subsets = new HashMap(sfs.subsets);
+ subsets = new HashMap<String, SimpleFieldSet>(sfs.subsets);
this.shortLived = false; // it's been copied!
endMarker = sfs.endMarker;
}
@@ -173,14 +173,14 @@
public synchronized String get(String key) {
int idx = key.indexOf(MULTI_LEVEL_CHAR);
if(idx == -1)
- return (String) values.get(key);
+ return values.get(key);
else if(idx == 0)
return (subset("") == null) ? null :
subset("").get(key.substring(1));
else {
if(subsets == null) return null;
String before = key.substring(0, idx);
String after = key.substring(idx+1);
- SimpleFieldSet fs = (SimpleFieldSet)
(subsets.get(before));
+ SimpleFieldSet fs = subsets.get(before);
if(fs == null) return null;
return fs.get(after);
}
@@ -193,7 +193,7 @@
}
private static final String[] split(String string) {
- if(string == null) return new String[0];
+ if(string == null) return EMPTY_STRING_ARRAY;
return string.split(String.valueOf(MULTI_VALUE_CHAR)); // slower???
// int index = string.indexOf(';');
// if(index == -1) return null;
@@ -212,7 +212,7 @@
}
private static final String unsplit(String[] strings) {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
for(int i=0;i<strings.length;i++) {
if(i != 0) sb.append(MULTI_VALUE_CHAR);
sb.append(strings[i]);
@@ -227,7 +227,7 @@
Iterator i = fs.values.keySet().iterator();
while(i.hasNext()) {
String key = (String) i.next();
- String hisVal = (String) fs.values.get(key);
+ String hisVal = fs.values.get(key);
values.put(key, hisVal); // overwrite old
}
if(fs.subsets == null) return;
@@ -235,8 +235,8 @@
i = fs.subsets.keySet().iterator();
while(i.hasNext()) {
String key = (String) i.next();
- SimpleFieldSet hisFS = (SimpleFieldSet) fs.subsets.get(key);
- SimpleFieldSet myFS = (SimpleFieldSet) subsets.get(key);
+ SimpleFieldSet hisFS = fs.subsets.get(key);
+ SimpleFieldSet myFS = subsets.get(key);
if(myFS != null) {
myFS.putAllOverwrite(hisFS);
} else {
@@ -294,14 +294,14 @@
if(value == null) return true; // valid no-op
if(value.indexOf('\n') != -1) throw new
IllegalArgumentException("A simplefieldSet can't accept newlines !");
if((idx = key.indexOf(MULTI_LEVEL_CHAR)) == -1) {
- String x = (String) values.get(key);
+ String x = values.get(key);
if(!shortLived) key = key.intern();
if(x == null || overwrite) {
values.put(key, value);
} else {
if(!allowMultiple) return false;
- values.put(key, ((String)values.get(key))+
MULTI_VALUE_CHAR +value);
+ values.put(key, (values.get(key))+
MULTI_VALUE_CHAR +value);
}
} else {
String before = key.substring(0, idx);
@@ -309,7 +309,7 @@
SimpleFieldSet fs = null;
if(subsets == null)
subsets = new HashMap();
- fs = (SimpleFieldSet) (subsets.get(before));
+ fs = subsets.get(before);
if(fs == null) {
fs = new SimpleFieldSet(shortLived);
if(!shortLived) before = before.intern();
@@ -399,7 +399,7 @@
}
private synchronized void writeToOrdered(Writer w, String prefix, boolean
noEndMarker) throws IOException {
- String[] keys = (String[]) values.keySet().toArray(new
String[values.size()]);
+ String[] keys = values.keySet().toArray(new String[values.size()]);
int i=0;
// Sort
@@ -410,7 +410,7 @@
w.write(prefix+keys[i]+KEYVALUE_SEPARATOR_CHAR+get(keys[i])+'\n');
if(subsets != null) {
- String[] orderedPrefixes = (String[])
subsets.keySet().toArray(new String[subsets.size()]);
+ String[] orderedPrefixes = subsets.keySet().toArray(new
String[subsets.size()]);
// Sort
Arrays.sort(orderedPrefixes);
@@ -429,6 +429,7 @@
}
}
+ @Override
public String toString() {
StringWriter sw = new StringWriter();
try {
@@ -461,10 +462,10 @@
if(subsets == null) return null;
int idx = key.indexOf(MULTI_LEVEL_CHAR);
if(idx == -1)
- return (SimpleFieldSet) subsets.get(key);
+ return subsets.get(key);
String before = key.substring(0, idx);
String after = key.substring(idx+1);
- SimpleFieldSet fs = (SimpleFieldSet) subsets.get(before);
+ SimpleFieldSet fs = subsets.get(before);
if(fs == null) return null;
return fs.subset(after);
}
@@ -519,7 +520,7 @@
if(subsetIterator == null ||
!subsetIterator.hasNext()) break;
String name = (String) subsetIterator.next();
if(name == null) continue;
- SimpleFieldSet fs = (SimpleFieldSet)
subsets.get(name);
+ SimpleFieldSet fs = subsets.get(name);
if(fs == null) continue;
String newPrefix = prefix + name +
MULTI_LEVEL_CHAR;
subIterator = fs.keyIterator(newPrefix);
@@ -538,7 +539,7 @@
if(subIterator != null) subIterator =
null;
if(subsetIterator != null &&
subsetIterator.hasNext()) {
String key = (String)
subsetIterator.next();
- SimpleFieldSet fs =
(SimpleFieldSet) subsets.get(key);
+ SimpleFieldSet fs =
subsets.get(key);
String newPrefix = prefix + key
+ MULTI_LEVEL_CHAR;
subIterator =
fs.keyIterator(newPrefix);
} else
@@ -571,7 +572,7 @@
subIterator = null;
if(subsetIterator != null &&
subsetIterator.hasNext()) {
String key = (String)
subsetIterator.next();
- SimpleFieldSet fs =
(SimpleFieldSet) subsets.get(key);
+ SimpleFieldSet fs =
subsets.get(key);
String newPrefix = prefix + key
+ MULTI_LEVEL_CHAR;
subIterator =
fs.keyIterator(newPrefix);
} else {
@@ -615,7 +616,7 @@
if(subsets == null) return;
String before = key.substring(0, idx);
String after = key.substring(idx+1);
- SimpleFieldSet fs = (SimpleFieldSet)
(subsets.get(before));
+ SimpleFieldSet fs = subsets.get(before);
if(fs == null) {
return;
}
@@ -646,7 +647,7 @@
} else {
String before = key.substring(0, idx);
String after = key.substring(idx+1);
- SimpleFieldSet fs = (SimpleFieldSet)
(subsets.get(before));
+ SimpleFieldSet fs = subsets.get(before);
if(fs == null) {
return;
}
@@ -669,7 +670,7 @@
}
public String[] namesOfDirectSubsets() {
- return (subsets == null) ? EMPTY_STRING_ARRAY : (String[])
subsets.keySet().toArray(new String[subsets.size()]);
+ return (subsets == null) ? EMPTY_STRING_ARRAY :
subsets.keySet().toArray(new String[subsets.size()]);
}
public static SimpleFieldSet readFrom(InputStream is, boolean
allowMultiple, boolean shortLived) throws IOException {
Modified:
branches/saltedhashstore/freenet/src/freenet/support/SortedLongSet.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/SortedLongSet.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/SortedLongSet.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -1,6 +1,5 @@
package freenet.support;
-import java.util.Arrays;
/**
* Sorted array of long's.
Modified: branches/saltedhashstore/freenet/src/freenet/support/WeakHashSet.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/WeakHashSet.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/WeakHashSet.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -5,50 +5,60 @@
import java.util.Iterator;
import java.util.WeakHashMap;
-public class WeakHashSet extends AbstractSet {
- private final WeakHashMap map;
+public class WeakHashSet<E> extends AbstractSet<E> {
+ private final WeakHashMap<E, Object> map;
public WeakHashSet() {
- map = new WeakHashMap();
+ map = new WeakHashMap<E, Object>();
}
- public boolean add(Object key) {
+ @Override
+ public boolean add(E key) {
return map.put(key, null) == null;
}
- public void clear() {
+ @Override
+ public void clear() {
map.clear();
}
- public boolean contains(Object key) {
+ @Override
+ public boolean contains(Object key) {
return map.containsKey(key);
}
- public boolean containsAll(Collection arg0) {
+ @Override
+ public boolean containsAll(Collection<?> arg0) {
return map.keySet().containsAll(arg0);
}
- public boolean isEmpty() {
+ @Override
+ public boolean isEmpty() {
return map.isEmpty();
}
- public Iterator iterator() {
+ @Override
+ public Iterator<E> iterator() {
return map.keySet().iterator();
}
- public boolean remove(Object key) {
+ @Override
+ public boolean remove(Object key) {
return map.remove(key) != null;
}
- public int size() {
+ @Override
+ public int size() {
return map.size();
}
- public Object[] toArray() {
+ @Override
+ public Object[] toArray() {
return map.keySet().toArray();
}
- public Object[] toArray(Object[] arg0) {
+ @Override
+ public <T> T[] toArray(T[] arg0) {
return map.keySet().toArray(arg0);
}
}
Modified: branches/saltedhashstore/freenet/src/freenet/support/io/Closer.java
===================================================================
--- branches/saltedhashstore/freenet/src/freenet/support/io/Closer.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/src/freenet/support/io/Closer.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -18,12 +18,8 @@
package freenet.support.io;
+import java.io.Closeable;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.jar.JarFile;
import java.util.zip.ZipFile;
/**
@@ -36,77 +32,16 @@
* @version $Id$
*/
public class Closer {
-
/**
- * Closes the given output stream.
+ * Closes the given stream.
*
* @param outputStream
* The output stream to close
*/
- public static void close(OutputStream outputStream) {
- if (outputStream != null) {
+ public static void close(Closeable closable) {
+ if (closable != null) {
try {
- outputStream.close();
- } catch (IOException ioe1) {
- }
- }
- }
-
- /**
- * Closes the given input stream.
- *
- * @param inputStream
- * The input stream to close
- */
- public static void close(InputStream inputStream) {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException ioe1) {
- }
- }
- }
-
- /**
- * Closes the given writer.
- *
- * @param writer
- * The writer to close
- */
- public static void close(Writer writer) {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException ioe1) {
- }
- }
- }
-
- /**
- * Closes the given reader.
- *
- * @param reader
- * The reader to close
- */
- public static void close(Reader reader) {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException ioe1) {
- }
- }
- }
-
- /**
- * Closes the given jar file.
- *
- * @param jarFile
- * The jar file to close
- */
- public static void close(JarFile jarFile) {
- if (jarFile != null) {
- try {
- jarFile.close();
+ closable.close();
} catch (IOException e) {
}
}
Modified:
branches/saltedhashstore/freenet/src/freenet/support/io/LineReadingInputStream.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/support/io/LineReadingInputStream.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/support/io/LineReadingInputStream.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -16,8 +16,6 @@
super(in);
}
- private byte[] buf;
-
/**
* Read a \n or \r\n terminated line of UTF-8 or ISO-8859-1.
* @param maxLength The maximum length of a line. If a line is longer
than this, we throw IOException rather
@@ -26,31 +24,73 @@
* @param utf If true, read as UTF-8, if false, read as ISO-8859-1.
*/
public String readLine(int maxLength, int bufferSize, boolean utf)
throws IOException {
+ if(maxLength <= bufferSize)
+ bufferSize = maxLength + 1; // Buffer too big, shrink
it (add 1 for the optional \r)
+
+ if(!markSupported())
+ return readLineWithoutMarking(maxLength, bufferSize,
utf);
+
+ byte[] buf = new byte[Math.max(Math.min(128, maxLength),
Math.min(1024, bufferSize))];
+ int ctr = 0;
+ mark((maxLength+1)*2); // Might be more than maxLengh if we use
utf8
+ while(true) {
+ int x = read(buf, ctr, buf.length - ctr);
+ if(x == -1) {
+ if(ctr == 0)
+ return null;
+ return new String(buf, 0, ctr, utf ? "UTF-8" :
"ISO-8859-1");
+ }
+ // REDFLAG this is definitely safe with the above
charsets, it may not be safe with some wierd ones.
+ for(; ctr < buf.length; ctr++) {
+ if(ctr >= maxLength)
+ throw new TooLongException();
+ if(buf[ctr] == '\n') {
+ String toReturn = "";
+ if(ctr != 0) {
+ boolean removeCR = (buf[ctr -
1] == '\r');
+ toReturn = new String(buf, 0,
(removeCR ? ctr - 1 : ctr), utf ? "UTF-8" : "ISO-8859-1");
+ }
+ reset();
+ skip(ctr + 1);
+ return toReturn;
+ }
+ }
+ if(x > 0) {
+ byte[] newBuf = new byte[Math.min(buf.length *
2, maxLength)];
+ System.arraycopy(buf, 0, newBuf, 0, buf.length);
+ buf = newBuf;
+ }
+ }
+ }
+
+ public String readLineWithoutMarking(int maxLength, int bufferSize,
boolean utf) throws IOException {
if(maxLength < bufferSize)
bufferSize = maxLength + 1; // Buffer too big, shrink
it (add 1 for the optional \r)
- if(buf == null)
- buf = new byte[Math.max(Math.min(128,maxLength),
Math.min(1024, bufferSize))];
+ byte[] buf = new byte[Math.max(Math.min(128, maxLength),
Math.min(1024, bufferSize))];
int ctr = 0;
while(true) {
int x = read();
if(x == -1) {
- if(ctr == 0) return null;
+ if(ctr == 0)
+ return null;
return new String(buf, 0, ctr, utf ? "UTF-8" :
"ISO-8859-1");
}
// REDFLAG this is definitely safe with the above
charsets, it may not be safe with some wierd ones.
if(x == '\n') {
- if(ctr == 0) return "";
- if(buf[ctr-1] == '\r') ctr--;
+ if(ctr == 0)
+ return "";
+ if(buf[ctr - 1] == '\r')
+ ctr--;
return new String(buf, 0, ctr, utf ? "UTF-8" :
"ISO-8859-1");
}
- if(ctr >= maxLength) throw new TooLongException();
+ if(ctr >= maxLength)
+ throw new TooLongException();
if(ctr >= buf.length) {
byte[] newBuf = new byte[Math.min(buf.length *
2, maxLength)];
System.arraycopy(buf, 0, newBuf, 0, buf.length);
buf = newBuf;
}
- buf[ctr++] = (byte)x;
+ buf[ctr++] = (byte) x;
}
}
-
}
Modified:
branches/saltedhashstore/freenet/src/freenet/support/io/RandomAccessThing.java
===================================================================
---
branches/saltedhashstore/freenet/src/freenet/support/io/RandomAccessThing.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/src/freenet/support/io/RandomAccessThing.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -3,13 +3,14 @@
* http://www.gnu.org/ for further details of the GPL. */
package freenet.support.io;
+import java.io.Closeable;
import java.io.IOException;
/**
* Trivial random access file base interface.
* @author toad
*/
-public interface RandomAccessThing {
+public interface RandomAccessThing extends Closeable {
public long size() throws IOException;
Modified: branches/saltedhashstore/freenet/test/freenet/support/BufferTest.java
===================================================================
--- branches/saltedhashstore/freenet/test/freenet/support/BufferTest.java
2008-08-17 10:36:48 UTC (rev 21952)
+++ branches/saltedhashstore/freenet/test/freenet/support/BufferTest.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -141,7 +141,7 @@
Buffer b2 = new Buffer("Buffer2".getBytes());
Buffer b3 = new Buffer("Buffer1".getBytes());
- Map hashMap = new HashMap();
+ Map<Buffer, Buffer> hashMap = new HashMap<Buffer, Buffer>();
hashMap.put(b1, b1);
hashMap.put(b2, b2);
Modified:
branches/saltedhashstore/freenet/test/freenet/support/ByteArrayWrapperTest.java
===================================================================
---
branches/saltedhashstore/freenet/test/freenet/support/ByteArrayWrapperTest.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/test/freenet/support/ByteArrayWrapperTest.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -32,7 +32,7 @@
assertFalse(wrapper2.equals(wrapper3));
assertFalse(wrapper1.equals(new String()));
- Map map = new HashMap();
+ Map<ByteArrayWrapper, ByteArrayWrapper> map = new
HashMap<ByteArrayWrapper, ByteArrayWrapper>();
map.put(wrapper1, wrapper1);
map.put(wrapper2, wrapper2); // should clobber 1 by hashcode
Modified:
branches/saltedhashstore/freenet/test/freenet/support/MultiValueTableTest.java
===================================================================
---
branches/saltedhashstore/freenet/test/freenet/support/MultiValueTableTest.java
2008-08-17 10:36:48 UTC (rev 21952)
+++
branches/saltedhashstore/freenet/test/freenet/support/MultiValueTableTest.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -63,8 +63,8 @@
* @param valuesNumber number of objects to create
* @return the sample List
*/
- private List fillSampleValuesList(int valuesNumber) {
- List sampleValues = new LinkedList();
+ private List<Object> fillSampleValuesList(int valuesNumber) {
+ List<Object> sampleValues = new LinkedList<Object>();
for(int i=0; i<valuesNumber;i++)
sampleValues.add(new Object());
return sampleValues;
Added:
branches/saltedhashstore/freenet/test/freenet/support/io/LineReadingInputStreamTest.java
===================================================================
---
branches/saltedhashstore/freenet/test/freenet/support/io/LineReadingInputStreamTest.java
(rev 0)
+++
branches/saltedhashstore/freenet/test/freenet/support/io/LineReadingInputStreamTest.java
2008-08-17 11:35:49 UTC (rev 21953)
@@ -0,0 +1,106 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+package freenet.support.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import junit.framework.TestCase;
+
+public class LineReadingInputStreamTest extends TestCase {
+ public static final String BLOCK =
"\ntesting1\ntesting2\r\ntesting3\n\n";
+ public static final String[] LINES = new String[] {
+ "",
+ "testing1",
+ "testing2",
+ "testing3",
+ ""
+ };
+
+ public static final String STRESSED_LINE = "\n\u0114\n";
+
+ public static final int MAX_LENGTH = 128;
+ public static final int BUFFER_SIZE = 128;
+
+ public void testReadLineWithoutMarking() throws Exception {
+ // try utf8
+ InputStream is = new
ByteArrayInputStream(STRESSED_LINE.getBytes("utf-8"));
+ LineReadingInputStream instance = new
LineReadingInputStream(is);
+ assertEquals("", instance.readLineWithoutMarking(MAX_LENGTH,
BUFFER_SIZE, true));
+ assertEquals("\u0114",
instance.readLineWithoutMarking(MAX_LENGTH, BUFFER_SIZE, true));
+ assertNull(instance.readLineWithoutMarking(MAX_LENGTH,
BUFFER_SIZE, true));
+
+ // try ISO-8859-1
+ is = new ByteArrayInputStream(BLOCK.getBytes("ISO-8859-1"));
+ instance = new LineReadingInputStream(is);
+ for(String expectedLine : LINES) {
+ assertEquals(expectedLine,
instance.readLineWithoutMarking(MAX_LENGTH, BUFFER_SIZE, false));
+ }
+ assertNull(instance.readLineWithoutMarking(MAX_LENGTH,
BUFFER_SIZE, false));
+
+ // is it returning null?
+ is = new NullInputStream();
+ instance = new LineReadingInputStream(is);
+ assertNull(instance.readLineWithoutMarking(0, BUFFER_SIZE,
false));
+
+ // is it throwing?
+ is = new ByteArrayInputStream("aaa\na\n".getBytes());
+ instance = new LineReadingInputStream(is);
+ try {
+ instance.readLineWithoutMarking(2, BUFFER_SIZE, true);
+ fail();
+ } catch (TooLongException e) {}
+ }
+
+ public void testReadLine() throws Exception {
+ // try utf8
+ InputStream is = new
ByteArrayInputStream(STRESSED_LINE.getBytes("utf-8"));
+ LineReadingInputStream instance = new
LineReadingInputStream(is);
+ assertEquals("", instance.readLine(MAX_LENGTH, BUFFER_SIZE,
true));
+ assertEquals("\u0114", instance.readLine(MAX_LENGTH,
BUFFER_SIZE, true));
+ assertNull(instance.readLine(MAX_LENGTH, BUFFER_SIZE, true));
+
+ // try ISO-8859-1
+ is = new ByteArrayInputStream(BLOCK.getBytes("ISO-8859-1"));
+ instance = new LineReadingInputStream(is);
+ for(String expectedLine : LINES) {
+ assertEquals(expectedLine,
instance.readLine(MAX_LENGTH, BUFFER_SIZE, false));
+ }
+ assertNull(instance.readLine(MAX_LENGTH, BUFFER_SIZE, false));
+
+ // is it returning null?
+ is = new NullInputStream();
+ instance = new LineReadingInputStream(is);
+ assertNull(instance.readLine(0, BUFFER_SIZE, false));
+
+ // is it throwing?
+ is = new ByteArrayInputStream("aaa\na\n".getBytes());
+ instance = new LineReadingInputStream(is);
+ try {
+ instance.readLine(2, BUFFER_SIZE, true);
+ fail();
+ } catch (TooLongException e) {}
+ }
+
+ public void testBothImplementation() throws Exception {
+ // CWD is either the node's or the build tree
+ File f = new File("freenet.ini");
+ if(!f.exists())
+ f = new File("build.xml");
+ BufferedInputStream bis1 = new BufferedInputStream(new
FileInputStream(f));
+ BufferedInputStream bis2 = new BufferedInputStream(new
FileInputStream(f));
+ LineReadingInputStream lris1 = new LineReadingInputStream(bis1);
+ LineReadingInputStream lris2 = new LineReadingInputStream(bis2);
+
+ while(bis1.available() > 0 || bis2.available() > 0) {
+ String stringWithoutMark
=lris2.readLineWithoutMarking(MAX_LENGTH*10, BUFFER_SIZE, true);
+ String stringWithMark = lris1.readLine(MAX_LENGTH*10,
BUFFER_SIZE, true);
+ assertEquals(stringWithMark, stringWithoutMark);
+ }
+ assertNull(lris1.readLine(MAX_LENGTH, BUFFER_SIZE, true));
+ assertNull(lris2.readLineWithoutMarking(MAX_LENGTH,
BUFFER_SIZE, true));
+ }
+}