From: David ‘Bombe’ Roden Date: Sun, 6 Apr 2014 20:03:03 +0000 (+0200) Subject: Remove dependency on utils package. X-Git-Tag: v0.1.3^2~9 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=317bb21d6c9d43795f026f97709a7e67acf6f751;p=jFCPlib.git Remove dependency on utils package. --- diff --git a/pom.xml b/pom.xml index c2a5995..4721108 100644 --- a/pom.xml +++ b/pom.xml @@ -20,9 +20,9 @@ test - net.pterodactylus - utils - 0.6.1 + com.google.guava + guava + 16.0.1 diff --git a/src/main/java/net/pterodactylus/fcp/FcpConnection.java b/src/main/java/net/pterodactylus/fcp/FcpConnection.java index 858b783..66377a2 100644 --- a/src/main/java/net/pterodactylus/fcp/FcpConnection.java +++ b/src/main/java/net/pterodactylus/fcp/FcpConnection.java @@ -31,8 +31,6 @@ import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; -import net.pterodactylus.util.logging.Logging; - /** * An FCP connection to a Freenet node. * @@ -41,7 +39,7 @@ import net.pterodactylus.util.logging.Logging; public class FcpConnection implements Closeable { /** Logger. */ - private static final Logger logger = Logging.getLogger(FcpConnection.class.getName()); + private static final Logger logger = Logger.getLogger(FcpConnection.class.getName()); /** The default port for FCP v2. */ public static final int DEFAULT_PORT = 9481; diff --git a/src/main/java/net/pterodactylus/fcp/FcpConnectionHandler.java b/src/main/java/net/pterodactylus/fcp/FcpConnectionHandler.java index e46966a..36be123 100644 --- a/src/main/java/net/pterodactylus/fcp/FcpConnectionHandler.java +++ b/src/main/java/net/pterodactylus/fcp/FcpConnectionHandler.java @@ -25,8 +25,6 @@ import java.nio.charset.Charset; import java.util.logging.Level; import java.util.logging.Logger; -import net.pterodactylus.util.logging.Logging; - /** * Handles an FCP connection to a node. * @@ -35,7 +33,7 @@ import net.pterodactylus.util.logging.Logging; class FcpConnectionHandler implements Runnable { /** The logger. */ - private static final Logger logger = Logging.getLogger(FcpConnectionHandler.class.getName()); + private static final Logger logger = Logger.getLogger(FcpConnectionHandler.class.getName()); /** The underlying connection. */ private final FcpConnection fcpConnection; diff --git a/src/main/java/net/pterodactylus/fcp/FcpListenerManager.java b/src/main/java/net/pterodactylus/fcp/FcpListenerManager.java index 4f3b9dd..7969da1 100644 --- a/src/main/java/net/pterodactylus/fcp/FcpListenerManager.java +++ b/src/main/java/net/pterodactylus/fcp/FcpListenerManager.java @@ -18,14 +18,18 @@ package net.pterodactylus.fcp; -import net.pterodactylus.util.event.AbstractListenerManager; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; /** * Manages FCP listeners and event firing. * * @author David ‘Bombe’ Roden <bombe@pterodactylus.net> */ -public class FcpListenerManager extends AbstractListenerManager { +public class FcpListenerManager { + + private final FcpConnection source; + private final List listeners = new CopyOnWriteArrayList(); /** * Creates a new listener manager. @@ -34,7 +38,23 @@ public class FcpListenerManager extends AbstractListenerManager getListeners() { + return listeners; } /** diff --git a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java index 56fb90d..bc1092e 100644 --- a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -18,6 +18,8 @@ package net.pterodactylus.fcp.highlevel; +import static com.google.common.collect.FluentIterable.from; + import java.io.Closeable; import java.io.IOException; import java.io.InputStream; @@ -32,6 +34,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.fcp.AddPeer; import net.pterodactylus.fcp.AllData; @@ -68,10 +71,8 @@ import net.pterodactylus.fcp.RemovePeer; import net.pterodactylus.fcp.SSKKeypair; import net.pterodactylus.fcp.SimpleProgress; import net.pterodactylus.fcp.WatchGlobal; -import net.pterodactylus.util.filter.Filter; -import net.pterodactylus.util.filter.Filters; -import net.pterodactylus.util.io.TemporaryInputStream; -import net.pterodactylus.util.thread.ObjectWrapper; + +import com.google.common.base.Predicate; /** * High-level FCP client that hides the details of the underlying FCP @@ -380,13 +381,7 @@ public class FcpClient implements Closeable { if (!allData.getIdentifier().equals(identifier)) { return; } - InputStream temporaryInputStream; - try { - temporaryInputStream = new TemporaryInputStream(allData.getPayloadInputStream()); - getResult.success(true).contentType(allData.getContentType()).contentLength(allData.getDataLength()).inputStream(temporaryInputStream); - } catch (IOException ioe1) { - getResult.success(false).exception(ioe1); - } + getResult.success(true).contentType(allData.getContentType()).contentLength(allData.getDataLength()).inputStream(allData.getPayloadInputStream()); completionLatch.countDown(); } @@ -742,7 +737,7 @@ public class FcpClient implements Closeable { * if an FCP error occurs */ public PeerNote getPeerNote(final Peer peer) throws IOException, FcpException { - final ObjectWrapper objectWrapper = new ObjectWrapper(); + final AtomicReference objectWrapper = new AtomicReference(); new ExtendedFcpAdapter() { /** @@ -828,7 +823,7 @@ public class FcpClient implements Closeable { * if an FCP error occurs */ public SSKKeypair generateKeyPair() throws IOException, FcpException { - final ObjectWrapper sskKeypairWrapper = new ObjectWrapper(); + final AtomicReference sskKeypairWrapper = new AtomicReference(); new ExtendedFcpAdapter() { /** @@ -870,16 +865,12 @@ public class FcpClient implements Closeable { * if an FCP error occurs */ public Collection getGetRequests(final boolean global) throws IOException, FcpException { - return Filters.filteredCollection(getRequests(global), new Filter() { - - /** - * {@inheritDoc} - */ + return from(getRequests(global)).filter(new Predicate() { @Override - public boolean filterObject(Request request) { + public boolean apply(Request request) { return request instanceof GetRequest; } - }); + }).toList(); } /** @@ -896,16 +887,12 @@ public class FcpClient implements Closeable { * if an FCP error occurs */ public Collection getPutRequests(final boolean global) throws IOException, FcpException { - return Filters.filteredCollection(getRequests(global), new Filter() { - - /** - * {@inheritDoc} - */ + return from(getRequests(global)).filter(new Predicate() { @Override - public boolean filterObject(Request request) { + public boolean apply(Request request) { return request instanceof PutRequest; } - }); + }).toList(); } /** @@ -1119,7 +1106,7 @@ public class FcpClient implements Closeable { * if an I/O error occurs */ public NodeData getNodeInformation(final Boolean giveOpennetRef, final Boolean withPrivate, final Boolean withVolatile) throws IOException, FcpException { - final ObjectWrapper nodeDataWrapper = new ObjectWrapper(); + final AtomicReference nodeDataWrapper = new AtomicReference(); new ExtendedFcpAdapter() { @Override diff --git a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClientListenerManager.java b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClientListenerManager.java index aa797e4..eb9ef2f 100644 --- a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClientListenerManager.java +++ b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClientListenerManager.java @@ -18,14 +18,18 @@ package net.pterodactylus.fcp.highlevel; -import net.pterodactylus.util.event.AbstractListenerManager; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; /** * Manages {@link FcpClientListener}s and fires events. * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ -public class FcpClientListenerManager extends AbstractListenerManager { +public class FcpClientListenerManager { + + private final FcpClient source; + private final List listeners = new CopyOnWriteArrayList(); /** * Creates a new FCP client listener manager. @@ -34,7 +38,15 @@ public class FcpClientListenerManager extends AbstractListenerManager getListeners() { + return listeners; } /** @@ -48,4 +60,12 @@ public class FcpClientListenerManager extends AbstractListenerManager