db43919e14ea2568253b061de5ab109321c234d0
[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         {
13                 if (ob == null)
14                         throw new NullPointerException();
15                 return ob;
16         }
17
18         public static void transfer(InputStream is, OutputStream os)
19                         throws IOException
20         {
21                 byte[] buffer = new byte[16384];
22                 int len = -1;
23                 while ((len = is.read(buffer)) != -1)
24                         os.write(buffer, 0, len);
25         }
26
27         public static void nothrowClose(Closeable c)
28         {
29                 if (c != null) {
30                         try {
31                                 c.close();
32                         }
33                         catch (IOException e) {}
34                 }
35         }
36         
37         public static <E> E first(Iterable<E> i)
38         {
39                 Iterator<E> it = i.iterator();
40                 if (it.hasNext())
41                         return it.next();
42                 return null;
43         }
44 }