Remove dependencies to Argeo Commons IO
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 1 Nov 2022 09:47:16 +0000 (10:47 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 1 Nov 2022 09:47:16 +0000 (10:47 +0100)
org.argeo.util/src/org/argeo/util/StreamUtils.java
swt/rcp/org.argeo.swt.specific.rcp/src/org/argeo/eclipse/ui/rcp/internal/rwt/RcpResourceManager.java

index 30404f1e4edc195b9270488b1b0ed41eb7056187..5e4e636fc45073f3615e5b9d6ce459bbc3c8ed3c 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.util;
 
 import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -44,6 +45,13 @@ public class StreamUtils {
                return count;
        }
 
+       public static byte[] toByteArray(InputStream in) throws IOException {
+               try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+                       copy(in, out);
+                       return out.toByteArray();
+               }
+       }
+
        public static void closeQuietly(InputStream in) {
                if (in != null)
                        try {
index 91109a9de436d38789ce52fd6ad3a4cf9806df0c..ac4217184138ec58c570892e2d414d35b72167c2 100644 (file)
@@ -7,17 +7,16 @@ import java.util.Collections;
 import java.util.Map;
 import java.util.TreeMap;
 
-import org.apache.commons.io.IOUtils;
+import org.argeo.util.StreamUtils;
 import org.eclipse.rap.rwt.service.ResourceManager;
 
 public class RcpResourceManager implements ResourceManager {
-       private Map<String, byte[]> register = Collections
-                       .synchronizedMap(new TreeMap<String, byte[]>());
+       private Map<String, byte[]> register = Collections.synchronizedMap(new TreeMap<String, byte[]>());
 
        @Override
        public void register(String name, InputStream in) {
                try {
-                       register.put(name, IOUtils.toByteArray(in));
+                       register.put(name, StreamUtils.toByteArray(in));
                } catch (IOException e) {
                        throw new RuntimeException("Cannot register " + name, e);
                }