Return the URI that was ultimately downloaded.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 Nov 2010 09:12:29 +0000 (10:12 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 Nov 2010 09:12:29 +0000 (10:12 +0100)
src/main/java/net/pterodactylus/sone/core/FreenetInterface.java
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java

index 9ff3a12..83a3253 100644 (file)
@@ -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<FreenetURI, FetchResult> fetchUri(FreenetURI uri) {
                FetchResult fetchResult = null;
                FreenetURI currentUri = new FreenetURI(uri);
                while (true) {
                        try {
                                fetchResult = client.fetch(currentUri);
-                               return fetchResult;
+                               return new Pair<FreenetURI, FetchResult>(currentUri, fetchResult);
                        } catch (FetchException fe1) {
                                if (fe1.getMode() == FetchException.PERMANENT_REDIRECT) {
                                        currentUri = fe1.newURI;
index d84a1c4..13154a0 100644 (file)
@@ -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<FreenetURI, FetchResult> 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);
                        }