From 087cfe551f0e87ebb128820045bac5b2c04b6ac2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 12 Oct 2010 16:50:36 +0200 Subject: [PATCH] Add method that fetches an URI. --- .../pterodactylus/sone/core/FreenetInterface.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 9214d85..8f9ec8f 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -17,8 +17,15 @@ package net.pterodactylus.sone.core; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.service.AbstractService; +import freenet.client.FetchException; +import freenet.client.FetchResult; import freenet.client.HighLevelSimpleClient; +import freenet.keys.FreenetURI; import freenet.node.Node; /** @@ -28,6 +35,9 @@ import freenet.node.Node; */ public class FreenetInterface extends AbstractService { + /** The logger. */ + private static final Logger logger = Logging.getLogger(FreenetInterface.class); + /** The node to interact with. */ private final Node node; @@ -47,4 +57,24 @@ public class FreenetInterface extends AbstractService { this.client = client; } + // + // ACTIONS + // + + /** + * Fetches the given URI. + * + * @param uri + * The URI to fetch + * @return The result of the fetch, or {@code null} if an error occured + */ + public FetchResult fetchUri(FreenetURI uri) { + try { + return client.fetch(uri); + } catch (FetchException fe1) { + logger.log(Level.WARNING, "Could not fetch “" + uri + "”!", fe1); + return null; + } + } + } -- 2.7.4