LEONARDI Application Composer - 8.9.0.40 by W4 S.A.

leon.misc
Class LyFileTools

java.lang.Object
  extended by leon.misc.LyFileTools

public class LyFileTools
extends java.lang.Object

This class offers general useful methods to manipulate files content.


Field Summary
static java.lang.String __VERSION
           
 
Constructor Summary
LyFileTools(LyEnvironment environment)
          Constructor.Only initializes the current environment with the given one.
 
Method Summary
static boolean compareTempFiles(java.lang.String fileName1, java.lang.String fileName2)
           compare if tempFiles could assumed to be the same
 java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory, boolean keepFileName)
           Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.
static java.lang.String decodeFile(LyEnvironment environment, java.lang.String encodingCharset, java.lang.String inputFileName, java.lang.String outputFileName)
          Decode the input file in the given output file with the given charset.
static java.lang.String encodeFile(LyEnvironment environment, java.lang.String encodingCharset, java.lang.String inputFileName, java.lang.String outputFileName)
          Encode the input file in the given output file with the given charset.
static java.lang.String getFileName(java.lang.String path)
          Extracts the filename from the specified PATH.
static java.lang.String getFileSuffix(java.lang.String path)
          Extracts the suffix (like .gif .doc) from the specified PATH.
static java.lang.String getMimeType(java.lang.String fileName)
          find a probable mimetype from file extension.
static java.lang.String getSuffixFromMimeType(java.lang.String mimeType)
          find a probable from file extension from given mimetype.
static java.lang.String native2ascii(LyEnvironment environment, boolean reverse, java.lang.String encodingCharset, java.lang.String inputFileName, java.lang.String outputFileName)
          Method to use the native2ascii Java tool.
static java.lang.String removeFileCounter(java.lang.String path)
          Extracts the suffix (like .gif .doc) from the specified PATH
static boolean replaceKey(LyEnvironment environment, java.io.Writer out, java.io.BufferedReader in, java.util.Hashtable<java.lang.String,java.lang.String> equivalent)
          Replaces all keys found in the in Buffer with the equivalent String value found in the equivalent Hashtable.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__VERSION

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

LyFileTools

public LyFileTools(LyEnvironment environment)
Constructor.Only initializes the current environment with the given one.

Parameters:
environment - The environment that must be used.
Method Detail

replaceKey

public static boolean replaceKey(LyEnvironment environment,
                                 java.io.Writer out,
                                 java.io.BufferedReader in,
                                 java.util.Hashtable<java.lang.String,java.lang.String> equivalent)
Replaces all keys found in the in Buffer with the equivalent String value found in the equivalent Hashtable.
Keys must be of this format: $KEY$. Other keys can be used in the replacement String. Keys cannot be cut between two lines. If a key is find in a line but not in the hashtable, it is replaced with an empty string.

Parameters:
environment - The environment within the operation occured.
out - The output file
in - The input file
equivalent - The hastable Key->Replacement String.
Returns:
true if everything was ok, false otherwise.

getFileName

public static java.lang.String getFileName(java.lang.String path)
Extracts the filename from the specified PATH.

Parameters:
path - input path
Returns:
the filename only

getFileSuffix

public static java.lang.String getFileSuffix(java.lang.String path)
Extracts the suffix (like .gif .doc) from the specified PATH.

Parameters:
path - input path
Returns:
the suffix only or null if it could not be found

removeFileCounter

public static java.lang.String removeFileCounter(java.lang.String path)
Extracts the suffix (like .gif .doc) from the specified PATH

Parameters:
path - input path
Returns:
the suffix only or null if it could not be found

encodeFile

public static java.lang.String encodeFile(LyEnvironment environment,
                                          java.lang.String encodingCharset,
                                          java.lang.String inputFileName,
                                          java.lang.String outputFileName)
Encode the input file in the given output file with the given charset.

Parameters:
environment - the application environment
encodingCharset - the charset used to encode the input file
inputFileName - the input file name
outputFileName - the output file name. If null the result of encoding is redirect to the current output stream.
Returns:
an error message if any, null otherwise

decodeFile

public static java.lang.String decodeFile(LyEnvironment environment,
                                          java.lang.String encodingCharset,
                                          java.lang.String inputFileName,
                                          java.lang.String outputFileName)
Decode the input file in the given output file with the given charset.

Parameters:
environment - the application environment
encodingCharset - the input file charset used to decode it
inputFileName - the input file name
outputFileName - the output file name. If null the result of encoding is redirect to the current output stream.
Returns:
an error message if any, null otherwise

native2ascii

public static java.lang.String native2ascii(LyEnvironment environment,
                                            boolean reverse,
                                            java.lang.String encodingCharset,
                                            java.lang.String inputFileName,
                                            java.lang.String outputFileName)
Method to use the native2ascii Java tool.
A JDK 1.5 or more must be specified in the variable: INI_JDK_HOME of the application ini file.
Java tool synopsis :
native2ascii [-reverse] [-encoding encoding_name] [inputfile [outputfile]]
-reverse:
Perform the reverse operation: convert a file with Latin-1 and/ or Unicode encoded characters to one with native-encoded characters.
-encoding encoding_name :
Specify the encoding name which is used by the conversion procedure. The default encoding is taken from System property file.encoding. The encoding_name string must be taken from the first column of the table of supported encodings in the Supported Encodings document.
inputfile:
The input file name. If, in addition, inputfile is omitted, standard input is used for input.
outputfile:
The output file name. If it is omitted, standard output is used for output.

Parameters:
environment - the application environment
reverse - indicates if the reverse operation has to be preformend or not
encodingCharset - the encoding charset
inputFileName - the input file name. If null, this method does nothing
outputFileName - the input file name. If null, write the result in the standard output.
Returns:
an error message if any, null otherwise

getMimeType

public static java.lang.String getMimeType(java.lang.String fileName)
find a probable mimetype from file extension.

Parameters:
fileName - fine path
Returns:
the mimetype if found or null if non valid arguments.

getSuffixFromMimeType

public static java.lang.String getSuffixFromMimeType(java.lang.String mimeType)
find a probable from file extension from given mimetype.

Parameters:
the - mimetype if found or null if non valid arguments.
Returns:
the file ext if any

createTempFile

public java.io.File createTempFile(java.lang.String prefix,
                                   java.lang.String suffix,
                                   java.io.File directory,
                                   boolean keepFileName)
                            throws java.io.IOException

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

Parameters:
prefix - The prefix string to be used in generating the file's name; must be at least three characters long
suffix - The suffix string to be used in generating the file's name; may be null, in which case the suffix ".tmp" will be used
directory - The directory in which the file is to be created, or null if the default temporary-file directory is to be used
keepFileName - Try to keep filename if possible, or
Returns:
An abstract pathname denoting a newly-created empty file
Throws:
java.lang.IllegalArgumentException - If the prefix argument contains fewer than three characters
java.io.IOException - If a file could not be created

compareTempFiles

public static boolean compareTempFiles(java.lang.String fileName1,
                                       java.lang.String fileName2)

compare if tempFiles could assumed to be the same

Parameters:
String - fileName1 first file
String - fileName2 second file
Returns:
true if files are equivalent

(c) January 2013 - W4 S.A.

Website: W4 S.A., contact us: support@w4global.com