org.placidus.file
Class FileHelper

java.lang.Object
  extended by org.placidus.file.FileHelper

public class FileHelper
extends java.lang.Object

Contains helperfunctions for File

Author:
ds

Constructor Summary
FileHelper()
           
 
Method Summary
static long getAdlerSum(java.lang.String fileName)
           
static long getCheckSum(java.lang.String fileName, java.util.zip.Checksum checkSum)
          This will calculate the given checksumtype of the filecontent for the given name
static long getCRC32Sum(java.lang.String fileName)
           
static java.io.File getFileForName(java.lang.String filename)
          This function creates a File object for the given filename with different methods to load it.
static java.lang.String getTempDir()
          Returns the temp-dir from system property "java.io.tmpdir".
static java.io.File save(java.io.File file, byte[] toSave)
          Used to save given bytes to given file object
static java.io.File save(java.lang.String fileName, byte[] toSave)
          This function saves the given bytes into the given filename
static java.io.File saveToTempDir(java.lang.String fileName, byte[] toSave)
          Saves the given byte array to filename in tempfolder
static java.io.File saveToTempFile(java.lang.String prefix, java.lang.String suffix, byte[] toSave)
          Saves the given byte array to filename in tempfolder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHelper

public FileHelper()
Method Detail

getFileForName

public static java.io.File getFileForName(java.lang.String filename)
                                   throws java.io.IOException,
                                          java.net.URISyntaxException
This function creates a File object for the given filename with different methods to load it. If you want to load a file from .jar files, use StreamHelper.getInputStreamForName(String)

Parameters:
filename - of new fileobject
Returns:
new fileobject
Throws:
java.io.IOException
java.net.URISyntaxException - if URL from resource is not formatted strictly according to to RFC2396 and cannot be converted to a URI

saveToTempDir

public static java.io.File saveToTempDir(java.lang.String fileName,
                                         byte[] toSave)
                                  throws java.io.IOException
Saves the given byte array to filename in tempfolder

Parameters:
fileName - filename to use in tempfolder
toSave - bytes to save
Returns:
returns the created File object
Throws:
java.io.IOException

saveToTempFile

public static java.io.File saveToTempFile(java.lang.String prefix,
                                          java.lang.String suffix,
                                          byte[] toSave)
                                   throws java.io.IOException
Saves the given byte array to filename in tempfolder

Parameters:
prefix - filename part
suffix - suffix part
toSave - bytes to save
Returns:
returns the created File object
Throws:
java.io.IOException

save

public static java.io.File save(java.lang.String fileName,
                                byte[] toSave)
                         throws java.io.IOException
This function saves the given bytes into the given filename

Parameters:
fileName - file to save
toSave - content to save
Returns:
returns the created File object
Throws:
java.io.IOException

save

public static java.io.File save(java.io.File file,
                                byte[] toSave)
                         throws java.io.IOException
Used to save given bytes to given file object

Parameters:
file - to save to
toSave - to save
Returns:
returns the given File object
Throws:
java.io.IOException

getCRC32Sum

public static long getCRC32Sum(java.lang.String fileName)
                        throws java.io.IOException,
                               java.net.URISyntaxException
Throws:
java.io.IOException
java.net.URISyntaxException
See Also:
with checksum = new CRC32

getAdlerSum

public static long getAdlerSum(java.lang.String fileName)
                        throws java.io.IOException,
                               java.net.URISyntaxException
Throws:
java.io.IOException
java.net.URISyntaxException
See Also:
with checksum = new Adler32

getCheckSum

public static long getCheckSum(java.lang.String fileName,
                               java.util.zip.Checksum checkSum)
                        throws java.io.IOException,
                               java.net.URISyntaxException
This will calculate the given checksumtype of the filecontent for the given name

Parameters:
fileName - to load and build checksum for
checkSum - checksum object to build sum
Returns:
checksum of file, 0 if inputstream for file can not be created
Throws:
java.io.IOException - content can not be read
java.net.URISyntaxException - if uri of fileName is not well formed

getTempDir

public static java.lang.String getTempDir()
Returns the temp-dir from system property "java.io.tmpdir".

Returns:
tempdirpath


Copyright © 2006 DS. All Rights Reserved.