From: David ‘Bombe’ Roden Date: Fri, 5 Nov 2010 09:12:29 +0000 (+0100) Subject: Return the URI that was ultimately downloaded. X-Git-Tag: 0.2-RC1~28 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=52d670f5e47eb7417a5a82662416beeb39c9a774;p=Sone.git Return the URI that was ultimately downloaded. --- diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 9ff3a12..83a3253 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -24,6 +24,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.collection.Pair; import net.pterodactylus.util.logging.Logging; import com.db4o.ObjectContainer; @@ -83,13 +84,13 @@ public class FreenetInterface { * The URI to fetch * @return The result of the fetch, or {@code null} if an error occured */ - public FetchResult fetchUri(FreenetURI uri) { + public Pair fetchUri(FreenetURI uri) { FetchResult fetchResult = null; FreenetURI currentUri = new FreenetURI(uri); while (true) { try { fetchResult = client.fetch(currentUri); - return fetchResult; + return new Pair(currentUri, fetchResult); } catch (FetchException fe1) { if (fe1.getMode() == FetchException.PERMANENT_REDIRECT) { currentUri = fe1.newURI; diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index d84a1c4..13154a0 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -30,6 +30,7 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.collection.Pair; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.number.Numbers; @@ -119,13 +120,13 @@ public class SoneDownloader extends AbstractService { FreenetURI requestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" }); core.setSoneStatus(sone, SoneStatus.downloading); try { - FetchResult fetchResult = freenetInterface.fetchUri(requestUri); - if (fetchResult == null) { + Pair fetchResults = freenetInterface.fetchUri(requestUri); + if (fetchResults == null) { /* TODO - mark Sone as bad. */ return; } - logger.log(Level.FINEST, "Got %d bytes back.", fetchResult.size()); - Sone parsedSone = parseSone(sone, fetchResult, requestUri); + logger.log(Level.FINEST, "Got %d bytes back.", fetchResults.getRight().size()); + Sone parsedSone = parseSone(sone, fetchResults.getRight(), fetchResults.getLeft()); if (parsedSone != null) { core.updateSone(parsedSone); }