From 60882ec340d291f5e6a31aeb1fe9281dbe4efc9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 18 Oct 2010 13:33:00 +0200 Subject: [PATCH] Add method to load a local Sone from Freenet. --- .../java/net/pterodactylus/sone/core/Core.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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); -- 2.7.4