filechampion4j 0.9.8.3
File validation library for Java
Loading...
Searching...
No Matches
dev.filechampion.filechampion4j.ValidationsHelper Class Reference
Collaboration diagram for dev.filechampion.filechampion4j.ValidationsHelper:
Collaboration graph

Public Member Functions

 ValidationsHelper (Extensions extensions)
 
StringBuilder getValidationResults (String fileCategory, String fileName, byte[] originalFile, String mimeString) throws IOException, SecurityException, NumberFormatException
 

Private Member Functions

StringBuilder doValidations () throws IOException, SecurityException, NumberFormatException
 
void logWarn (StringBuilder message)
 
void logFine (StringBuilder message)
 
boolean isBlank (String str)
 
StringBuilder checkFileSize ()
 
StringBuilder checkMimeType () throws IOException, SecurityException
 
String getFileExtension (String fileName)
 
StringBuilder containsMagicBytes ()
 
boolean containsMagicBytesProcessor (byte[] originalFileBytes, String magicBytesPattern) throws NumberFormatException
 
StringBuilder containsHeaderSignatures ()
 
boolean containsHeaderSignaturesProcessor (byte[] fileBytes, String headerSignaturesPattern) throws NumberFormatException
 
StringBuilder containsFooterSignatures ()
 
boolean containsFooterSignaturesProcessor (byte[] fileBytes, String footerSignaturesPattern) throws NumberFormatException
 
Path saveFileToTempDir (String fileExtension, byte[] originalFile)
 
Boolean deleteTempDir (Path tempFilePath)
 

Private Attributes

Extensions extensions
 
boolean failFast = false
 
StringBuilder sharedStringBuilder = new StringBuilder()
 
String fileCategory
 
byte[] originalFile
 
String mimeString
 
String fileExtension
 
String commonLogString
 
int responseMsgCountFail
 
StringBuilder sbresponseAggregationFail
 
int responseMsgCountSuccess
 
StringBuilder sbresponseAggregationSuccess
 

Static Private Attributes

static final Logger LOGGER = Logger.getLogger(ValidationsHelper.class.getName())
 

Detailed Description

This class contains helper methods for the FileValidator class

Version
0.9.8.3

Definition at line 17 of file ValidationsHelper.java.

Constructor & Destructor Documentation

◆ ValidationsHelper()

dev.filechampion.filechampion4j.ValidationsHelper.ValidationsHelper ( Extensions  extensions)

This is the constructor for the ValidationsHelper class.

Parameters
extensions(Extensions) the Extensions object containing the file validation configuration

Definition at line 37 of file ValidationsHelper.java.

37 {
38 this.extensions = extensions;
39 }

References dev.filechampion.filechampion4j.ValidationsHelper.extensions.

Member Function Documentation

◆ checkFileSize()

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.checkFileSize ( )
private

Compare file size to the maximum allowed size

Returns
StringBuilder (StringBuilder) the results of the file size check

Definition at line 152 of file ValidationsHelper.java.

152 {
153 int maxSize;
154 try {
155 maxSize = Integer.parseInt(extensions.getValidationValue(fileCategory, fileExtension, "max_size") != null ? extensions.getValidationValue(fileCategory, fileExtension, "max_size").toString() : "-1");
156 } catch (NumberFormatException e) {
157 maxSize = -1;
158 }
159 if ((maxSize > -1) && (originalFile.length / 1000 > maxSize || originalFile.length == 0)) {
160 sbresponseAggregationFail.append(System.lineSeparator() + ++responseMsgCountFail + ". ")
161 .append("Invalid file size (")
162 .append(originalFile.length / 1000)
163 .append("KB) exceeds maximum allowed size (")
164 .append(maxSize)
165 .append("KB)")
166 .append(commonLogString);
169 } else {
170 sbresponseAggregationSuccess.append(System.lineSeparator() + ++responseMsgCountSuccess + ". ")
171 .append("File size check passed, file size: ")
172 .append(originalFile.length / 1000)
173 .append("KB");
176 }
177 }
Object getValidationValue(String category, String extension, String validationKey)

References dev.filechampion.filechampion4j.ValidationsHelper.commonLogString, dev.filechampion.filechampion4j.ValidationsHelper.extensions, dev.filechampion.filechampion4j.ValidationsHelper.fileCategory, dev.filechampion.filechampion4j.ValidationsHelper.fileExtension, dev.filechampion.filechampion4j.Extensions.getValidationValue(), dev.filechampion.filechampion4j.ValidationsHelper.logFine(), dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), dev.filechampion.filechampion4j.ValidationsHelper.originalFile, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountFail, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountSuccess, dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationFail, and dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationSuccess.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.doValidations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkMimeType()

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.checkMimeType ( ) throws IOException, SecurityException
private

Compare the file MIME type to the expected MIME type

Returns
StringBuilder (StringBuilder) the results of the MIME type check
Exceptions
IOException(IOException) if the file cannot be saved/deleted to/from a temporary directory
SecurityException(SecurityException) if the accessed to file is denied for Files.probContentType

Definition at line 187 of file ValidationsHelper.java.

187 {
188 String mimeType = (String) extensions.getValidationValue(fileCategory, fileExtension, "mime_type");
189 String fileMimeType = isBlank(mimeString) ? "" : mimeString;
190 if (!isBlank(mimeType) && isBlank(fileMimeType)) {
192 if (tempFile == null) {
193 sharedStringBuilder.replace(0, sharedStringBuilder.length(), "Error: checkMimeType failed: tempFile is null");
195 throw new IOException(sharedStringBuilder.toString());
196 }
197 try {
198 fileMimeType = Files.probeContentType(tempFile);
199 } catch (IOException e) {
200 sharedStringBuilder.replace(0, sharedStringBuilder.length(), "Error: checkMimeType failed: ").append(e.getMessage());
202 throw new IOException(sharedStringBuilder.toString());
203 } catch (SecurityException e) {
204 sharedStringBuilder.replace(0, sharedStringBuilder.length(), "Error: checkMimeType failed: ").append(e.getMessage());
206 throw new SecurityException(sharedStringBuilder.toString());
207 } finally {
208 deleteTempDir(tempFile);
209 }
210 }
211 if (!isBlank(mimeType) && !isBlank(fileMimeType) && !fileMimeType.equals(mimeType)) {
212 sbresponseAggregationFail.append(System.lineSeparator() + ++responseMsgCountFail + ". ")
213 .append("Invalid mime_type")
214 .append(commonLogString);
217 } else {
218 sbresponseAggregationSuccess.append(System.lineSeparator() + ++responseMsgCountSuccess + ". ")
219 .append("Mime type check passed, mime type: ")
220 .append(mimeType);
223 }
224 }
Path saveFileToTempDir(String fileExtension, byte[] originalFile)

References dev.filechampion.filechampion4j.ValidationsHelper.commonLogString, dev.filechampion.filechampion4j.ValidationsHelper.deleteTempDir(), dev.filechampion.filechampion4j.ValidationsHelper.extensions, dev.filechampion.filechampion4j.ValidationsHelper.fileCategory, dev.filechampion.filechampion4j.ValidationsHelper.fileExtension, dev.filechampion.filechampion4j.Extensions.getValidationValue(), dev.filechampion.filechampion4j.ValidationsHelper.isBlank(), dev.filechampion.filechampion4j.ValidationsHelper.logFine(), dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), dev.filechampion.filechampion4j.ValidationsHelper.mimeString, dev.filechampion.filechampion4j.ValidationsHelper.originalFile, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountFail, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountSuccess, dev.filechampion.filechampion4j.ValidationsHelper.saveFileToTempDir(), dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationFail, dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationSuccess, and dev.filechampion.filechampion4j.ValidationsHelper.sharedStringBuilder.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.doValidations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsFooterSignatures()

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.containsFooterSignatures ( )
private

Check if the file contains the expected footer signatures

Returns
StringBuilder (StringBuilder) the results of the footer signatures check

Definition at line 344 of file ValidationsHelper.java.

344 {
345 String footerSignatures = (String) extensions.getValidationValue(fileCategory, fileExtension, "footer_signatures");
346 if (!isBlank(footerSignatures) && !containsFooterSignaturesProcessor(originalFile, footerSignatures)) {
347 sbresponseAggregationFail.append(System.lineSeparator() + ++responseMsgCountFail + ". ")
348 .append("Invalid footer_signatures")
349 .append(commonLogString);
352 } else {
353 sbresponseAggregationSuccess.append(System.lineSeparator() + ++responseMsgCountSuccess + ". ")
354 .append("Footer signatures check passed, footer signatures: ")
355 .append(footerSignatures);
358 }
359 }
boolean containsFooterSignaturesProcessor(byte[] fileBytes, String footerSignaturesPattern)

References dev.filechampion.filechampion4j.ValidationsHelper.commonLogString, dev.filechampion.filechampion4j.ValidationsHelper.containsFooterSignaturesProcessor(), dev.filechampion.filechampion4j.ValidationsHelper.extensions, dev.filechampion.filechampion4j.ValidationsHelper.fileCategory, dev.filechampion.filechampion4j.ValidationsHelper.fileExtension, dev.filechampion.filechampion4j.Extensions.getValidationValue(), dev.filechampion.filechampion4j.ValidationsHelper.isBlank(), dev.filechampion.filechampion4j.ValidationsHelper.logFine(), dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), dev.filechampion.filechampion4j.ValidationsHelper.originalFile, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountFail, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountSuccess, dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationFail, and dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationSuccess.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.doValidations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsFooterSignaturesProcessor()

boolean dev.filechampion.filechampion4j.ValidationsHelper.containsFooterSignaturesProcessor ( byte[]  fileBytes,
String  footerSignaturesPattern 
) throws NumberFormatException
private

Check if the file contains the expected footer signatures

Parameters
fileBytes(byte[]) the file bytes of the file being validated
footerSignaturesPattern(String) the expected footer signatures of the file being validated
Returns
Boolean (Boolean) true if the file contains the expected footer signatures, false otherwise

Definition at line 367 of file ValidationsHelper.java.

367 {
368 if (isBlank(footerSignaturesPattern)) {
369 return true;
370 }
371 String hexPattern = footerSignaturesPattern.replaceAll("\\p{Zs}", "");
372 if (hexPattern.length() % 2 != 0) {
373 hexPattern = "0" + hexPattern;
374 }
375 byte[] footerSignatures = new byte[hexPattern.length() / 2];
376 for (int i = 0; i < hexPattern.length(); i += 2) {
377 footerSignatures[i / 2] = (byte) Integer.parseInt(hexPattern.substring(i, i + 2), 16);
378 }
379 int footerStartIndex = fileBytes.length - footerSignatures.length -1;
380 if (footerStartIndex < 0) {
381 return false;
382 }
383 for (int i = 0; i < footerSignatures.length; i++) {
384 if (fileBytes[footerStartIndex + i] != footerSignatures[i]) {
385 return false;
386 }
387 }
388 return true;
389 }

References dev.filechampion.filechampion4j.ValidationsHelper.isBlank().

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.containsFooterSignatures().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsHeaderSignatures()

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.containsHeaderSignatures ( )
private

Check if the file contains the expected header signatures

Returns
StringBuilder (StringBuilder) the results of the header signatures check

Definition at line 297 of file ValidationsHelper.java.

297 {
298 String headerSignatures = (String) extensions.getValidationValue(fileCategory, fileExtension, "header_signatures");
299 if (!isBlank(headerSignatures) && !containsHeaderSignaturesProcessor(originalFile, headerSignatures)) {
300 sbresponseAggregationFail.append(System.lineSeparator() + ++responseMsgCountFail + ". ")
301 .append("Invalid header_signatures")
302 .append(commonLogString);
305 } else {
306 sbresponseAggregationSuccess.append(System.lineSeparator() + ++responseMsgCountSuccess + ". ")
307 .append("Header signatures check passed, header signatures: ")
308 .append(headerSignatures);
311 }
312 }
boolean containsHeaderSignaturesProcessor(byte[] fileBytes, String headerSignaturesPattern)

References dev.filechampion.filechampion4j.ValidationsHelper.commonLogString, dev.filechampion.filechampion4j.ValidationsHelper.containsHeaderSignaturesProcessor(), dev.filechampion.filechampion4j.ValidationsHelper.extensions, dev.filechampion.filechampion4j.ValidationsHelper.fileCategory, dev.filechampion.filechampion4j.ValidationsHelper.fileExtension, dev.filechampion.filechampion4j.Extensions.getValidationValue(), dev.filechampion.filechampion4j.ValidationsHelper.isBlank(), dev.filechampion.filechampion4j.ValidationsHelper.logFine(), dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), dev.filechampion.filechampion4j.ValidationsHelper.originalFile, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountFail, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountSuccess, dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationFail, and dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationSuccess.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.doValidations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsHeaderSignaturesProcessor()

boolean dev.filechampion.filechampion4j.ValidationsHelper.containsHeaderSignaturesProcessor ( byte[]  fileBytes,
String  headerSignaturesPattern 
) throws NumberFormatException
private

Check if the file contains the expected header signatures

Parameters
fileBytes(byte[]) the file bytes of the file being validated
headerSignaturesPattern(String) the expected header signatures of the file being validated
Returns
Boolean (Boolean) true if the file contains the expected header signatures, false otherwise

Definition at line 320 of file ValidationsHelper.java.

320 {
321 if (isBlank(headerSignaturesPattern)) {
322 return true;
323 }
324 String hexPattern = headerSignaturesPattern.replaceAll("\\p{Zs}", "");
325 if (hexPattern.length() % 2 != 0) {
326 hexPattern = "0" + hexPattern;
327 }
328 byte[] headerSignatures = new byte[hexPattern.length() / 2];
329 for (int i = 0; i < hexPattern.length(); i += 2) {
330 headerSignatures[i / 2] = (byte) Integer.parseInt(hexPattern.substring(i, i + 2), 16);
331 }
332 for (int i = 0; i < headerSignatures.length; i++) {
333 if (i >= fileBytes.length || fileBytes[i] != headerSignatures[i]) {
334 return false;
335 }
336 }
337 return true;
338 }

References dev.filechampion.filechampion4j.ValidationsHelper.isBlank().

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.containsHeaderSignatures().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsMagicBytes()

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.containsMagicBytes ( )
private

Check if the file contains the expected magic bytes

Returns
StringBuilder (StringBuilder) the results of the magic bytes check

Definition at line 243 of file ValidationsHelper.java.

243 {
244 String magicBytes = (String) extensions.getValidationValue(fileCategory, fileExtension, "magic_bytes");
245 if (!isBlank(magicBytes) && !containsMagicBytesProcessor(originalFile, magicBytes)) {
246 sbresponseAggregationFail.append(System.lineSeparator() + ++responseMsgCountFail + ". ")
247 .append("Invalid magic_bytes")
248 .append(commonLogString);
251 } else {
252 sbresponseAggregationSuccess.append(System.lineSeparator() + ++responseMsgCountSuccess + ". ")
253 .append("Magic bytes check passed, magic bytes: ")
254 .append(magicBytes);
257 }
258 }
boolean containsMagicBytesProcessor(byte[] originalFileBytes, String magicBytesPattern)

References dev.filechampion.filechampion4j.ValidationsHelper.commonLogString, dev.filechampion.filechampion4j.ValidationsHelper.containsMagicBytesProcessor(), dev.filechampion.filechampion4j.ValidationsHelper.extensions, dev.filechampion.filechampion4j.ValidationsHelper.fileCategory, dev.filechampion.filechampion4j.ValidationsHelper.fileExtension, dev.filechampion.filechampion4j.Extensions.getValidationValue(), dev.filechampion.filechampion4j.ValidationsHelper.isBlank(), dev.filechampion.filechampion4j.ValidationsHelper.logFine(), dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), dev.filechampion.filechampion4j.ValidationsHelper.originalFile, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountFail, dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountSuccess, dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationFail, and dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationSuccess.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.doValidations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containsMagicBytesProcessor()

boolean dev.filechampion.filechampion4j.ValidationsHelper.containsMagicBytesProcessor ( byte[]  originalFileBytes,
String  magicBytesPattern 
) throws NumberFormatException
private

Check if the file contains the expected magic bytes

Parameters
originalFileBytes(byte[]) the file bytes of the file being validated
magicBytesPattern(String) the expected magic bytes of the file being validated
Returns
Boolean (Boolean) true if the file contains the expected magic bytes, false otherwise

Definition at line 266 of file ValidationsHelper.java.

266 {
267 if (originalFileBytes.length == 0 || magicBytesPattern == null || magicBytesPattern.isEmpty()) {
268 return false;
269 }
270 magicBytesPattern = magicBytesPattern.replaceAll("\\p{Zs}", "");
271 if (magicBytesPattern.length() % 2 != 0) {
272 magicBytesPattern = "0" + magicBytesPattern;
273 }
274 byte[] magicBytes = new byte[magicBytesPattern.length() / 2];
275 for (int i = 0; i < magicBytesPattern.length(); i += 2) {
276 magicBytes[i / 2] = (byte) Integer.parseInt(magicBytesPattern.substring(i, i + 2), 16);
277 }
278 for (int i = 0; i < originalFileBytes.length - magicBytes.length; i++) {
279 boolean found = true;
280 for (int j = 0; j < magicBytes.length; j++) {
281 if (originalFileBytes[i + j] != magicBytes[j]) {
282 found = false;
283 break;
284 }
285 }
286 if (found) {
287 return true;
288 }
289 }
290 return false;
291 }

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.containsMagicBytes().

Here is the caller graph for this function:

◆ deleteTempDir()

Boolean dev.filechampion.filechampion4j.ValidationsHelper.deleteTempDir ( Path  tempFilePath)
private

Helper method to delete the temporary directory

Parameters
tempFilePath(Path) the path to the temporary file
Returns
Boolean (Boolean) true if the temporary directory was deleted successfully, false otherwise

Definition at line 417 of file ValidationsHelper.java.

417 {
418 try (Stream<Path> walk = Files.walk(tempFilePath)) {
419 walk.sorted(Comparator.reverseOrder())
420 .map(Path::toFile)
421 .forEach(File::delete);
422 return true;
423 } catch (Exception e) {
424 sharedStringBuilder.replace(0, sharedStringBuilder.length(), "Error: Delete temporary directoy failed: ").append(e.getMessage());
426 return false;
427 }
428 }

References dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), and dev.filechampion.filechampion4j.ValidationsHelper.sharedStringBuilder.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.checkMimeType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doValidations()

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.doValidations ( ) throws IOException, SecurityException, NumberFormatException
private

Following initial validations and before plugins, this method is used to execute the validations for the file.

Returns
StringBuilder (StringBuilder) the results of the file validations
Exceptions
IOException(IOException) if the file cannot be saved/deleted to/from a temporary directory
SecurityException(SecurityException) if the accessed to file is denied for Files.probContentType

Definition at line 73 of file ValidationsHelper.java.

73 {
74
76 if (responseMsgCountFail > 0 && failFast) {
79 }
80
82 if (responseMsgCountFail > 0 && failFast) {
85 }
86
88 if (responseMsgCountFail > 0 && failFast) {
91 }
92
94 if (responseMsgCountFail > 0 && failFast) {
97 }
98
100 if (responseMsgCountFail > 0 && failFast) {
103 }
104
105 if (responseMsgCountFail > 0) {
108 } else {
111 }
112 }

References dev.filechampion.filechampion4j.ValidationsHelper.checkFileSize(), dev.filechampion.filechampion4j.ValidationsHelper.checkMimeType(), dev.filechampion.filechampion4j.ValidationsHelper.containsFooterSignatures(), dev.filechampion.filechampion4j.ValidationsHelper.containsHeaderSignatures(), dev.filechampion.filechampion4j.ValidationsHelper.containsMagicBytes(), dev.filechampion.filechampion4j.ValidationsHelper.failFast, dev.filechampion.filechampion4j.ValidationsHelper.logFine(), dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), dev.filechampion.filechampion4j.ValidationsHelper.responseMsgCountFail, dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationFail, and dev.filechampion.filechampion4j.ValidationsHelper.sbresponseAggregationSuccess.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.getValidationResults().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFileExtension()

String dev.filechampion.filechampion4j.ValidationsHelper.getFileExtension ( String  fileName)
private

Parse the file extension from the file name

Parameters
fileName(String) the name of the file being validated
Returns
String (String) the file extension of the file being validated

Definition at line 231 of file ValidationsHelper.java.

231 {
232 int dotIndex = fileName.lastIndexOf('.');
233 if (dotIndex == -1 || dotIndex == fileName.length() - 1) {
234 return "";
235 }
236 return fileName.substring(dotIndex + 1);
237 }

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.getValidationResults().

Here is the caller graph for this function:

◆ getValidationResults()

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.getValidationResults ( String  fileCategory,
String  fileName,
byte[]  originalFile,
String  mimeString 
) throws IOException, SecurityException, NumberFormatException

ValidationsHelper entry point for file validation

Parameters
fileCategory(String) the file category of the file being validated
fileName(String) the file name of the file being validated
originalFile(byte[]) the byte of the file being validated
mimeString(String) the mime type of the file being validated
Returns
StringBuilder (StringBuilder) the results of the file validations
Exceptions
IOException(IOException) if the file cannot be saved/deleted to/from a temporary directory
SecurityException(SecurityException) if the accessed to file is denied for Files.probContentType

Definition at line 51 of file ValidationsHelper.java.

51 {
52 this.fileExtension = getFileExtension(fileName);
53 this.responseMsgCountFail = 0;
54 this.sbresponseAggregationFail = new StringBuilder();
55 this.responseMsgCountSuccess = 0;
56 this.sbresponseAggregationSuccess = new StringBuilder();
57 this.fileCategory = fileCategory;
58 this .failFast = extensions.getValidationValue(fileCategory, fileExtension, "fail_fast") != null ?
59 (boolean) extensions.getValidationValue(fileCategory, fileExtension, "fail_fast") : false;
60 this.originalFile = originalFile;
61 this.mimeString = mimeString;
62 this.commonLogString = " for file: " + fileName;
63
64 return doValidations();
65 }

References dev.filechampion.filechampion4j.ValidationsHelper.doValidations(), dev.filechampion.filechampion4j.ValidationsHelper.extensions, dev.filechampion.filechampion4j.ValidationsHelper.fileCategory, dev.filechampion.filechampion4j.ValidationsHelper.fileExtension, dev.filechampion.filechampion4j.ValidationsHelper.getFileExtension(), dev.filechampion.filechampion4j.Extensions.getValidationValue(), dev.filechampion.filechampion4j.ValidationsHelper.mimeString, and dev.filechampion.filechampion4j.ValidationsHelper.originalFile.

Referenced by dev.filechampion.filechampion4j.FileValidator.doValidations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBlank()

boolean dev.filechampion.filechampion4j.ValidationsHelper.isBlank ( String  str)
private

isBlank wrapper method for support of Java 8

Parameters
str(String) the string to check if empty or null
Returns
boolean (boolean) true if the string is empty or null, false otherwise

Definition at line 144 of file ValidationsHelper.java.

144 {
145 return str == null || str.trim().isEmpty();
146 }

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.checkMimeType(), dev.filechampion.filechampion4j.ValidationsHelper.containsFooterSignatures(), dev.filechampion.filechampion4j.ValidationsHelper.containsFooterSignaturesProcessor(), dev.filechampion.filechampion4j.ValidationsHelper.containsHeaderSignatures(), dev.filechampion.filechampion4j.ValidationsHelper.containsHeaderSignaturesProcessor(), and dev.filechampion.filechampion4j.ValidationsHelper.containsMagicBytes().

Here is the caller graph for this function:

◆ logFine()

void dev.filechampion.filechampion4j.ValidationsHelper.logFine ( StringBuilder  message)
private

◆ logWarn()

◆ saveFileToTempDir()

Path dev.filechampion.filechampion4j.ValidationsHelper.saveFileToTempDir ( String  fileExtension,
byte[]  originalFile 
)
private

Helper method to save the file to a temporary directory

Parameters
fileExtension(String) the file extension of the file being validated
originalFile(byte[]) the file bytes of the file being validated
Returns
Path (Path) the path to the temporary file

Definition at line 397 of file ValidationsHelper.java.

397 {
398 Path tempFilePath = null;
399 try {
400 // Create a temporary directory
401 Path tempDir = Files.createTempDirectory("tempDir");
402 tempFilePath = Files.createTempFile(tempDir, "tempFile", "." + fileExtension);
403 Files.write(tempFilePath, originalFile);
404 } catch (Exception e) {
405 sharedStringBuilder.replace(0, sharedStringBuilder.length(), "Error: Saving file to temporary directory failed: ").append(e.getMessage());
407 return null;
408 }
409 return tempFilePath;
410 }

References dev.filechampion.filechampion4j.ValidationsHelper.fileExtension, dev.filechampion.filechampion4j.ValidationsHelper.logWarn(), dev.filechampion.filechampion4j.ValidationsHelper.originalFile, and dev.filechampion.filechampion4j.ValidationsHelper.sharedStringBuilder.

Referenced by dev.filechampion.filechampion4j.ValidationsHelper.checkMimeType().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ commonLogString

◆ extensions

◆ failFast

boolean dev.filechampion.filechampion4j.ValidationsHelper.failFast = false
private

◆ fileCategory

◆ fileExtension

◆ LOGGER

final Logger dev.filechampion.filechampion4j.ValidationsHelper.LOGGER = Logger.getLogger(ValidationsHelper.class.getName())
staticprivate

◆ mimeString

String dev.filechampion.filechampion4j.ValidationsHelper.mimeString
private

◆ originalFile

◆ responseMsgCountFail

◆ responseMsgCountSuccess

◆ sbresponseAggregationFail

◆ sbresponseAggregationSuccess

◆ sharedStringBuilder

StringBuilder dev.filechampion.filechampion4j.ValidationsHelper.sharedStringBuilder = new StringBuilder()
private

The documentation for this class was generated from the following file: