Refactor code
Modified the code on Acer Chromebook
This commit is contained in:
parent
03c8c04b0f
commit
ef9df54fc1
BIN
lib/commons-codec-1.17.1.jar
Normal file
BIN
lib/commons-codec-1.17.1.jar
Normal file
Binary file not shown.
BIN
lib/commons-csv-1.12.0.jar
Normal file
BIN
lib/commons-csv-1.12.0.jar
Normal file
Binary file not shown.
BIN
lib/commons-io-2.18.0.jar
Normal file
BIN
lib/commons-io-2.18.0.jar
Normal file
Binary file not shown.
BIN
lib/jcommander-1.82.jar
Normal file
BIN
lib/jcommander-1.82.jar
Normal file
Binary file not shown.
@ -13,6 +13,6 @@ public class jCommanderArgs {
|
||||
@Parameter(names = "--encrypt", description = "Value to encrypt using the Encryption Key")
|
||||
public String encrypt;
|
||||
|
||||
@Parameter(names = "--debug", description = "Display debug information on the screen")
|
||||
@Parameter(names = "--debug", description = "Display debug information on the screen (true/false)")
|
||||
public String debug;
|
||||
}
|
||||
|
@ -9,14 +9,20 @@ public class jCommanderVerifyFile implements IParameterValidator
|
||||
{
|
||||
public void validate(String name, String value) throws ParameterException
|
||||
{
|
||||
File file = new File (value);
|
||||
boolean isThere = file.exists();
|
||||
|
||||
if (!isThere)
|
||||
try
|
||||
{
|
||||
File file = new File(value);
|
||||
boolean success = file.exists();
|
||||
if (!success)
|
||||
{
|
||||
throw new ParameterException("Parameter value " + name + " points to a file that does not exist : " + value);
|
||||
}
|
||||
}
|
||||
catch (ParameterException ex)
|
||||
{
|
||||
System.out.println();
|
||||
System.out.println("Parameter value " + name + " points to a file that does not exist!");
|
||||
throw new ParameterException("Parameter value " + name + " points to a file that does not exist!");
|
||||
System.out.println(ex.toString());
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,17 @@ public class jCommanderVerifyKey implements IParameterValidator {
|
||||
|
||||
public void validate(String name, String value) throws ParameterException
|
||||
{
|
||||
try {
|
||||
int n = value.length();
|
||||
if (n != 16) {
|
||||
System.out.println();
|
||||
System.out.println("Parameter value " + name + " must have a length of 16 characters!");
|
||||
throw new ParameterException("Parameter value " + name + " must have a length of 16 characters!");
|
||||
}
|
||||
}
|
||||
catch (ParameterException ex)
|
||||
{
|
||||
System.out.println();
|
||||
System.out.println(ex.toString());
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,14 +13,18 @@ public class userVerify
|
||||
public static void main (String[] args) {
|
||||
System.out.println();
|
||||
Scanner myObj = new Scanner(System.in); // Create a Scanner object
|
||||
System.out.print("Enter the name of the file to verify : ");
|
||||
|
||||
String varFileName = myObj.nextLine(); // Read user input
|
||||
File thisFile = new File(varFileName);
|
||||
if (!thisFile.exists()) {
|
||||
System.out.println("The file " + varFileName + " does not exist. Please enter a valid filename!");
|
||||
System.exit(0);
|
||||
String varFileName = new String();
|
||||
while (true) {
|
||||
System.out.print("Enter the name of the file to verify : ");
|
||||
varFileName = myObj.nextLine(); // Read user input
|
||||
File thisFile = new File(varFileName);
|
||||
if (thisFile.exists())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println("CSV input file : " + varFileName);
|
||||
ArrayList thisCSV = readCSV(varFileName, true);
|
||||
@ -41,7 +45,7 @@ public class userVerify
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
boolean validfile = (thisCSV.isEmpty());
|
||||
boolean validfile = (!thisCSV.isEmpty());
|
||||
System.out.println("CSV file records : " + varIter);
|
||||
System.out.println("CSV file is valid : " + validfile);
|
||||
System.out.println();
|
||||
@ -62,10 +66,9 @@ public class userVerify
|
||||
Reader in = new FileReader(varFile);
|
||||
String varHeader = fileProcessor.readFirstLine(thisFile);
|
||||
|
||||
System.out.println(varHeader);
|
||||
if (varHeader.length() == 0)
|
||||
{
|
||||
System.out.println("The " + thisFile + " file appears to be missing a valid header!");
|
||||
System.out.println(thisFile + " : appears to be missing a valid header!");
|
||||
return finalArray;
|
||||
}
|
||||
|
||||
@ -97,7 +100,7 @@ public class userVerify
|
||||
finalArray.add(record.toMap());
|
||||
if (fromUser)
|
||||
{
|
||||
System.out.println("PASSED => CSV line : " + lineNum);
|
||||
System.out.println("PASSED : CSV line " + lineNum);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -105,8 +108,8 @@ public class userVerify
|
||||
invalidNum++;
|
||||
if (fromUser)
|
||||
{
|
||||
System.out.println("FAILED => CSV line : " + lineNum);
|
||||
System.out.println("FAILED => Contents : " + lineNum + " is " + record.toMap().toString());
|
||||
System.out.println("FAILED : CSV line " + lineNum);
|
||||
System.out.println("FAILED : Contents " + record.toMap().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public class webService {
|
||||
varKey = args.key;
|
||||
String varToEncrypt = args.encrypt;
|
||||
|
||||
if (varToEncrypt != null && varToEncrypt.length() > 0)
|
||||
if (varToEncrypt != null && !varToEncrypt.isEmpty())
|
||||
{
|
||||
String varToStore = secretProcessor.encode(secretProcessor.encrypt(varKey, varToEncrypt));
|
||||
String varChecked = secretProcessor.decrypt(varKey, secretProcessor.decode(varToStore));
|
||||
@ -61,14 +61,14 @@ public class webService {
|
||||
String varProps = args.props;
|
||||
if (varProps == null && varToEncrypt == null)
|
||||
{
|
||||
debugProcessor.writer(true, "Check your parameters. There is simply nothing to see here!");
|
||||
debugProcessor.writer(true, "Check the program parameters. There is nothing to do!");
|
||||
System.out.println();
|
||||
jct.usage();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (!fileProcessor.getFile(varProps)) {
|
||||
debugProcessor.writer(true, "Please supply a valid properties file for --props");
|
||||
if (!fileProcessor.getFile(varProps))
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ public class webService {
|
||||
byte[] varDecoded = secretProcessor.decode(varPasswordTemp);
|
||||
varPassword = secretProcessor.decrypt(varKey, varDecoded);
|
||||
} catch (Exception e) {
|
||||
debugProcessor.writer(varDebug, "The supplied password could not be decrypted. Please check the password!");
|
||||
debugProcessor.writer(true, "The password could not be decrypted. Please check that the Encryption Key is correct!");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user