org.licas.util

## Class FileObject

- java.lang.Object
- - org.licas.util.FileObject

-     public class FileObject
      extends java.lang.Object

  This stores the details and contents for a file that can be represented by an instance of this class. The file path and optional Java class name is stored. The file contents are stored as a list of bytes, or as a string or xml-based representation.
  Author:
    Kieran Greer

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `asBytes` If true the contents can only be stored as a list of bytes.
    `protected java.lang.String` | `classType` This defines the class type
    `protected java.lang.Object` | `fileContents` The file contents
    `protected java.lang.String` | `filePath` This define the file path
    `protected java.lang.String` | `password` Password of either type to protect processing on a remote service, for example.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FileObject()` Creates a new instance of FileObject

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `addFileContents(java.lang.Object theFileContents)` Add the object passed in to the end of the file contents.
    `static java.io.File` | `checkFileType(java.io.File theFile, java.lang.String type)` Check the file type to make sure it is in the file name.
    `static java.lang.String` | `contentTypeFromCode(java.lang.String bodyStr)` Get the html content file type description from the content itself.
    `static java.lang.String` | `contentTypeFromFile(java.lang.String fileName)` Get the html content file type description from the file path.
    `static void` | `copyStream(java.io.File sourceFile, java.io.File destFile)` Copy the source input stream contents to the destination file.
    `static ByteArray` | `fileToByteArray(java.lang.String filePath)` Copy the source input stream contents to a list of Byte objects.
    `static java.util.ArrayList<java.lang.String>` | `getAllJarFilePaths(java.lang.String jarFile, java.lang.String serverIp)` Get the list of all required jar files for a particular jar class.
    `boolean` | `getAsBytes()` Get a value indicating that the file contents can only be stored as a byte list.
    `java.lang.String` | `getClassType()` Get the class type this file relates to.
    `static java.lang.String` | `getCurrentDirectory()` Get the current directory the program is running in.
    `static java.util.ArrayList<java.lang.String>` | `getDirectoryList(java.lang.String dirPath)` Get the list of directories stored in the specified directory.
    `java.lang.Object` | `getFileContents()` Get the contents of the file.
    `static java.util.ArrayList<java.lang.String>` | `getFileList(java.lang.String dirPath)` Get the list of files stored in the specified directory.
    `java.lang.String` | `getFilePath()` Get the file path.
    `static java.lang.String` | `getFileType(java.lang.String fileName)` Get the file type.
    `static java.util.ArrayList<java.lang.String>` | `getFullFileListPaths(java.lang.String dirPath)` Get the list of files stored in the specified directory.
    `static java.util.ArrayList<java.lang.String>` | `getFullFileListPaths(java.lang.String dirPath, boolean subFolders)` Get the list of files stored in the specified directory.
    `java.lang.String` | `getPassword()` Get the security password.
    `static boolean` | `isBinaryFile(java.lang.String fileName)` Return true if the file is binary, requiring a byte list.
    `static boolean` | `isHtmlFile(java.lang.String fileName)` Return true if the file path ends with a known internet file type.
    `static boolean` | `isImageFile(java.lang.String fileName)` Return true if the file path ends with a known image file type.
    `static boolean` | `isKnownApplicationType(java.lang.String dataType)` Return true if the data type is a known application type, for example 'Application/pdf', etc..
    `static boolean` | `isKnownBinaryType(java.lang.String dataType)` Return true if the data type is a known binary type, for example 'image,png', or 'Application/pdf', etc.
    `static boolean` | `isKnownDataType(java.lang.String dataType)` Return true if the data type is known, for example 'text/html', or 'image,png', etc.
    `static boolean` | `isKnownFile(java.lang.String fileName)` Return true if the file path end with a known file type.
    `static boolean` | `isKnownHtmlType(java.lang.String dataType)` Return true if the data type is a known html type, for example 'text/xhtml', etc.
    `static boolean` | `isKnownImageType(java.lang.String dataType)` Return true if the data type is a known image type, for example 'image,png', etc..
    `static boolean` | `isKnownTextType(java.lang.String dataType)` Return true if the data type is a known text type, for example 'text/html', etc.
    `static boolean` | `isKnownXmlType(java.lang.String dataType)` Return true if the data type is a known xml type, for example 'text/xml', etc.
    `static boolean` | `isTextFile(java.lang.String fileName)` Return true if the file path ends with a known text file type.
    `static boolean` | `isXmlFile(java.lang.String fileName)` Return true if the file path ends with a known xml file type.
    `void` | `loadFile(java.lang.String theFilePath)` Load the contents of the file specified by the path into an appropriate data structure.
    `static java.lang.String` | `removeFileType(java.lang.String fileName)` Remove the file type from the file name.
    `void` | `setAsBytes(boolean thisAsBytes)` Set a value indicating that the file contents can only be stored as a byte list and not in any other form.
    `void` | `setClassType(java.lang.String theClassType)` Set the class type this file relates to.
    `void` | `setFileContents(java.lang.Object theFileContents)` Set the contents of this file to the value passed in.
    `void` | `setFilePath(java.lang.String theFilePath)` Set the file path to the value passed in.
    `void` | `setPassword(java.lang.String thePassword)` Set the security password.
    `java.lang.String` | `toString()` Return a String description of this object.
    `protected boolean` | `useAsXmlFile(java.lang.String fileName)` Return true if an xml file representation should be used.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### filePath

          protected java.lang.String filePath

      This define the file path

    - #### classType

          protected java.lang.String classType

      This defines the class type

    - #### fileContents

          protected java.lang.Object fileContents

      The file contents

    - #### asBytes

          protected boolean asBytes

      If true the contents can only be stored as a list of bytes. If false, then xml or string-based representations are also possible. The default is false.

    - #### password

          protected java.lang.String password

      Password of either type to protect processing on a remote service, for example.

  - ### Constructor Detail

    - #### FileObject

          public FileObject()

      Creates a new instance of FileObject

  - ### Method Detail

    - #### setAsBytes

          public void setAsBytes(boolean thisAsBytes)

      Set a value indicating that the file contents can only be stored as a byte list and not in any other form.
      Parameters:
        `thisAsBytes` - true if the file contents can only be stored as a byte list.

    - #### getAsBytes

          public boolean getAsBytes()

      Get a value indicating that the file contents can only be stored as a byte list.
      Returns:
        the value of asBytes.

    - #### setFilePath

          public void setFilePath(java.lang.String theFilePath)

      Set the file path to the value passed in.
      Parameters:
        `theFilePath` - the file path.

    - #### getFilePath

          public java.lang.String getFilePath()

      Get the file path.
      Returns:
        the value of filePath.

    - #### setClassType

          public void setClassType(java.lang.String theClassType)

      Set the class type this file relates to.
      Parameters:
        `theClassType` - the class type.

    - #### getClassType

          public java.lang.String getClassType()

      Get the class type this file relates to.
      Returns:
        the value of classType.

    - #### setPassword

          public void setPassword(java.lang.String thePassword)

      Set the security password.
      Parameters:
        `thePassword` - the security password.

    - #### getPassword

          public java.lang.String getPassword()

      Get the security password.
      Returns:
        the value of password.

    - #### setFileContents

          public void setFileContents(java.lang.Object theFileContents)

      Set the contents of this file to the value passed in.
      Parameters:
        `theFileContents` - the file contents.

    - #### addFileContents

          public boolean addFileContents(java.lang.Object theFileContents)

      Add the object passed in to the end of the file contents.
      Parameters:
        `theFileContents` - can be either a String or a ArrayList of Bytes.
      Returns:
        true if added, false otherwise.

    - #### getFileContents

          public java.lang.Object getFileContents()

      Get the contents of the file.
      Returns:
        the value of fileContents.

    - #### isKnownDataType

          public static boolean isKnownDataType(java.lang.String dataType)

      Return true if the data type is known, for example 'text/html', or 'image,png', etc.
      Parameters:
        `dataType` - the data type, usually for a browser realisation.
      Returns:
        true if the data type is already known and does not need to be changed.

    - #### isKnownTextType

          public static boolean isKnownTextType(java.lang.String dataType)

      Return true if the data type is a known text type, for example 'text/html', etc.
      Parameters:
        `dataType` - the data type, usually for a browser realisation.
      Returns:
        true if the data type is already known and does not need to be changed.

    - #### isKnownHtmlType

          public static boolean isKnownHtmlType(java.lang.String dataType)

      Return true if the data type is a known html type, for example 'text/xhtml', etc.
      Parameters:
        `dataType` - the data type, usually for a browser realisation.
      Returns:
        true if the data type is already known and does not need to be changed.

    - #### isKnownXmlType

          public static boolean isKnownXmlType(java.lang.String dataType)

      Return true if the data type is a known xml type, for example 'text/xml', etc.
      Parameters:
        `dataType` - the data type, usually for a browser realisation.
      Returns:
        true if the data type is already known and does not need to be changed.

    - #### isKnownBinaryType

          public static boolean isKnownBinaryType(java.lang.String dataType)

      Return true if the data type is a known binary type, for example 'image,png', or 'Application/pdf', etc.
      Parameters:
        `dataType` - the data type, usually for a browser realisation.
      Returns:
        true if the data type is already known and does not need to be changed.

    - #### isKnownImageType

          public static boolean isKnownImageType(java.lang.String dataType)

      Return true if the data type is a known image type, for example 'image,png', etc..
      Parameters:
        `dataType` - the data type, usually for a browser realisation.
      Returns:
        true if the data type is already known and does not need to be changed.

    - #### isKnownApplicationType

          public static boolean isKnownApplicationType(java.lang.String dataType)

      Return true if the data type is a known application type, for example 'Application/pdf', etc..
      Parameters:
        `dataType` - the data type, usually for a browser realisation.
      Returns:
        true if the data type is already known and does not need to be changed.

    - #### isKnownFile

          public static boolean isKnownFile(java.lang.String fileName)

      Return true if the file path end with a known file type. The path itself might not be correct, but it ends with a known file type nameOnly.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        true if it indicates a known file type.

    - #### isTextFile

          public static boolean isTextFile(java.lang.String fileName)

      Return true if the file path ends with a known text file type. That is, something that is not binary but is in ascii text format. The path itself might not be correct, but it ends with a known file type nameOnly.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        true if it indicates a known text file type.

    - #### isBinaryFile

          public static boolean isBinaryFile(java.lang.String fileName)

      Return true if the file is binary, requiring a byte list.
      Parameters:
        `fileName` - the file path or name.
      Returns:
        true if byte list required, false otherwise.

    - #### isXmlFile

          public static boolean isXmlFile(java.lang.String fileName)

      Return true if the file path ends with a known xml file type. The path itself might not be correct, but it ends with a known file type nameOnly.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        true if it indicates a known xml file type.

    - #### isImageFile

          public static boolean isImageFile(java.lang.String fileName)

      Return true if the file path ends with a known image file type. The path itself might not be correct, but it ends with a known file type nameOnly.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        true if it indicates a known image file type.

    - #### isHtmlFile

          public static boolean isHtmlFile(java.lang.String fileName)

      Return true if the file path ends with a known internet file type. The path itself might not be correct, but it ends with a known file type nameOnly. Not every type is included.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        true if it indicates a known internet file type.

    - #### useAsXmlFile

          protected boolean useAsXmlFile(java.lang.String fileName)

      Return true if an xml file representation should be used.
      Parameters:
        `fileName` - the file path or name.
      Returns:
        true if the file type indicates an xml file and binary has not already been specified.

    - #### getFileType

          public static java.lang.String getFileType(java.lang.String fileName)

      Get the file type.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        the nameOnly, or content after the last '.'.

    - #### removeFileType

          public static java.lang.String removeFileType(java.lang.String fileName)

      Remove the file type from the file name.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        the filename, or content before the last '.'.

    - #### contentTypeFromFile

          public static java.lang.String contentTypeFromFile(java.lang.String fileName)

      Get the html content file type description from the file path.
      Parameters:
        `fileName` - the file name or full file path.
      Returns:
        the content type, to add to an http message resource.

    - #### contentTypeFromCode

          public static java.lang.String contentTypeFromCode(java.lang.String bodyStr)

      Get the html content file type description from the content itself. This is used for specific cases only.
      Parameters:
        `bodyStr` - the file content as a string.
      Returns:
        the content type, to add to an http message resource.

    - #### loadFile

          public void loadFile(java.lang.String theFilePath)
                        throws java.lang.Exception

      Load the contents of the file specified by the path into an appropriate data structure.
      Parameters:
        `theFilePath` - the local path of the file to load.
      Throws:
        `java.lang.Exception` - any error.

    - #### fileToByteArray

          public static ByteArray fileToByteArray(java.lang.String filePath)

      Copy the source input stream contents to a list of Byte objects.
      Parameters:
        `filePath` - the file path in string format.
      Returns:
        the source stream as a list of Byte objects.

    - #### copyStream

          public static void copyStream(java.io.File sourceFile,
                                        java.io.File destFile)
                                 throws java.lang.Exception

      Copy the source input stream contents to the destination file.
      Parameters:
        `sourceFile` - the file to copy.
        `destFile` - the file path to copy to
      Throws:
        `java.lang.Exception` - any error.

    - #### getCurrentDirectory

          public static java.lang.String getCurrentDirectory()
                                                      throws java.lang.Exception

      Get the current directory the program is running in.
      Returns:
        the directory path in String format.
      Throws:
        `java.lang.Exception` - any error.

    - #### getDirectoryList

          public static java.util.ArrayList<java.lang.String> getDirectoryList(java.lang.String dirPath)

      Get the list of directories stored in the specified directory.
      Parameters:
        `dirPath` - the directory path.
      Returns:
        a list of all directories stored under this directory.

    - #### getFileList

          public static java.util.ArrayList<java.lang.String> getFileList(java.lang.String dirPath)
                                                                   throws java.lang.Exception

      Get the list of files stored in the specified directory.
      Parameters:
        `dirPath` - the directory path.
      Returns:
        a list of all files stored under this directory.
      Throws:
        `java.lang.Exception` - any error.

    - #### getFullFileListPaths

          public static java.util.ArrayList<java.lang.String> getFullFileListPaths(java.lang.String dirPath)
                                                                            throws java.lang.Exception

      Get the list of files stored in the specified directory.
      Parameters:
        `dirPath` - the directory path.
      Returns:
        a list of all files in the directory. This is the full file names, with paths.
      Throws:
        `java.lang.Exception` - any error.

    - #### getFullFileListPaths

          public static java.util.ArrayList<java.lang.String> getFullFileListPaths(java.lang.String dirPath,
                                                                                   boolean subFolders)
                                                                            throws java.lang.Exception

      Get the list of files stored in the specified directory.
      Parameters:
        `dirPath` - the directory path.
        `subFolders` - if true include all files in all sub-folders, if false include files in the current folder only.
      Returns:
        a list of all files in the directory. This is the full file names, with paths.
      Throws:
        `java.lang.Exception` - any error.

    - #### getAllJarFilePaths

          public static java.util.ArrayList<java.lang.String> getAllJarFilePaths(java.lang.String jarFile,
                                                                                 java.lang.String serverIp)
                                                                          throws java.lang.Exception

      Get the list of all required jar files for a particular jar class.
      Parameters:
        `jarFile` - the path for the base jar file.
        `serverIp` - the server ip address.
      Returns:
        the base jar file formatted, together with any in its lib folder.
      Throws:
        `java.lang.Exception` - any error.

    - #### checkFileType

          public static java.io.File checkFileType(java.io.File theFile,
                                                   java.lang.String type)

      Check the file type to make sure it is in the file name.
      Parameters:
        `theFile` - the file object with the full file path.
        `type` - the file type that should be indicated.
      Returns:
        the same file object with a filename ending with the file type.

    - #### toString

          public java.lang.String toString()

      Return a String description of this object.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the values as a String.