X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fj32%2Futil%2FUtil.java;fp=src%2Fmain%2Fjava%2Fde%2Fj32%2Futil%2FUtil.java;h=cd4efb8a5e20fcf32383806e3fcb6f7da630e6a0;hb=4c31953ffe274db62393de67740de5df70b06d33;hp=0000000000000000000000000000000000000000;hpb=5ac05364dc652686046f01849b810da6ffef1192;p=jpim.git diff --git a/src/main/java/de/j32/util/Util.java b/src/main/java/de/j32/util/Util.java new file mode 100644 index 0000000..cd4efb8 --- /dev/null +++ b/src/main/java/de/j32/util/Util.java @@ -0,0 +1,50 @@ +package de.j32.util; + +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Iterator; + +public class Util +{ + + public static E nonnull(E ob) + { + if (ob == null) throw new NullPointerException(); + return ob; + } + + public static void transfer(InputStream is, OutputStream os) + throws IOException + { + byte[] buffer = new byte[16384]; + int len = -1; + while ((len = is.read(buffer)) != -1) + os.write(buffer, 0, len); + } + + public static void nothrowClose(Closeable c) + { + if (c != null) { + try { + c.close(); + } + catch (IOException e) {} + } + } + + public static E first(Iterable i) + { + Iterator it = i.iterator(); + if (it.hasNext()) return it.next(); + return null; + } + + public static E first(Iterator it) + { + if (it.hasNext()) return it.next(); + return null; + } + +}