initial commit
[jpim.git] / src / de / j32 / util / Util.java
1 package de.j32.util;
2
3 import java.io.Closeable;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.OutputStream;
7 import java.util.Iterator;
8
9 public class Util {
10
11         public static <E> E nonnull(E ob) {
12                 if (ob == null)
13                         throw new NullPointerException();
14                 return ob;
15         }
16
17         public static void transfer(InputStream is, OutputStream os)
18                         throws IOException {
19                 byte[] buffer = new byte[16384];
20                 int len = -1;
21                 while ((len = is.read(buffer)) != -1)
22                         os.write(buffer, 0, len);
23         }
24
25         public static void nothrowClose(Closeable c) {
26                 if (c != null) {
27                         try {
28                                 c.close();
29                         } catch (IOException e) {}
30                 }
31         }
32         
33         public static <E> E first(Iterable<E> i)
34         {
35                 Iterator<E> it = i.iterator();
36                 if (it.hasNext())
37                         return it.next();
38                 return null;
39         }
40 }