aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/at/gv
diff options
context:
space:
mode:
authorpdanner <pdanner@d688527b-c9ab-4aba-bd8d-4036d912da1d>2007-09-10 15:16:34 +0000
committerpdanner <pdanner@d688527b-c9ab-4aba-bd8d-4036d912da1d>2007-09-10 15:16:34 +0000
commit4e12d1df5daab1f7600fa3a58e6fc535375224ff (patch)
tree9391d309ef57e98c0d46833356b726b622926b36 /common/src/main/java/at/gv
parenteecee431bf1e766c8b4d8b744269e2b62a7dc2b8 (diff)
downloadmoa-id-spss-4e12d1df5daab1f7600fa3a58e6fc535375224ff.tar.gz
moa-id-spss-4e12d1df5daab1f7600fa3a58e6fc535375224ff.tar.bz2
moa-id-spss-4e12d1df5daab1f7600fa3a58e6fc535375224ff.zip
moved test classes, cashing of resolved entities
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@1002 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'common/src/main/java/at/gv')
-rw-r--r--common/src/main/java/at/gv/egovernment/moa/util/StreamUtils.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/common/src/main/java/at/gv/egovernment/moa/util/StreamUtils.java b/common/src/main/java/at/gv/egovernment/moa/util/StreamUtils.java
index a22f1c2a8..3b1a6b56b 100644
--- a/common/src/main/java/at/gv/egovernment/moa/util/StreamUtils.java
+++ b/common/src/main/java/at/gv/egovernment/moa/util/StreamUtils.java
@@ -3,6 +3,7 @@ package at.gv.egovernment.moa.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.PrintStream;
/**
@@ -88,10 +89,17 @@ public class StreamUtils {
* @throws IOException on any exception thrown
*/
public static byte[] readStream(InputStream in) throws IOException {
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ copyStream(in, out, null);
+
+ /*
ByteArrayOutputStream out = new ByteArrayOutputStream();
int b;
while ((b = in.read()) >= 0)
out.write(b);
+
+ */
in.close();
return out.toByteArray();
}
@@ -107,14 +115,51 @@ public class StreamUtils {
*/
public static String readStream(InputStream in, String encoding) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
+ copyStream(in, out, null);
+
+ /*
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
int b;
while ((b = in.read()) >= 0)
out.write(b);
+ */
in.close();
return out.toString(encoding);
}
/**
+ * Reads all data (until EOF is reached) from the given source to the
+ * destination stream. If the destination stream is null, all data is dropped.
+ * It uses the given buffer to read data and forward it. If the buffer is
+ * null, this method allocates a buffer.
+ *
+ * @param source The stream providing the data.
+ * @param destination The stream that takes the data. If this is null, all
+ * data from source will be read and discarded.
+ * @param buffer The buffer to use for forwarding. If it is null, the method
+ * allocates a buffer.
+ * @exception IOException If reading from the source or writing to the
+ * destination fails.
+ */
+ private static void copyStream(InputStream source, OutputStream destination, byte[] buffer) throws IOException {
+ if (source == null) {
+ throw new NullPointerException("Argument \"source\" must not be null.");
+ }
+ if (buffer == null) {
+ buffer = new byte[8192];
+ }
+
+ if (destination != null) {
+ int bytesRead;
+ while ((bytesRead = source.read(buffer)) >= 0) {
+ destination.write(buffer, 0, bytesRead);
+ }
+ } else {
+ while (source.read(buffer) >= 0);
+ }
+ }
+
+ /**
* Gets the stack trace of the <code>Throwable</code> passed in as a string.
* @param t The <code>Throwable</code>.
* @return a String representing the stack trace of the <code>Throwable</code>.