aboutsummaryrefslogtreecommitdiff
path: root/src/share/classes/com/sun/org/apache/xml/internal/security/utils/JavaUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/classes/com/sun/org/apache/xml/internal/security/utils/JavaUtils.java')
-rw-r--r--src/share/classes/com/sun/org/apache/xml/internal/security/utils/JavaUtils.java176
1 files changed, 90 insertions, 86 deletions
diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/utils/JavaUtils.java b/src/share/classes/com/sun/org/apache/xml/internal/security/utils/JavaUtils.java
index 52eb6ac55..540c722f4 100644
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/utils/JavaUtils.java
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/utils/JavaUtils.java
@@ -20,8 +20,6 @@
*/
package com.sun.org.apache.xml.internal.security.utils;
-
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -29,99 +27,105 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-
/**
* A collection of different, general-purpose methods for JAVA-specific things
* @author Christian Geuer-Pollmann
- *
*/
public class JavaUtils {
- /** {@link java.util.logging} logging facility */
+ /** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(JavaUtils.class.getName());
- private JavaUtils() {
- // we don't allow instantiation
- }
- /**
- * Method getBytesFromFile
- *
- * @param fileName
- * @return the bytes readed from the file
- *
- * @throws FileNotFoundException
- * @throws IOException
- */
- public static byte[] getBytesFromFile(String fileName)
- throws FileNotFoundException, IOException {
-
- byte refBytes[] = null;
-
- {
- FileInputStream fisRef = new FileInputStream(fileName);
- UnsyncByteArrayOutputStream baos = new UnsyncByteArrayOutputStream();
- byte buf[] = new byte[1024];
- int len;
-
- while ((len = fisRef.read(buf)) > 0) {
- baos.write(buf, 0, len);
- }
-
- refBytes = baos.toByteArray();
- }
-
- return refBytes;
- }
-
- /**
- * Method writeBytesToFilename
- *
- * @param filename
- * @param bytes
- */
- public static void writeBytesToFilename(String filename, byte[] bytes) {
-
- try {
- if (filename != null && bytes != null) {
- File f = new File(filename);
-
- FileOutputStream fos = new FileOutputStream(f);
-
- fos.write(bytes);
- fos.close();
- } else {
- if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "writeBytesToFilename got null byte[] pointed");
- }
- } catch (Exception ex) {}
- }
-
- /**
- * This method reads all bytes from the given InputStream till EOF and returns
- * them as a byte array.
- *
- * @param inputStream
- * @return the bytes readed from the stream
- *
- * @throws FileNotFoundException
- * @throws IOException
- */
- public static byte[] getBytesFromStream(InputStream inputStream) throws IOException {
-
- byte refBytes[] = null;
-
- {
- UnsyncByteArrayOutputStream baos = new UnsyncByteArrayOutputStream();
- byte buf[] = new byte[1024];
- int len;
-
- while ((len = inputStream.read(buf)) > 0) {
+ private JavaUtils() {
+ // we don't allow instantiation
+ }
+
+ /**
+ * Method getBytesFromFile
+ *
+ * @param fileName
+ * @return the bytes readed from the file
+ *
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ public static byte[] getBytesFromFile(String fileName)
+ throws FileNotFoundException, IOException {
+
+ byte refBytes[] = null;
+
+ FileInputStream fisRef = new FileInputStream(fileName);
+ try {
+ UnsyncByteArrayOutputStream baos = new UnsyncByteArrayOutputStream();
+ byte buf[] = new byte[1024];
+ int len;
+
+ while ((len = fisRef.read(buf)) > 0) {
+ baos.write(buf, 0, len);
+ }
+
+ refBytes = baos.toByteArray();
+ } finally {
+ fisRef.close();
+ }
+
+ return refBytes;
+ }
+
+ /**
+ * Method writeBytesToFilename
+ *
+ * @param filename
+ * @param bytes
+ */
+ public static void writeBytesToFilename(String filename, byte[] bytes) {
+
+ FileOutputStream fos = null;
+ try {
+ if (filename != null && bytes != null) {
+ File f = new File(filename);
+
+ fos = new FileOutputStream(f);
+
+ fos.write(bytes);
+ fos.close();
+ } else {
+ log.log(java.util.logging.Level.FINE, "writeBytesToFilename got null byte[] pointed");
+ }
+ } catch (IOException ex) {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException ioe) {}
+ }
+ }
+ }
+
+ /**
+ * This method reads all bytes from the given InputStream till EOF and
+ * returns them as a byte array.
+ *
+ * @param inputStream
+ * @return the bytes readed from the stream
+ *
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ public static byte[] getBytesFromStream(InputStream inputStream)
+ throws IOException {
+
+ byte refBytes[] = null;
+
+ UnsyncByteArrayOutputStream baos = new UnsyncByteArrayOutputStream();
+ byte buf[] = new byte[1024];
+ int len;
+
+ while ((len = inputStream.read(buf)) > 0) {
baos.write(buf, 0, len);
- }
-
- refBytes = baos.toByteArray();
- }
+ }
- return refBytes;
- }
+ refBytes = baos.toByteArray();
+ return refBytes;
+ }
}