VLab Common 1.2

pl.psnc.vlab.util
Class FileTools

java.lang.Object
  extended by pl.psnc.vlab.util.FileTools

public class FileTools
extends java.lang.Object

FileTools class - set of utility methods on files.

Author:
Dominik Stoklosa (~osa~)
Email address
osa@man.poznan.pl

Field Summary
static java.lang.String FILE_SEPARATOR
          System file separator.
static java.lang.String gif
           
static java.lang.String HOME_DIRECTORY
          User home directory
static java.lang.String IMAGE_DIRECTORY
          Directory containing images
static java.lang.String jgx
           
static java.lang.String jpeg
           
static java.lang.String jpg
           
static java.lang.String LINE_SEPARATOR
          System line separator I.e.
static java.lang.String png
           
static java.lang.String tif
           
static java.lang.String tiff
           
static java.lang.String WORKING_DIRECTORY
          User working directory
 
Constructor Summary
FileTools()
           
 
Method Summary
static void closeIgnoringException(java.io.Closeable c)
          Close the given stream ignoring exceptions thrown
static boolean fileExists(java.io.File file)
          Check whether the specyfied file by this URL exists.
static boolean fileExists(java.lang.String fileName)
          Check whether the specyfied file by this URL exists.
static java.lang.String getBase(java.lang.String fileName)
          Get the file name without extension
static java.lang.String getBase(java.net.URL url)
          Get the url without extension
static java.lang.String getClassNameWithoutPackage(java.lang.Class<?> cl)
          Returns the classname without the package.
static byte[] getContent(java.io.File file)
          Reads the content of the given file into a byte array
static byte[] getContent(java.io.InputStream inputStream)
          Reads the content of the given input stream into a byte array
static java.lang.String getExtension(java.io.File f)
          Get the extension of a file.
static java.lang.String getExtension(java.lang.String fileName)
          Get the extension of a file by the file name
static java.lang.String getResourceName(java.lang.String resAbsolutePath)
          Get the resource name from its absolute path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

public static java.lang.String LINE_SEPARATOR
System line separator I.e. "\n" in Linux systems


FILE_SEPARATOR

public static java.lang.String FILE_SEPARATOR
System file separator. I.e. "/" in Linux systems


WORKING_DIRECTORY

public static java.lang.String WORKING_DIRECTORY
User working directory


HOME_DIRECTORY

public static java.lang.String HOME_DIRECTORY
User home directory


IMAGE_DIRECTORY

public static java.lang.String IMAGE_DIRECTORY
Directory containing images


jpeg

public static final java.lang.String jpeg
See Also:
Constant Field Values

jpg

public static final java.lang.String jpg
See Also:
Constant Field Values

gif

public static final java.lang.String gif
See Also:
Constant Field Values

tiff

public static final java.lang.String tiff
See Also:
Constant Field Values

tif

public static final java.lang.String tif
See Also:
Constant Field Values

png

public static final java.lang.String png
See Also:
Constant Field Values

jgx

public static final java.lang.String jgx
See Also:
Constant Field Values
Constructor Detail

FileTools

public FileTools()
Method Detail

getExtension

public static java.lang.String getExtension(java.io.File f)
Get the extension of a file.

Parameters:
f - the file to be checked
Returns:
file extension

getExtension

public static java.lang.String getExtension(java.lang.String fileName)
Get the extension of a file by the file name

Parameters:
fileName - file name
Returns:
file extension

getBase

public static java.lang.String getBase(java.lang.String fileName)
Get the file name without extension

Parameters:
fileName - name of the file
Returns:
file name without extension

getBase

public static java.lang.String getBase(java.net.URL url)
Get the url without extension

Parameters:
url - url to be converted
Returns:
url url to file without the file extension

fileExists

public static boolean fileExists(java.io.File file)
Check whether the specyfied file by this URL exists.

Parameters:
file - the File representation of the given file
Returns:
true if the file exists, false otherwise

fileExists

public static boolean fileExists(java.lang.String fileName)
Check whether the specyfied file by this URL exists.

Parameters:
fileName - the file name
Returns:
true if the file exists, false otherwise

getClassNameWithoutPackage

public static java.lang.String getClassNameWithoutPackage(java.lang.Class<?> cl)
Returns the classname without the package. Example: If the input class is java.lang.String than the return value is String.

Parameters:
cl - The class to inspect
Returns:
The classname

getResourceName

public static java.lang.String getResourceName(java.lang.String resAbsolutePath)
Get the resource name from its absolute path.

Parameters:
resAbsolutePath - resource absolute path
Returns:
resource name from its absolute path.

getContent

public static byte[] getContent(java.io.InputStream inputStream)
Reads the content of the given input stream into a byte array

Parameters:
inputStream - input stream (InputStream)
Returns:
content of the given input stream

getContent

public static byte[] getContent(java.io.File file)
Reads the content of the given file into a byte array

Parameters:
file - current file
Returns:
byte representation of the file content or null if error occurs

closeIgnoringException

public static void closeIgnoringException(java.io.Closeable c)
Close the given stream ignoring exceptions thrown

Parameters:
c - instance of Closeable interface

VLab Common 1.2

Copyright 2004 by VLAB Dominik Stoklosa.