Skip navigation links


com.essbase.eas.utils
Class FileUtilities

java.lang.Object
  extended by com.essbase.eas.utils.FileUtilities


public final class FileUtilities
extends java.lang.Object

basic file operation utilities.

Since:
6.5.1
Version:
6.5.4
Author:
Joe Fernandez

Nested Class Summary
static class FileUtilities.FileErrorMessage
           

 

Field Summary
static int FILE_COPY_ERROR
           
static java.lang.String FILE_PREFIX
           
static java.lang.String FILE_SUFFIX
           
static int MB
          MB in bytes
static short NATIVE
           
static java.lang.String UNIX_SEPARATOR
           
static short UNKNOWN
           
static short UTF8
           
static java.lang.String WIN32_SEPARATOR
           
static java.lang.String XML_MESSAGESFILE
           

 

Constructor Summary
FileUtilities()
           

 

Method Summary
static java.util.zip.ZipOutputStream addEntriesToZipStream(java.util.zip.ZipOutputStream out, java.io.File[] files)
          Adds entries to the zip stream
static java.io.File allocateTempDirectory()
          Creates a valid name for a directory but does not create it.
static java.io.File byteArrayToTempFile(java.io.ByteArrayInputStream in)
           
static java.lang.String convertUnixTextToDos(java.lang.String s)
          Convert a string from the UNIX format of '\r' to "\r\n"
static boolean copyFile(java.io.File source, java.io.File destination)
          Copies a file from source to destination
static boolean copyFile(java.io.File source, java.io.File destination, boolean showError)
           
static java.io.File copyToTempFile(java.io.File source)
          Copies the file to a temp file
static java.io.File createFafFile(java.lang.String processId)
          A Faf file is created in the faf output dir and persists for the life of a background process
static java.io.File createNamedTempFile(java.lang.String name)
          Generates a temporary file in the form of java.io.tmpdir/easXXXXname where XXXX is a unique number generated from the createTempFile method
static java.io.File createTempDirectory()
          Creates a temp directory
static java.io.File createTempFile()
          Does the same thing as createTempFile(String prefix), but it specifies the prefix for you as "eas"
static java.io.File createTempFile(java.lang.String prefix)
          Creates a temp file with the prefix specified in the default temporary file directory for the operating system.
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix)
          Creates a temp file with the prefix and suffix specified in the default temporary file directory for the operating system.
static java.lang.String createTempFileName()
           
static boolean deleteFile(java.io.File file)
          Deletes the specified file
static boolean deleteFile(java.lang.String fileName)
          Deletes the specified file
static boolean deleteFiles(java.io.File[] files)
          Deletes the specified files
static java.lang.Object deSerializeObject(java.io.File file)
          Deserialize an object from the file
static boolean exists(java.lang.String filename)
           
static java.lang.String extractFileNameFromPath(java.lang.String filePath)
           
static java.lang.String extractLeafDirectoryFromPath(java.lang.String dirPath)
          Extracts the final subdirectory from the given directory
static java.io.ByteArrayOutputStream filesToByteStream(java.io.File[] files)
          Creates a byte output stream from a list of files
static java.io.ByteArrayOutputStream fileToByteArray(java.io.File file)
          Converts a file to a byte array stream
static java.lang.String fileToString(java.io.File file)
          This method is read the input UTF-8 file as a byte array and returns a Unicode string which contains the content of UTF-8 file
static java.lang.String getFileAsString(java.io.File file, java.lang.String charset)
           
static boolean isValueWithPathAndFileName(java.lang.String value)
           
static java.io.File listmodelToFile(RandomAccessFileListModel model, java.io.File outputFile, short encoding)
           
static void main(java.lang.String[] args)
           
static java.io.File messageToXmlFile(java.lang.String message)
           
static void openFile(java.io.File file)
          launches a file on windows platforms (Win95, Win98, WinNT 4.0 & 5.0)
static void openFile(java.io.File file, boolean wait)
          Opens a file
static byte[] readByteArray(java.io.File file)
           
static java.lang.String readFile(java.io.File file)
          Reads the file
static java.lang.String readFile(java.lang.String filename)
          Reads the file
static java.lang.String readFile(java.net.URL url, java.lang.String charset)
           
static boolean renameFile(java.io.File source, java.io.File target)
          Renames a file
static java.io.File serializeObject(java.lang.Object obj, java.lang.String fileName)
          Serializes an object to a file
static void showError(java.lang.String error)
           
static java.io.File stringListToFafFile(java.util.ArrayList stringList, java.lang.String processId)
          Creates a file from a list with the name of the process id
static java.io.File stringListToFile(java.util.ArrayList stringList)
          Writes a list of strings to a file.
static java.io.File stringListToFile(java.util.ArrayList stringList, java.io.File outputFile, short encoding)
          Writes a list of strings to a file
static java.io.File stringToFafFile(java.lang.String s, java.lang.String processId)
          A fire and forget file is put in the storage/output directory but needs to persist as long as the fire and forget process is stored in the mid-tier.
static java.io.File stringToFile(java.lang.String s)
           
static java.io.File stringToFile(java.lang.String s, java.io.File outputFile)
           
static java.io.File stringToFile(java.lang.String s, java.lang.String fileName)
           
static java.io.File tailFileToFile(java.io.File file, int tailSize)
          This method is used to read the last tailSize bytes of the contents of a file from the end of the file backwards.
static java.lang.String tailFileToString(java.io.File file, int tailSize)
          This method is used to read the last tailSize bytes of the contents of a file from the end of the file backwards.
static java.io.File utfToFile(java.lang.String s)
           
static java.io.File utfToFile(java.lang.String s, java.io.File outputFile)
           
static java.io.File utfToFile(java.lang.String s, java.lang.String fileName)
           
static boolean writeFile(java.io.File file, byte[] contents)
           
static boolean writeFile(java.io.File file, java.lang.String contents, short encoding)
          writes a file based on the encoding
static void writeFile(java.net.URL url, java.lang.String contents, java.lang.String charset)
           
static boolean writeFile2(java.io.File file, byte[] contents)
           
static boolean writeFile2(java.io.File file, byte[] contents, int length)
           
static boolean writeFile2(java.io.File file, java.lang.String contents, short encoding)
           
static boolean writeToFile(java.io.File file, java.lang.String contents, short encoding)
          Writes the contents to a file
static boolean writeToFile(java.io.File file, java.lang.String contents, short encoding, boolean append)
           
static boolean writeToFile(java.lang.String file, java.lang.String contents, short encoding)
          Writes the contents to a file
static java.io.File zipArrayToEntries(java.io.InputStream in)
           
static java.io.File[] zipArrayToFiles(java.io.InputStream in)
           
static java.io.File zipEntrytoFile(java.util.zip.ZipInputStream zin, java.util.zip.ZipEntry entry, java.io.File targetDir)
           

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

FILE_COPY_ERROR

public static final int FILE_COPY_ERROR
See Also:
Constant Field Values

UNIX_SEPARATOR

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

WIN32_SEPARATOR

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

XML_MESSAGESFILE

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

FILE_PREFIX

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

FILE_SUFFIX

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

MB

public static final int MB
MB in bytes
See Also:
Constant Field Values

NATIVE

public static final short NATIVE
See Also:
Constant Field Values

UTF8

public static final short UTF8
See Also:
Constant Field Values

UNKNOWN

public static final short UNKNOWN
See Also:
Constant Field Values

Constructor Detail

FileUtilities

public FileUtilities()

Method Detail

createTempFile

public static java.io.File createTempFile(java.lang.String prefix)
Creates a temp file with the prefix specified in the default temporary file directory for the operating system.
Parameters:
prefix - prefix for the file
Returns:
the file object

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix)
Creates a temp file with the prefix and suffix specified in the default temporary file directory for the operating system.
Parameters:
prefix - prefix for the temp file
suffix - suffix for the temp file
Returns:
the temp file

createTempFile

public static java.io.File createTempFile()
Does the same thing as createTempFile(String prefix), but it specifies the prefix for you as "eas"
Returns:
the temp file

createNamedTempFile

public static java.io.File createNamedTempFile(java.lang.String name)
Generates a temporary file in the form of java.io.tmpdir/easXXXXname where XXXX is a unique number generated from the createTempFile method
Parameters:
name - the file name
Returns:
the temp file

createFafFile

public static java.io.File createFafFile(java.lang.String processId)
A Faf file is created in the faf output dir and persists for the life of a background process
Parameters:
processId - process id
Returns:
a File object referencing a Fire and Forget results file

stringToFafFile

public static java.io.File stringToFafFile(java.lang.String s,
                                           java.lang.String processId)
                                    throws java.io.IOException
A fire and forget file is put in the storage/output directory but needs to persist as long as the fire and forget process is stored in the mid-tier. The file name is a work id with a .txt extension
Parameters:
s - String to be written to file
processId - the process id
Returns:
the output file
Throws:
java.io.IOException

stringListToFafFile

public static java.io.File stringListToFafFile(java.util.ArrayList stringList,
                                               java.lang.String processId)
                                        throws java.io.IOException
Creates a file from a list with the name of the process id
Parameters:
stringList - list of strings
processId - the process id
Returns:
the output file
Throws:
java.io.IOException

createTempDirectory

public static java.io.File createTempDirectory()
Creates a temp directory
Returns:
file that represents the created a directory

allocateTempDirectory

public static java.io.File allocateTempDirectory()
Creates a valid name for a directory but does not create it. Used when calling function must create directory.
Returns:
the file

filesToByteStream

public static java.io.ByteArrayOutputStream filesToByteStream(java.io.File[] files)
                                                       throws java.io.IOException
Creates a byte output stream from a list of files
Parameters:
files - the files to be converted
Returns:
output stream
Throws:
java.io.IOException

addEntriesToZipStream

public static java.util.zip.ZipOutputStream addEntriesToZipStream(java.util.zip.ZipOutputStream out,
                                                                  java.io.File[] files)
                                                           throws java.io.IOException
Adds entries to the zip stream
Parameters:
out - the zip output stream
files - the files to be added to the zip stream
Returns:
the zip output stream
Throws:
java.io.IOException

fileToByteArray

public static java.io.ByteArrayOutputStream fileToByteArray(java.io.File file)
                                                     throws java.io.IOException
Converts a file to a byte array stream
Parameters:
file - the file to be read
Returns:
byte array stream
Throws:
java.io.IOException

readByteArray

public static byte[] readByteArray(java.io.File file)

tailFileToString

public static java.lang.String tailFileToString(java.io.File file,
                                                int tailSize)
                                         throws java.io.IOException
This method is used to read the last tailSize bytes of the contents of a file from the end of the file backwards. If the length of the file is smaller than the tailSize provided then the entire file contents are returned.
Parameters:
file - the file whose contents are to be read
tailSize - the position in the file to start reading
Returns:
String containing the text of the file
Throws:
java.io.IOException

tailFileToFile

public static java.io.File tailFileToFile(java.io.File file,
                                          int tailSize)
                                   throws java.io.IOException
This method is used to read the last tailSize bytes of the contents of a file from the end of the file backwards. If the length of the file is smaller than the tailSize provided then the entire file contents are returned.
Parameters:
file - the file whose contents are to be read
tailSize - the position in the file to start reading
Returns:
File containing the tail of the file
Throws:
java.io.IOException

fileToString

public static java.lang.String fileToString(java.io.File file)
                                     throws java.io.IOException
This method is read the input UTF-8 file as a byte array and returns a Unicode string which contains the content of UTF-8 file
Parameters:
file - the UTF-8 file whose contents are to be read
Returns:
String containing the tail contents of the file
Throws:
java.io.IOException

messageToXmlFile

public static java.io.File messageToXmlFile(java.lang.String message)
                                     throws java.io.IOException
Throws:
java.io.IOException

utfToFile

public static java.io.File utfToFile(java.lang.String s,
                                     java.lang.String fileName)
                              throws java.io.IOException
Throws:
java.io.IOException

utfToFile

public static java.io.File utfToFile(java.lang.String s)
                              throws java.io.IOException
Throws:
java.io.IOException

utfToFile

public static java.io.File utfToFile(java.lang.String s,
                                     java.io.File outputFile)
                              throws java.io.IOException
Throws:
java.io.IOException

stringToFile

public static java.io.File stringToFile(java.lang.String s)
                                 throws java.io.IOException
Throws:
java.io.IOException

stringToFile

public static java.io.File stringToFile(java.lang.String s,
                                        java.lang.String fileName)
                                 throws java.io.IOException
Throws:
java.io.IOException

stringToFile

public static java.io.File stringToFile(java.lang.String s,
                                        java.io.File outputFile)
                                 throws java.io.IOException
Throws:
java.io.IOException

byteArrayToTempFile

public static java.io.File byteArrayToTempFile(java.io.ByteArrayInputStream in)
                                        throws java.io.IOException
Throws:
java.io.IOException

zipArrayToEntries

public static java.io.File zipArrayToEntries(java.io.InputStream in)
                                      throws java.io.IOException
Throws:
java.io.IOException

zipArrayToFiles

public static java.io.File[] zipArrayToFiles(java.io.InputStream in)
                                      throws java.io.IOException
Throws:
java.io.IOException

exists

public static boolean exists(java.lang.String filename)

isValueWithPathAndFileName

public static boolean isValueWithPathAndFileName(java.lang.String value)
Parameters:
value - should be absolute path with file name
Returns:
if value is not provided as described above, then this method will return false, otherwise true

zipEntrytoFile

public static java.io.File zipEntrytoFile(java.util.zip.ZipInputStream zin,
                                          java.util.zip.ZipEntry entry,
                                          java.io.File targetDir)
                                   throws java.io.IOException
Throws:
java.io.IOException

extractFileNameFromPath

public static java.lang.String extractFileNameFromPath(java.lang.String filePath)

extractLeafDirectoryFromPath

public static java.lang.String extractLeafDirectoryFromPath(java.lang.String dirPath)
Extracts the final subdirectory from the given directory
Parameters:
dirPath - directory path
Returns:
the leaf directory

renameFile

public static boolean renameFile(java.io.File source,
                                 java.io.File target)
                          throws java.io.IOException
Renames a file
Parameters:
source - the source file path
target - the target file path
Returns:
true if successful
Throws:
java.io.IOException

openFile

public static void openFile(java.io.File file)
                     throws java.io.IOException
launches a file on windows platforms (Win95, Win98, WinNT 4.0 & 5.0)
Parameters:
file - a file to be viewed
Throws:
java.io.IOException

openFile

public static void openFile(java.io.File file,
                            boolean wait)
                     throws java.io.IOException
Opens a file
Parameters:
file - the file
wait - true to wait
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)

convertUnixTextToDos

public static java.lang.String convertUnixTextToDos(java.lang.String s)
Convert a string from the UNIX format of '\r' to "\r\n"
Parameters:
s - string to be converted
Returns:
converted string

readFile

public static java.lang.String readFile(java.lang.String filename)
Reads the file
Parameters:
filename - file to be read
Returns:
the file content as a string

readFile

public static java.lang.String readFile(java.io.File file)
Reads the file
Parameters:
file - file to be read
Returns:
the file content as a string

readFile

public static java.lang.String readFile(java.net.URL url,
                                        java.lang.String charset)
                                 throws java.io.IOException
Throws:
java.io.IOException

writeFile

public static void writeFile(java.net.URL url,
                             java.lang.String contents,
                             java.lang.String charset)
                      throws java.io.IOException
Throws:
java.io.IOException

copyToTempFile

public static java.io.File copyToTempFile(java.io.File source)
                                   throws java.io.IOException
Copies the file to a temp file
Parameters:
source - source file
Returns:
the temp file
Throws:
java.io.IOException

copyFile

public static boolean copyFile(java.io.File source,
                               java.io.File destination)
                        throws java.io.IOException
Copies a file from source to destination
Parameters:
source - the source file
destination - destination file
Returns:
true if successful
Throws:
java.io.IOException

copyFile

public static boolean copyFile(java.io.File source,
                               java.io.File destination,
                               boolean showError)
                        throws java.io.IOException
Throws:
java.io.IOException

showError

public static void showError(java.lang.String error)

serializeObject

public static java.io.File serializeObject(java.lang.Object obj,
                                           java.lang.String fileName)
Serializes an object to a file
Parameters:
obj - object to be serialized
fileName - the output file
Returns:
output file

deSerializeObject

public static java.lang.Object deSerializeObject(java.io.File file)
Deserialize an object from the file
Parameters:
file - file that contains the serialized information
Returns:
deserialized object

createTempFileName

public static java.lang.String createTempFileName()
                                           throws java.lang.Exception
Throws:
java.lang.Exception

writeFile

public static boolean writeFile(java.io.File file,
                                java.lang.String contents,
                                short encoding)
writes a file based on the encoding
Parameters:
file - file handle
contents - the data to be written
encoding - either NATIVE or UTF8
Returns:
true if successful

writeFile

public static boolean writeFile(java.io.File file,
                                byte[] contents)

writeToFile

public static boolean writeToFile(java.lang.String file,
                                  java.lang.String contents,
                                  short encoding)
                           throws java.io.IOException
Writes the contents to a file
Parameters:
file - output file
contents - contents for the file
encoding - encoding for file
Returns:
true if the write succeeeds
Throws:
java.io.IOException

writeToFile

public static boolean writeToFile(java.io.File file,
                                  java.lang.String contents,
                                  short encoding)
                           throws java.io.IOException
Writes the contents to a file
Parameters:
file - file
contents - contents
encoding - encoding for file
Returns:
true if the write succeeeds
Throws:
java.io.IOException

writeToFile

public static boolean writeToFile(java.io.File file,
                                  java.lang.String contents,
                                  short encoding,
                                  boolean append)
                           throws java.io.IOException
Throws:
java.io.IOException

stringListToFile

public static java.io.File stringListToFile(java.util.ArrayList stringList)
                                     throws java.io.IOException
Writes a list of strings to a file. Assume the encoding is NATIVE
Parameters:
stringList - list of strings
Returns:
the file
Throws:
java.io.IOException

stringListToFile

public static java.io.File stringListToFile(java.util.ArrayList stringList,
                                            java.io.File outputFile,
                                            short encoding)
                                     throws java.io.IOException
Writes a list of strings to a file
Parameters:
stringList - list of strings
outputFile - output file
encoding - encoding on the file
Returns:
the file
Throws:
java.io.IOException

listmodelToFile

public static java.io.File listmodelToFile(RandomAccessFileListModel model,
                                           java.io.File outputFile,
                                           short encoding)
                                    throws java.io.IOException
Throws:
java.io.IOException

deleteFiles

public static boolean deleteFiles(java.io.File[] files)
Deletes the specified files
Parameters:
files - files to be deleted
Returns:
true if successful

deleteFile

public static boolean deleteFile(java.lang.String fileName)
Deletes the specified file
Parameters:
fileName - file to be deleted
Returns:
true if successful

deleteFile

public static boolean deleteFile(java.io.File file)
Deletes the specified file
Parameters:
file - file to be deleted
Returns:
true if successful

getFileAsString

public static java.lang.String getFileAsString(java.io.File file,
                                               java.lang.String charset)
                                        throws java.io.IOException
Throws:
java.io.IOException

writeFile2

public static boolean writeFile2(java.io.File file,
                                 java.lang.String contents,
                                 short encoding)

writeFile2

public static boolean writeFile2(java.io.File file,
                                 byte[] contents)

writeFile2

public static boolean writeFile2(java.io.File file,
                                 byte[] contents,
                                 int length)

Skip navigation links


Copyright © 2001, 2012, Oracle. All rights reserved.