org.clazzes.util.io
Class IOUtil

java.lang.Object
  extended by org.clazzes.util.io.IOUtil

public class IOUtil
extends java.lang.Object

Author:
lech

Method Summary
static void copyStreams(java.io.InputStream is, java.io.OutputStream os)
          Copy all the data from an INputStream to an OutputStream.
static java.lang.String getFileBaseName(java.lang.String fileName)
           
static java.lang.String getFileExtension(java.lang.String fileName)
           
static byte readByte(java.io.InputStream is)
          Read one byte from the Stream.
static byte[] readByteArrayFromFile(java.io.File baFile)
          Reads a byte array from the given file
static byte[] readByteArrayFromFile(java.lang.String baFileName)
          Reads a byte array from the file with the given name
static byte[] readZeroTerminatedString(java.io.InputStream is, int maxLength)
          Read a 0x00 terminated String
static void writeToFile(java.io.File baFile, byte[] ba)
          Write the byte array to the given file
static void writeToFile(java.lang.String baFileName, byte[] ba)
          Write the byte array to the file with the given file name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readByte

public static byte readByte(java.io.InputStream is)
                     throws java.io.IOException
Read one byte from the Stream.

Parameters:
is -
Returns:
Throws:
java.lang.Exception
java.io.IOException

readZeroTerminatedString

public static byte[] readZeroTerminatedString(java.io.InputStream is,
                                              int maxLength)
                                       throws java.io.IOException
Read a 0x00 terminated String

Parameters:
is - The Stream to read from.
maxLength - The maximum amount of bytes to read.
Returns:
The Byte array containing the read String.
Throws:
java.io.IOException - if something goes wrong.

readByteArrayFromFile

public static byte[] readByteArrayFromFile(java.io.File baFile)
                                    throws java.io.IOException
Reads a byte array from the given file

Parameters:
baFile - File to read from
Returns:
A new byte array with all the data from the file.
Throws:
java.io.IOException - in case of any I/O Problem

writeToFile

public static void writeToFile(java.lang.String baFileName,
                               byte[] ba)
                        throws java.io.IOException
Write the byte array to the file with the given file name

Parameters:
baFileName - Name of the file to write the byte array to.
ba - Byte Array to write to the file.
Throws:
java.io.IOException - in case of any I/O Problem

writeToFile

public static void writeToFile(java.io.File baFile,
                               byte[] ba)
                        throws java.io.IOException
Write the byte array to the given file

Parameters:
baFile - File to write the byte array to.
ba - Byte Array to write to the file.
Throws:
java.io.IOException - in case of any I/O Problem

readByteArrayFromFile

public static byte[] readByteArrayFromFile(java.lang.String baFileName)
                                    throws java.io.IOException
Reads a byte array from the file with the given name

Parameters:
baFileName - Name of the file to read from
Returns:
A new byte array with all the data from the file.
Throws:
java.io.IOException - in case of any I/O Problem

copyStreams

public static void copyStreams(java.io.InputStream is,
                               java.io.OutputStream os)
                        throws java.io.IOException
Copy all the data from an INputStream to an OutputStream. The OutputStrema is flushed after the copy operation, but it is not closed in order to allow writing additional data.

Parameters:
is - The source of the data.
os - The destination of the data.
Throws:
java.io.IOException - Upon I/O errors.

getFileExtension

public static java.lang.String getFileExtension(java.lang.String fileName)
Parameters:
fileName - The name of a file possibly containing a file extension.
Returns:
The portion of the fileName after the last '.' character or null, if fileName contains no '.' character.

getFileBaseName

public static java.lang.String getFileBaseName(java.lang.String fileName)
Parameters:
fileName - The name of a file possibly containing a file extension.
Returns:
The portion of the file after up to and excluding the last '.' character or fileName as a whole, if fileName contains no '.' character.


Copyright © 2009. All Rights Reserved.