5df5e94370c93144c57083c3df55a614d866d054
[jpim.git] / src / de / j32 / pimstuff / Data.java
1 package de.j32.pimstuff;
2
3 import java.io.IOException;
4
5 import de.j32.pimstuff.conduit.Conduit;
6 import de.j32.pimstuff.conduit.ConduitException;
7 import de.j32.pimstuff.conduit.Exporter;
8 import de.j32.pimstuff.conduit.Importer;
9 import de.j32.pimstuff.data.EntryConsumer;
10 import de.j32.pimstuff.data.EntryProducer;
11 import de.j32.util.Util;
12
13 public class Data
14 {
15     public static void transfer(EntryProducer producer, EntryConsumer consumer)
16     {
17         // TODO: It would be more 'beautoful' to have the EntryProducer be an
18         // Iterable, but this is simpler ...
19         producer.sendTo(consumer);
20     }
21
22     public static void transfer(Conduit conduit, EntryConsumer consumer) throws ConduitException,
23             IOException
24     {
25         Importer importer = null;
26         try {
27             importer = conduit.importer();
28             transfer(importer, consumer);
29             importer.close();
30             importer = null;
31         }
32         finally {
33             Util.nothrowClose(importer);
34         }
35     }
36
37     public static void transfer(EntryProducer producer, Conduit conduit) throws ConduitException,
38             IOException
39     {
40         Exporter exporter = null;
41         try {
42             exporter = conduit.exporter();
43             transfer(producer, exporter);
44             exporter.close();
45             exporter = null;
46         }
47         finally {
48             Util.nothrowClose(exporter);
49         }
50     }
51 }