+ errorAcc.add(target);
+ }
+
+ return errorAcc;
+ }
+
+ /**
+ * Open the resource next to the given {@link Class}.
+ *
+ * @param location
+ * the location where to look for the resource
+ * @param name
+ * the resource name (only the filename, no path)
+ *
+ * @return the opened resource if found, NULL if not
+ */
+ public static InputStream openResource(
+ @SuppressWarnings("rawtypes") Class location, String name) {
+ String loc = location.getName().replace(".", "/")
+ .replaceAll("/[^/]*$", "/");
+ return openResource(loc + name);
+ }
+
+ /**
+ * Open the given /-separated resource (from the binary root).
+ *
+ * @param name
+ * the resource name (the full path, with "/" as separator)
+ *
+ * @return the opened resource if found, NULL if not
+ */
+ public static InputStream openResource(String name) {
+ ClassLoader loader = IOUtils.class.getClassLoader();
+ if (loader == null) {
+ loader = ClassLoader.getSystemClassLoader();
+ }
+
+ return loader.getResourceAsStream(name);
+ }
+
+ /**
+ * Return a resetable {@link InputStream} from this stream, and reset it.
+ *
+ * @param in
+ * the input stream
+ * @return the resetable stream, which <b>may</b> be the same
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public static InputStream forceResetableStream(InputStream in)
+ throws IOException {
+ boolean resetable = in.markSupported();
+ if (resetable) {
+ try {
+ in.reset();
+ } catch (IOException e) {
+ resetable = false;
+ }
+ }
+
+ if (resetable) {
+ return in;
+ }
+
+ final File tmp = File.createTempFile(".tmp-stream.", ".tmp");
+ try {
+ write(in, tmp);
+ in.close();
+
+ return new MarkableFileInputStream(tmp) {
+ @Override
+ public void close() throws IOException {
+ try {
+ super.close();
+ } finally {
+ tmp.delete();
+ }
+ }
+ };
+ } catch (IOException e) {
+ tmp.delete();
+ throw e;
+ }
+ }
+
+ /**
+ * Convert the {@link InputStream} into a byte array.
+ *
+ * @param in
+ * the input stream
+ *
+ * @return the array
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public static byte[] toByteArray(InputStream in) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ write(in, out);
+ return out.toByteArray();
+ } finally {
+ out.close();
+ }
+ }
+
+ /**
+ * Convert the {@link File} into a byte array.
+ *
+ * @param file
+ * the input {@link File}
+ *
+ * @return the array
+ *
+ * @throws IOException
+ * in case of I/O error
+ */
+ public static byte[] toByteArray(File file) throws IOException {
+ FileInputStream fis = new FileInputStream(file);
+ try {
+ return toByteArray(fis);
+ } finally {
+ fis.close();