Add method to delegate Sone parsing.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 49cbc8a..e0f2649 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sone.core;
 
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -438,6 +439,26 @@ public class Core extends AbstractService {
        }
 
        /**
+        * 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
@@ -626,7 +647,7 @@ public class Core extends AbstractService {
                                SoneInserter.setInsertionDelay(newValue);
                        }
 
-               })).set(configuration.getIntValue("Option/InsertionDelay").getValue(null));
+               }));
 
                options.addBooleanOption("ClearOnNextRestart", new DefaultOption<Boolean>(false)).set(configuration.getBooleanValue("Option/ClearOnNextRestart").getValue(null));
                options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption<Boolean>(false)).set(configuration.getBooleanValue("Option/ReallyClearOnNextRestart").getValue(null));
@@ -639,6 +660,8 @@ public class Core extends AbstractService {
                        return;
                }
 
+               options.getIntegerOption("InsertionDelay").set(configuration.getIntValue("Option/InsertionDelay").getValue(null));
+
                /* parse local Sones. */
                logger.log(Level.INFO, "Loading Sones…");
                int soneId = 0;