X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FFreenetInterface.java;h=9515876a868f78ee50c0d64f72b2c49fd1da1277;hp=4e8b49a41214e5c31830e7ae15871f230fdc3ba7;hb=036c6fa20ce11ce8093f46fc0fce1c1da1839789;hpb=2076d1e91d695ca41a1f925ee42e79f237df7e9c diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 4e8b49a..9515876 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -29,7 +29,6 @@ import java.util.logging.Logger; import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.TemporaryImage; -import net.pterodactylus.util.collection.Pair; import net.pterodactylus.util.logging.Logging; import com.db4o.ObjectContainer; @@ -101,13 +100,13 @@ public class FreenetInterface { * The URI to fetch * @return The result of the fetch, or {@code null} if an error occured */ - public Pair fetchUri(FreenetURI uri) { + public Fetched fetchUri(FreenetURI uri) { FetchResult fetchResult = null; FreenetURI currentUri = new FreenetURI(uri); while (true) { try { fetchResult = client.fetch(currentUri); - return new Pair(currentUri, fetchResult); + return new Fetched(currentUri, fetchResult); } catch (FetchException fe1) { if (fe1.getMode() == FetchException.PERMANENT_REDIRECT) { currentUri = fe1.newURI; @@ -302,6 +301,56 @@ public class FreenetInterface { } /** + * Container for a fetched URI and the {@link FetchResult}. + * + * @author David Roden + */ + public static class Fetched { + + /** The fetched URI. */ + private final FreenetURI freenetUri; + + /** The fetch result. */ + private final FetchResult fetchResult; + + /** + * Creates a new fetched URI. + * + * @param freenetUri + * The URI that was fetched + * @param fetchResult + * The fetch result + */ + public Fetched(FreenetURI freenetUri, FetchResult fetchResult) { + this.freenetUri = freenetUri; + this.fetchResult = fetchResult; + } + + // + // ACCESSORS + // + + /** + * Returns the fetched URI. + * + * @return The fetched URI + */ + public FreenetURI getFreenetUri() { + return freenetUri; + } + + /** + * Returns the fetch result. + * + * @return The fetch result + */ + public FetchResult getFetchResult() { + return fetchResult; + } + + } + + /** * Callback for USK watcher events. * * @author David ‘Bombe’ Roden