SimpleFile (SelekTOR Java Documentation)
Date: 2018-05-25

lib

## Class SimpleFile

- java.lang.Object
- - lib.SimpleFile

-     public class SimpleFile
      extends java.lang.Object

  Author:
    Alistair Neil info@dazzleships.net

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `FILEDELETEFAIL`
    `static int` | `FILEDELETEOK`
    `static int` | `NOTFOUND`
    `static int` | `PERIOD_DAYS`
    `static int` | `PERIOD_HOURS`
    `static int` | `PERIOD_MINUTES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleFile()`
    `SimpleFile(java.lang.String pathname)` Constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `addFilesToZip(java.io.File... srcfiles)` Add files to a zip file
    `void` | `closeFile()` Close file and any resources such as buffered readers/writers that are attached to it.
    `void` | `closeZipStream()` Close a zip stream
    `static void` | `compress(java.lang.String source, java.lang.String dest)`
    `static void` | `copyFolderContents(java.lang.String from, java.lang.String to, java.lang.String ignore)` Copy multiple files from one folder to another
    `static void` | `copyFromTo(java.lang.String frompath, java.lang.String topath)` Copy file to
    `boolean` | `createFile()` Create a new file
    `boolean` | `createFolder()` Creates a new folder
    `static boolean` | `createFolder(java.lang.String path)` Creates a new folder
    `boolean` | `delete()` Deletes file
    `static boolean` | `delete(java.lang.String filename)` Deletes the specified file
    `void` | `deleteFileList(java.io.File[] files)` Deletes the supplied list of files, be very carefull with this
    `static boolean` | `deleteFolder(java.lang.String folder)` Delete folder and its contents using specified folder path
    `boolean` | `exists()` Test to see if path exists
    `static boolean` | `exists(java.lang.String pathname)` Test to see if path exists
    `boolean` | `extractZipTo(java.lang.String destpath)` Extracts a zip file to a supplied location
    `void` | `flushWriter()`
    `static float` | `getAgeOfFile(java.lang.String filepath, int period)` Get the age of a specified file
    `java.io.File` | `getFile()` Get file
    `java.lang.String` | `getFileFilter()` Gets the current file filter
    `java.io.File[]` | `getFileList()` Gets the file list at the specified directory location based on filter contents
    `java.lang.String[]` | `getFilenames(int offset)` Returns an array of filenames, array if populated from the offset value onwards
    `java.io.File` | `getOldestFile()`
    `static java.lang.String` | `getSeparator()`
    `static boolean` | `isDaysOlder(java.lang.String filename, long days)` Test to see our file is older in days, returns true if it is
    `static boolean` | `isHoursOlder(java.lang.String filename, long hours)` Test to see our file is older in hours, returns true if it is
    `static boolean` | `isMinutesOlder(java.lang.String filename, long minutes)` Test to see our file is older in minutes, returns true if it is
    `static void` | `mergeFiles(java.lang.String srcpath1, java.lang.String srcpath2, java.lang.String destpath)`
    `static java.lang.Object` | `objectRead(java.lang.String filepath, java.lang.Object defObject)`
    `static boolean` | `objectWrite(java.lang.String filepath, java.lang.Object o)`
    `void` | `openBufferedAppend()` Opens a buffered file for append
    `java.io.BufferedReader` | `openBufferedRead()` Opens a buffered file for read
    `void` | `openBufferedResource()` Use this if you need access to a file within a jar
    `void` | `openBufferedWrite()` Opens a buffered file for write
    `java.io.FileInputStream` | `openFileInputStream(java.lang.String filename)`
    `java.io.FileOutputStream` | `openFileOutputStream()` Opens a file output stream
    `boolean` | `openZipStream(int level)` Opens a zipstream.
    `java.lang.String` | `readEntireFile()` Read bytes from previously opened BufferedReader
    `java.lang.String` | `readLine()` Read a single line from a text file
    `boolean` | `renameFile(java.lang.String toname)`
    `static java.io.File` | `renameTo(java.io.File f, java.lang.String newname)`
    `static void` | `secureWipe(java.io.File f)` Wipe file using specified File
    `static void` | `secureWipe(java.lang.String filename)` Wipe file using specified filename
    `static void` | `secureWipeFolder(java.io.File folder)` Wipe folder and its contents using specified File
    `static void` | `secureWipeFolder(java.lang.String folder)` Wipe folder and its contents using specified folder path
    `void` | `setFile(java.io.File file)` Set file
    `void` | `setFileFilter(java.lang.String filter)` Sets the file filter
    `void` | `setFileName(java.lang.String pathname)` Set filename
    `static void` | `walkFileTree(java.lang.String path, java.util.ArrayList<java.io.File> files)`
    `static void` | `walkFileTree(java.lang.String path, java.util.ArrayList<java.io.File> files, java.lang.String filter)`
    `void` | `writeFile(char[] data, int nochars)` Write to a previously opened output file
    `void` | `writeFile(java.lang.String data, int newlines)` Write to a previously opened output file

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

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

- - ### Field Detail

    - #### PERIOD_MINUTES

          public static final int PERIOD_MINUTES

      See Also:
        Constant Field Values

    - #### PERIOD_HOURS

          public static final int PERIOD_HOURS

      See Also:
        Constant Field Values

    - #### PERIOD_DAYS

          public static final int PERIOD_DAYS

      See Also:
        Constant Field Values

    - #### NOTFOUND

          public static final int NOTFOUND

      See Also:
        Constant Field Values

    - #### FILEDELETEOK

          public static final int FILEDELETEOK

      See Also:
        Constant Field Values

    - #### FILEDELETEFAIL

          public static final int FILEDELETEFAIL

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SimpleFile

          public SimpleFile()

    - #### SimpleFile

          public SimpleFile(java.lang.String pathname)

      Constructor
      Parameters:
        `pathname` -

  - ### Method Detail

    - #### setFileName

          public final void setFileName(java.lang.String pathname)

      Set filename
      Parameters:
        `pathname` -

    - #### setFile

          public final void setFile(java.io.File file)

      Set file
      Parameters:
        `file` -

    - #### getFile

          public final java.io.File getFile()

      Get file
      Returns:
        file

    - #### closeFile

          public final void closeFile()

      Close file and any resources such as buffered readers/writers that are attached to it.

    - #### setFileFilter

          public final void setFileFilter(java.lang.String filter)

      Sets the file filter
      Parameters:
        `filter` -

    - #### getFileFilter

          public final java.lang.String getFileFilter()

      Gets the current file filter
      Returns:
        Returns the file filter

    - #### getSeparator

          public static final java.lang.String getSeparator()

    - #### createFolder

          public final boolean createFolder()

      Creates a new folder
      Returns:
        True if successful

    - #### createFolder

          public static final boolean createFolder(java.lang.String path)

      Creates a new folder
      Parameters:
        `path` - The location of the new folder
      Returns:
        True if successful

    - #### createFile

          public final boolean createFile()

      Create a new file
      Returns:
        True if file exist or is created

    - #### getFileList

          public final java.io.File[] getFileList()

      Gets the file list at the specified directory location based on filter contents
      Returns:
        An array of Files

    - #### getOldestFile

          public final java.io.File getOldestFile()

    - #### walkFileTree

          public static final void walkFileTree(java.lang.String path,
                                                java.util.ArrayList<java.io.File> files)

    - #### walkFileTree

          public static final void walkFileTree(java.lang.String path,
                                                java.util.ArrayList<java.io.File> files,
                                                java.lang.String filter)

    - #### deleteFileList

          public final void deleteFileList(java.io.File[] files)

      Deletes the supplied list of files, be very carefull with this
      Parameters:
        `files` -

    - #### deleteFolder

          public static final boolean deleteFolder(java.lang.String folder)

      Delete folder and its contents using specified folder path
      Parameters:
        `folder` -
      Returns:
        boolean True if successful

    - #### secureWipeFolder

          public static final void secureWipeFolder(java.lang.String folder)

      Wipe folder and its contents using specified folder path
      Parameters:
        `folder` -

    - #### secureWipeFolder

          public static final void secureWipeFolder(java.io.File folder)

      Wipe folder and its contents using specified File
      Parameters:
        `folder` -

    - #### secureWipe

          public static final void secureWipe(java.lang.String filename)

      Wipe file using specified filename
      Parameters:
        `filename` -

    - #### secureWipe

          public static final void secureWipe(java.io.File f)

      Wipe file using specified File
      Parameters:
        `f` -

    - #### renameTo

          public static final java.io.File renameTo(java.io.File f,
                                                    java.lang.String newname)

    - #### copyFolderContents

          public static final void copyFolderContents(java.lang.String from,
                                                      java.lang.String to,
                                                      java.lang.String ignore)

      Copy multiple files from one folder to another
      Parameters:
        `from` - The from path
        `to` - The to path
        `ignore` -

    - #### getFilenames

          public final java.lang.String[] getFilenames(int offset)

      Returns an array of filenames, array if populated from the offset value onwards
      Parameters:
        `offset` -
      Returns:
        An array of filenames

    - #### exists

          public final boolean exists()

      Test to see if path exists
      Returns:
        Returns true if file exists

    - #### exists

          public static final boolean exists(java.lang.String pathname)

      Test to see if path exists
      Parameters:
        `pathname` - The pathname to check for
      Returns:
        Returns true if file exists

    - #### delete

          public final boolean delete()

      Deletes file
      Returns:
        Returns true if successful

    - #### delete

          public static final boolean delete(java.lang.String filename)

      Deletes the specified file
      Parameters:
        `filename` -
      Returns:
        Returns true if successful

    - #### renameFile

          public final boolean renameFile(java.lang.String toname)

      Parameters:
        `toname` -
      Returns:
        Returns true if successful

    - #### openBufferedRead

          public final java.io.BufferedReader openBufferedRead()

      Opens a buffered file for read
      Returns:
        Returns null if failed

    - #### openBufferedResource

          public final void openBufferedResource()

      Use this if you need access to a file within a jar

    - #### openBufferedAppend

          public final void openBufferedAppend()

      Opens a buffered file for append

    - #### readLine

          public final java.lang.String readLine()

      Read a single line from a text file
      Returns:
        Contents as String

    - #### readEntireFile

          public final java.lang.String readEntireFile()

      Read bytes from previously opened BufferedReader
      Returns:
        Returns the entire contents from a file

    - #### openFileInputStream

          public final java.io.FileInputStream openFileInputStream(java.lang.String filename)

    - #### openFileOutputStream

          public final java.io.FileOutputStream openFileOutputStream()

      Opens a file output stream
      Returns:
        Returns Opened file output stream

    - #### openBufferedWrite

          public final void openBufferedWrite()

      Opens a buffered file for write

    - #### flushWriter

          public final void flushWriter()

    - #### writeFile

          public final void writeFile(java.lang.String data,
                                      int newlines)

      Write to a previously opened output file
      Parameters:
        `data` - The data to be written
        `newlines` - The number of newlines to generate

    - #### writeFile

          public final void writeFile(char[] data,
                                      int nochars)

      Write to a previously opened output file
      Parameters:
        `data` - The character data to be written
        `nochars` -

    - #### copyFromTo

          public static final void copyFromTo(java.lang.String frompath,
                                              java.lang.String topath)

      Copy file to
      Parameters:
        `frompath` -
        `topath` -

    - #### mergeFiles

          public static final void mergeFiles(java.lang.String srcpath1,
                                              java.lang.String srcpath2,
                                              java.lang.String destpath)

    - #### getAgeOfFile

          public static final float getAgeOfFile(java.lang.String filepath,
                                                 int period)

      Get the age of a specified file
      Parameters:
        `filepath` -
        `period` -
      Returns:
        Age of file as float

    - #### isMinutesOlder

          public static final boolean isMinutesOlder(java.lang.String filename,
                                                     long minutes)

      Test to see our file is older in minutes, returns true if it is
      Parameters:
        `filename` -
        `minutes` -
      Returns:
        boolean

    - #### isHoursOlder

          public static final boolean isHoursOlder(java.lang.String filename,
                                                   long hours)

      Test to see our file is older in hours, returns true if it is
      Parameters:
        `filename` -
        `hours` -
      Returns:
        boolean

    - #### isDaysOlder

          public static final boolean isDaysOlder(java.lang.String filename,
                                                  long days)

      Test to see our file is older in days, returns true if it is
      Parameters:
        `filename` -
        `days` -
      Returns:
        boolean

    - #### openZipStream

          public final boolean openZipStream(int level)

      Opens a zipstream. returns false if it fails
      Parameters:
        `level` -
      Returns:
        an open zipstream

    - #### closeZipStream

          public final void closeZipStream()

      Close a zip stream

    - #### compress

          public static final void compress(java.lang.String source,
                                            java.lang.String dest)

    - #### addFilesToZip

          public final boolean addFilesToZip(java.io.File... srcfiles)

      Add files to a zip file
      Parameters:
        `srcfiles` - An array of Files
      Returns:
        boolean True if successful

    - #### extractZipTo

          public final boolean extractZipTo(java.lang.String destpath)

      Extracts a zip file to a supplied location
      Parameters:
        `destpath` - Destination for contents of zip file
      Returns:
        True if successful

    - #### objectWrite

          public static final boolean objectWrite(java.lang.String filepath,
                                                  java.lang.Object o)

    - #### objectRead

          public static final java.lang.Object objectRead(java.lang.String filepath,
                                                          java.lang.Object defObject)