From 33a8eaa4c59dd439a280d4c96ea25b1a3a781e8c Mon Sep 17 00:00:00 2001 From: Keith Armstrong Date: Thu, 9 Jan 2025 19:27:01 -0500 Subject: [PATCH] Added new code to check binary file --- src/com/belkast/soap/fileProcessor.java | 38 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/com/belkast/soap/fileProcessor.java b/src/com/belkast/soap/fileProcessor.java index 803a374..2a399b6 100644 --- a/src/com/belkast/soap/fileProcessor.java +++ b/src/com/belkast/soap/fileProcessor.java @@ -9,15 +9,18 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import java.nio.charset.CodingErrorAction; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class fileProcessor { public static String readFirstLine(String thisFile) throws IOException { File file = new File(thisFile); Boolean isValid = validFile(thisFile); + if ( !isValid ) { - return ""; + return null; } if (file.exists()) { @@ -28,7 +31,9 @@ public class fileProcessor { return s; } } + return null; + } public static Boolean getFile(String myFile) { @@ -54,7 +59,9 @@ public class fileProcessor { FileReader fileReader = new FileReader(myFile); BufferedReader reader = new BufferedReader(fileReader); String line; - while ((line = reader.readLine()) != null) { + while ((line = reader.readLine()) != null) + { + line = line.replaceAll("(?m)^\\s+|\\s+$", ""); sb.append(line); } reader.close(); @@ -75,6 +82,33 @@ public class fileProcessor { return returnString; } + public static boolean fileHasText(String thisFile, String word) throws FileNotFoundException + { + boolean flag = false; + Scanner sc2 = new Scanner(new FileInputStream(thisFile)); + while(sc2.hasNextLine()) { + String line = sc2.nextLine(); + if( line.indexOf(word) != -1 ) + { + flag = true; + } + } + return flag; + } + + public static boolean stringHasText(String line, String regex) throws FileNotFoundException + { + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(line); + + int matches = 0; + while ( matcher.find() ) + { + matches++; + } + return (matches > 0); + } + public static boolean validFile(String thisFile) { Path path = Paths.get(thisFile);