X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=basic%2Fruntime%2Forg.argeo.basic.nodeps%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2FStreamUtils.java;fp=basic%2Fruntime%2Forg.argeo.basic.nodeps%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2FStreamUtils.java;h=10af68fa42f0862e72f477c18035b9af37eb55d2;hb=9de5b5babb1d3676b89ceed1e27b67f81c798625;hp=0000000000000000000000000000000000000000;hpb=f69fd2fc2195f457a7da1dba3fe4cb27c7ffdffb;p=lgpl%2Fargeo-commons.git diff --git a/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/StreamUtils.java b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/StreamUtils.java new file mode 100644 index 000000000..10af68fa4 --- /dev/null +++ b/basic/runtime/org.argeo.basic.nodeps/src/main/java/org/argeo/StreamUtils.java @@ -0,0 +1,43 @@ +package org.argeo; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** Utilities to be used when APache COmmons IO is not available. */ +public class StreamUtils { + + public static void copy(InputStream in, OutputStream out) + throws IOException { + byte[] buf = new byte[8192]; + while (true) { + int length = in.read(buf); + if (length < 0) + break; + out.write(buf, 0, length); + } + } + + public static void closeQuietly(InputStream in) { + if (in != null) + try { + in.close(); + } catch (Exception e) { + // + } + } + + public static void closeQuietly(OutputStream out) { + if (out != null) + try { + out.close(); + } catch (Exception e) { + // + } + } + + private StreamUtils() { + + } + +}