MOEA Framework 2.12
API Specification

org.moeaframework.util.io
Class FileProtection

java.lang.Object
  extended by org.moeaframework.util.CommandLineUtility
      extended by org.moeaframework.util.io.FileProtection

public class FileProtection
extends CommandLineUtility

Detects corrupted files using the MD5 message digest in a format compatible with the Unix command line utility md5sum.

  1. Strict mode - All files must be validated, otherwise exceptions are thrown
  2. Safe mode - Files with associated digest files are validated, but only warnings are printed if no digest file exists


Field Summary
static String SAFE_MODE
          The property value for safe mode.
static String STRICT_MODE
          The property value for strict mode.
 
Method Summary
static File getDigestFile(File file)
          Returns the digest file for the specified file.
 org.apache.commons.cli.Options getOptions()
          Returns the options made available by this command line utility.
static void main(String[] args)
          Starts the command line utility for validating files using message digests.
static InputStream openInputStream(File file)
          Returns an InputStream for reading from the specified file and performs validation on the file when the close method is invoked on the stream.
static OutputStream openOutputStream(File file)
          Returns an OutputStream for writing to the specified file and saves a digest file for validating its contents when the close method is invoked.
static Reader openReader(File file)
          Returns a Reader wrapping the result from calling openInputStream with the specified file.
static Writer openWriter(File file)
          Returns a Writer wrapping the result from calling openOutputStream with the specified file.
 void run(org.apache.commons.cli.CommandLine commandLine)
          Runs this command line utility with the specified command line arguments.
static void validate(File file)
          Validates the file.
 
Methods inherited from class org.moeaframework.util.CommandLineUtility
getCommandString, setCommandString, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRICT_MODE

public static final String STRICT_MODE
The property value for strict mode.

See Also:
Constant Field Values

SAFE_MODE

public static final String SAFE_MODE
The property value for safe mode.

See Also:
Constant Field Values
Method Detail

getDigestFile

public static File getDigestFile(File file)
Returns the digest file for the specified file.

Parameters:
file - the file to be validated
Returns:
the digest file for the specified file

openReader

public static Reader openReader(File file)
                         throws FileNotFoundException
Returns a Reader wrapping the result from calling openInputStream with the specified file.

Parameters:
file - the file to be opened
Returns:
a Reader wrapping the result from calling openInputStream with the specified file
Throws:
FileNotFoundException - if the specified file does not exist

openInputStream

public static InputStream openInputStream(File file)
                                   throws FileNotFoundException
Returns an InputStream for reading from the specified file and performs validation on the file when the close method is invoked on the stream.

Parameters:
file - the file to the opened and validated
Returns:
an InputStream for reading from the specified file
Throws:
FileNotFoundException - if the specified file does not exist

openWriter

public static Writer openWriter(File file)
                         throws FileNotFoundException
Returns a Writer wrapping the result from calling openOutputStream with the specified file.

Parameters:
file - the file to be opened
Returns:
a Writer wrapping the result from calling openOutputStream with the specified file
Throws:
FileNotFoundException - if the specified file does not exist

validate

public static void validate(File file)
                     throws IOException
Validates the file.

Parameters:
file - the file to be validated
Throws:
IOException - if an I/O error occurred

openOutputStream

public static OutputStream openOutputStream(File file)
                                     throws FileNotFoundException
Returns an OutputStream for writing to the specified file and saves a digest file for validating its contents when the close method is invoked.

Parameters:
file - the file to be opened
Returns:
an OutputStream for writing to the specified file
Throws:
FileNotFoundException - if the specified file does not exist

getOptions

public org.apache.commons.cli.Options getOptions()
Description copied from class: CommandLineUtility
Returns the options made available by this command line utility. The base implementation automatically provides the -h,--help option. Implementations overriding this method and begin with a call to super.getOptions().

Overrides:
getOptions in class CommandLineUtility
Returns:
the options made available by this command line utility

run

public void run(org.apache.commons.cli.CommandLine commandLine)
         throws Exception
Description copied from class: CommandLineUtility
Runs this command line utility with the specified command line arguments.

Specified by:
run in class CommandLineUtility
Parameters:
commandLine - the command line arguments
Throws:
Exception

main

public static void main(String[] args)
                 throws Exception
Starts the command line utility for validating files using message digests.

Parameters:
args - the command line arguments
Throws:
Exception - if an error occurred

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!