+ * Loads a Sone from an input stream.
+ *
+ * @param soneInputStream
+ * The input stream to load the Sone from
+ * @return The parsed Sone, or {@code null} if the Sone could not be parsed
+ */
+ public Sone loadSone(InputStream soneInputStream) {
+ Sone parsedSone = soneDownloader.parseSone(soneInputStream);
+ if (parsedSone == null) {
+ return null;
+ }
+ if (parsedSone.getInsertUri() != null) {
+ addLocalSone(parsedSone);
+ } else {
+ addSone(parsedSone);
+ }
+ return parsedSone;
+ }
+
+ /**
+ * Loads and updates the given Sone.
+ *
+ * @param sone
+ * The Sone to load
+ */
+ public void loadSone(final Sone sone) {
+ new Thread(new Runnable() {
+
+ @Override
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ FreenetURI realRequestUri = sone.getRequestUri().setMetaString(new String[] { "sone.xml" });
+ setSoneStatus(sone, SoneStatus.downloading);
+ try {
+ FetchResult fetchResult = freenetInterface.fetchUri(realRequestUri);
+ if (fetchResult == null) {
+ /* TODO - mark Sone as bad. */
+ return;
+ }
+ Sone parsedSone = soneDownloader.parseSone(sone, fetchResult, realRequestUri);
+ if (parsedSone != null) {
+ addSone(parsedSone);
+ }
+ } finally {
+ setSoneStatus(sone, (sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
+ }
+ }
+ }, "Sone Downloader").start();
+ }
+
+ /**