com.sibvisions.util.type
Class FileUtil

java.lang.Object
  extended by com.sibvisions.util.type.FileUtil

public final class FileUtil
extends Object

The FileUtil contains file and filename dependent utility methods.


Method Summary
static long copy(File pSource, File pTarget)
          Copies one file into another file using java.nio Channels.
static long copy(InputStream pIn, boolean pCloseIn, OutputStream pOut, boolean pCloseOut)
          Copies the content of an InputStream to the desired OutputStream.
static long copy(InputStream pIn, OutputStream pOut)
          Copies the content of an InputStream to the desired OutputStream.
static byte[] getContent(InputStream pStream)
          Reads the content of an InputStream into a byte array.
static byte[] getContent(InputStreamReader pReader)
          Reads the content of an InputStreamReader into a byte array.
static String getExtension(String pPath)
          Gets the extension of an absolute file path.
static String getName(String pAbsolutePath)
          Gets the name of a file from an absolute path.
static File getNotExistingFile(File pFile)
          Gets a file that does not exist.
static String removeExtension(String pPath)
          Removes the file extension from a file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copy

public static long copy(InputStream pIn,
                        OutputStream pOut)
                 throws IOException
Copies the content of an InputStream to the desired OutputStream.

Parameters:
pIn - input stream with content
pOut - output stream
Returns:
the length of the InputStream.
Throws:
IOException - if it's not possible to read from the InputStream or write to the OutputStream

copy

public static long copy(InputStream pIn,
                        boolean pCloseIn,
                        OutputStream pOut,
                        boolean pCloseOut)
                 throws IOException
Copies the content of an InputStream to the desired OutputStream.

Parameters:
pIn - input stream with content
pCloseIn - true, if the input stream
pOut - output stream
pCloseOut - true, if the output stream
Returns:
the length of the InputStream.
Throws:
IOException - if it's not possible to read from the InputStream or write to the OutputStream

copy

public static long copy(File pSource,
                        File pTarget)
                 throws IOException
Copies one file into another file using java.nio Channels.

Parameters:
pSource - source file
pTarget - target file
Returns:
the length of the source file.
Throws:
IOException - if it's not possible to copy the file

getContent

public static byte[] getContent(InputStream pStream)
Reads the content of an InputStream into a byte array.

Parameters:
pStream - the input stream
Returns:
the content of the stream or null if an error occurs

getContent

public static byte[] getContent(InputStreamReader pReader)
Reads the content of an InputStreamReader into a byte array.

Parameters:
pReader - the input stream reader
Returns:
the content of the reader or null if an error occurs

removeExtension

public static String removeExtension(String pPath)
Removes the file extension from a file name.

Parameters:
pPath - the filename
Returns:
the filename without extension

getExtension

public static String getExtension(String pPath)
Gets the extension of an absolute file path.

Parameters:
pPath - the absolute path of a file
Returns:
the extension (text behind the last '.') or null if the path is null or has no extension

getNotExistingFile

public static File getNotExistingFile(File pFile)
Gets a file that does not exist. If the given file already exists, the file name built in the way "nameWithoutExtension[number].extension".

Parameters:
pFile - the desired file name
Returns:
a file that does not exist.

getName

public static String getName(String pAbsolutePath)
Gets the name of a file from an absolute path.

Parameters:
pAbsolutePath - the absolute path for a file
Returns:
the name of the file without path


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.