X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fde%2Fj32%2Fpimstuff%2Fconduit%2FFritzAddressbookConduit.java;h=32a389ac284d5db61e3bf1f8dff0514f82316dff;hb=e4126a1787b7045a53f6074e9ef15681c9f5fde4;hp=d894ae032e466bb264645ca4902f14b3b63a21b4;hpb=276d9a69fa796728169c2992921a1e4bd875f549;p=jpim.git diff --git a/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java b/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java index d894ae0..32a389a 100644 --- a/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java +++ b/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java @@ -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; + } }