From: David ‘Bombe’ Roden Date: Tue, 12 Oct 2010 14:50:36 +0000 (+0200) Subject: Add method that fetches an URI. X-Git-Tag: 0.1-RC1~532 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=087cfe551f0e87ebb128820045bac5b2c04b6ac2;p=Sone.git Add method that fetches an URI. --- 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; + } + } + }