Code formating and whitespace cleanup
[jpim.git] / src / de / j32 / pimstuff / conduit / FritzAddressbookConduit.java
index d894ae0..32a389a 100644 (file)
@@ -1,53 +1,68 @@
 package de.j32.pimstuff.conduit;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 
 import org.xml.sax.SAXException;
 
 import de.j32.avmfritz.FritzBox;
+import de.j32.util.Util;
 
-public class FritzAddressbookConduit
-       implements Conduit
+public class FritzAddressbookConduit implements Conduit
 {
-       FritzBox fb_;
-       
-       public FritzAddressbookConduit()
-               throws ConduitException
-       {
-               try {
-                       fb_ = new FritzBox(
-                                               Config.get("fritzbox-password"),
-                                               Config.get("fritzbox-url","http://fritz.box"));
-               } catch (SAXException e) {
-                       throw new ConduitException(e);
-               } catch (IOException e) {
-                       throw new ConduitException(e);
-               }
-       }
+    FritzBox fb_;
 
-       @Override
-       public Exporter exporter()
-               throws ConduitException
-       {
-               try {
-                       return new FritzAddressbookExporter(fb_.importAddressbook());
-               }
-               catch (IOException e) {
-                       throw new ConduitException(e);
-               }
-       }
+    public FritzAddressbookConduit() throws ConduitException
+    {
+        try {
+            fb_ = new FritzBox(Config.get("fritzbox-password"), Config.get(
+                    "fritzbox-url", "http://fritz.box"));
+        }
+        catch (SAXException e) {
+            throw new ConduitException(e);
+        }
+        catch (IOException e) {
+            throw new ConduitException(e);
+        }
+    }
 
-       @Override
-       public Importer importer()
-               throws ConduitException
-       {
-               try {
-                       return new FritzAddressbookImporter(fb_.exportAddressbook());
-               }
-               catch (IOException e) {
-                       throw new ConduitException(e);
-               } catch (SAXException e) {
-                       throw new ConduitException(e);
-               }
-       }
+    @Override
+    public Exporter exporter() throws ConduitException
+    {
+        OutputStream os = null;
+        FritzAddressbookExporter exporter = null;
+        try {
+            os = fb_.importAddressbook();
+            exporter = new FritzAddressbookExporter(os);
+        }
+        catch (IOException e) {
+            throw new ConduitException(e);
+        }
+        finally {
+            if (exporter == null) Util.nothrowClose(os);
+        }
+        return exporter;
+    }
+
+    @Override
+    public Importer importer() throws ConduitException
+    {
+        InputStream is = null;
+        FritzAddressbookImporter importer = null;
+        try {
+            is = fb_.exportAddressbook();
+            importer = new FritzAddressbookImporter(is);
+        }
+        catch (IOException e) {
+            throw new ConduitException(e);
+        }
+        catch (SAXException e) {
+            throw new ConduitException(e);
+        }
+        finally {
+            if (importer == null) Util.nothrowClose(is);
+        }
+        return importer;
+    }
 }