From: David ‘Bombe’ Roden Date: Mon, 18 Oct 2010 11:33:00 +0000 (+0200) Subject: Add method to load a local Sone from Freenet. X-Git-Tag: 0.1-RC1~236 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=60882ec340d291f5e6a31aeb1fe9281dbe4efc9e;p=Sone.git Add method to load a local Sone from Freenet. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 6ecd5fc..c861fd1 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -330,6 +330,21 @@ public class Core extends AbstractService { * The request URI to load the Sone from */ public void loadSone(final String requestUri) { + loadSone(requestUri, null); + } + + /** + * Loads the Sone from the given request URI. The fetching of the data is + * performed in a new thread so this method returns immediately. If + * {@code insertUri} is not {@code null} the loaded Sone is converted into a + * local Sone and available using as any other local Sone. + * + * @param requestUri + * The request URI to load the Sone from + * @param insertUri + * The insert URI of the Sone + */ + public void loadSone(final String requestUri, final String insertUri) { new Thread(new Runnable() { @Override @@ -340,7 +355,12 @@ public class Core extends AbstractService { FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri); Sone parsedSone = soneDownloader.parseSone(null, fetchResult, realRequestUri); if (parsedSone != null) { - addSone(parsedSone); + if (insertUri != null) { + parsedSone.setInsertUri(new FreenetURI(insertUri)); + addLocalSone(parsedSone); + } else { + addSone(parsedSone); + } } } catch (MalformedURLException mue1) { logger.log(Level.INFO, "Could not create URI from “" + requestUri + "”.", mue1);