FileDocCategorySizeDatePackage
JavaUtils.javaAPI DocJava SE 6 API3335Tue Jun 10 00:23:04 BST 2008com.sun.org.apache.xml.internal.security.utils

JavaUtils

public class JavaUtils extends Object
A collection of different, general-purpose methods for JAVA-specific things
author
Christian Geuer-Pollmann

Fields Summary
static Logger
log
{@link java.util.logging} logging facility
Constructors Summary
private JavaUtils()


     
     // we don't allow instantiation
   
Methods Summary
public static byte[]getBytesFromFile(java.lang.String fileName)
Method getBytesFromFile

param
fileName
return
the bytes readed from the file
throws
FileNotFoundException
throws
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;
   
public static byte[]getBytesFromStream(java.io.InputStream inputStream)
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


      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;
   
public static voidwriteBytesToFilename(java.lang.String filename, byte[] bytes)
Method writeBytesToFilename

param
filename
param
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) {}