com.griaule.grFinger
Class GrFingerAppletInstaller

java.lang.Object
  extended by com.griaule.grFinger.GrFingerAppletInstaller

public class GrFingerAppletInstaller
extends Object

This helper class sets up the required libraries in order to make GrFinger working on Java Applet environments. It's recomended to thoroughly check this class and the related documentation before working with it.

Version:
1.0
Author:
Griaule Tecnologia Ltda.

Field Summary
private static int bufferTransferSize
           
private static HashSet copyFiles
           
private  String directoryDest
           
private  String DllZipName
           
private static String fileSeparator
           
private  String installSourceDir
           
private static String pathSeparator
           
 
Constructor Summary
GrFingerAppletInstaller(String relativeUrlSource, String DllZipName)
          Creates a new GrFinger installer helper class object.
 
Method Summary
 void copyAndExtractZip()
          Extracts all the contents of the ZIP file into the temporary folder.
private static void copyInputStream(InputStream in, OutputStream out)
           
 void copyLicense(String licenseFile)
          Copies the given license files to the temporary folder.
 void copyURL(URL src, String dest)
          Copies a file.
static boolean deleteCopiedFiles()
          Tries to remove all the files that have been copied and/or extracted by the GrFingerAppletInstaller class.
 void finalize()
          Finalizes this instance of the GrFingerAppletInstaller, also removing the temporary files (required libraries and licenses) created.
static HashSet getCopiedFiles()
          Returns a HashSet with all the files that have been copied and/or extracted by the GrFingerAppletInstaller class.
 String getDestDirectory()
          Returns the temporary directory on which all file operations (copies and extractions) are executed.
 String getDllZipName()
          Returns the name of the default ZIP file used for file extraction.
 com.griaule.grFinger.GrFinger getGrFinger()
          Returns a GrFinger object.
 String getInstallSourceDir()
          Returns the default path used as the source for copying and/or extracting files.
 void loadDll(String dllName)
          Loads a DLL.
 void setDllZipName(String dllZipName)
          Sets the name of the default ZIP file used for file extraction.
 void setInstallSourceDir(String installSourceDir)
          Sets the default path used as the source for copying and/or extracting files.
 void unzip(String srcPath, String destPath, String srcZip)
          Extracts all the files in the given ZIP file, located in the given source path, to the given destination path.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

installSourceDir

private String installSourceDir

directoryDest

private String directoryDest

DllZipName

private String DllZipName

fileSeparator

private static String fileSeparator

pathSeparator

private static String pathSeparator

copyFiles

private static HashSet copyFiles

bufferTransferSize

private static int bufferTransferSize
Constructor Detail

GrFingerAppletInstaller

public GrFingerAppletInstaller(String relativeUrlSource,
                               String DllZipName)
                        throws IOException,
                               SecurityException
Creates a new GrFinger installer helper class object. This constructor receives the relative path where all the necessary files are located in the applet JAR archive and the ZIP filename (inside the JAR archive) contaning the required GrFinger DLL files. This constructor also sets the temporary directory on which all file operations (copies and extractions) will be executed.

Using a ZIP file to store the required files is a good practice, since it reduces the JAR download size in about 50%, while avoiding confusion between GrFinger DLLs and other DLLs your applet may use.

Parameters:
relativeUrlSource - Current relative URL where the required ZIP and license files can be found.
DllZipName - ZIP file name containing all DLL files required by GrFinger.
Throws:
IOException - If no temporary directory is available.
SecurityException - If applet is unable to update the library path to load GrFinger libraries.
Method Detail

loadDll

public void loadDll(String dllName)
             throws IOException,
                    SecurityException,
                    UnsatisfiedLinkError
Loads a DLL. If it can’t find the DLL in the system, it will extract all files from the ZIP file before trying to load the DLL again. It's recommended that only GrFinger libraries be loaded by this function. In case you need loading another system library, use System.loadLibrary().

Parameters:
dllName - The DLL name, without extension.
Throws:
SecurityException - If the DLL load failed because the applet doesn't have the required permissions.
UnsatisfiedLinkError - If the DLL was not found.
IOException - If an error occurred while extracting the files from the ZIP file.

copyAndExtractZip

public void copyAndExtractZip()
                       throws IOException
Extracts all the contents of the ZIP file into the temporary folder.

Throws:
IOException - If an error occurred while extracting the files from the ZIP file.

copyLicense

public void copyLicense(String licenseFile)
                 throws IOException
Copies the given license files to the temporary folder.

Parameters:
licenseFile - The name of the license file (xxxx.txt).
Throws:
IOException - If an error occurred while copying the files.

copyURL

public void copyURL(URL src,
                    String dest)
             throws IOException
Copies a file. Both source and destination are given as URLs.

Parameters:
src - The URL of the source file.
dest - The URL of the destination file. Must be a local directory.
Throws:
IOException - If an error occurred while copying the file.

unzip

public void unzip(String srcPath,
                  String destPath,
                  String srcZip)
           throws IOException
Extracts all the files in the given ZIP file, located in the given source path, to the given destination path. Both source and destination paths are given as URLs.

Parameters:
srcPath - ZIP file source URL.
destPath - ZIP file contents destination URL.
srcZip - ZIP file name.
Throws:
IOException - If an error occurred while extracting the files from the ZIP file.

copyInputStream

private static final void copyInputStream(InputStream in,
                                          OutputStream out)
                                   throws IOException
Throws:
IOException

getGrFinger

public com.griaule.grFinger.GrFinger getGrFinger()
                                          throws com.griaule.grFinger.GrErrorException
Returns a GrFinger object. This method is preferred instead of directly creating a GrFinger object, since it will go through all the necessary pre-requisite steps (regarding libraries and licenses). Creating a GrFinger object directly will lead to an initialization failure, due to the unsatisfied dependencies.

Returns:
A GrFinger object.
Throws:
GrErrorException - If GrFinger initialization fails.

finalize

public void finalize()
Finalizes this instance of the GrFingerAppletInstaller, also removing the temporary files (required libraries and licenses) created. This method must be called to correctly finalize the GrFinger library.

Overrides:
finalize in class Object

getDestDirectory

public String getDestDirectory()
Returns the temporary directory on which all file operations (copies and extractions) are executed.

Returns:
The temporary directory.

getCopiedFiles

public static HashSet getCopiedFiles()
Returns a HashSet with all the files that have been copied and/or extracted by the GrFingerAppletInstaller class. The HashSet contains File objects.

Returns:
A HashSet with File objects.

deleteCopiedFiles

public static boolean deleteCopiedFiles()
Tries to remove all the files that have been copied and/or extracted by the GrFingerAppletInstaller class. The HashSet returned by the getCopiedFiles method will be updated accordingly. If a file is in use, it will not be deleted. This method returns false if any of the files can't be removed.

Returns:
true if all files were deleted, false otherwise.

setDllZipName

public void setDllZipName(String dllZipName)
Sets the name of the default ZIP file used for file extraction.

Parameters:
dllZipName - The name of the default ZIP file used for file extraction.

getDllZipName

public String getDllZipName()
Returns the name of the default ZIP file used for file extraction.

Returns:
The name of the default ZIP file used for file extraction.

setInstallSourceDir

public void setInstallSourceDir(String installSourceDir)
Sets the default path used as the source for copying and/or extracting files.

Parameters:
installSourceDir - The default path used as the source for copying and/or extracting files.

getInstallSourceDir

public String getInstallSourceDir()
Returns the default path used as the source for copying and/or extracting files.

Returns:
The default path used as the source for copying and/or extracting files.