File Validator
The FileValidator
class is used to validate files. It has the following methods:
- isValidAudio
- file (File) - required
- audioExtensions (String[]) - default: [“mp3”, “wav”]
- exclude (String[]) - (optional) - default: null
- You can exclude the extensions you don’t want to validate
- file (File) - required
- isValidImage
- file (File) - required
- imageExtensions (String[]) - default: [“ico”, “jpeg”, “png”, “gif”]
- exclude (String[]) - (optional) - default: null
- You can exclude the extensions you don’t want to validate
- file (File) - required
- isValidPdf
- file (File) - required
- pdfExtensions (String) - default: “pdf”
- file (File) - required
- isValidTxt
- file (File) - required
- txtExtensions (String) - default: “txt”
- file (File) - required
import static io.github.multiform_validator.FileValidator.isValidAudio;
import java.io.File;
public class Main {
public static void main(String[] args) {
File file = new File("src/main/resources/audio.mp3");
System.out.println(isValidAudio(file)); // true | false
exampleExcludingExtensions();
}
public static void exampleExcludingExtensions() {
File file = new File("src/main/resources/audio.mp3");
String[] audioExtensions = {"mp3"};
System.out.println(isValidAudio(file, audioExtensions)); // false
}
}
import static io.github.multiform_validator.FileValidator.isValidImage;
import java.io.File;
public class Main {
public static void main(String[] args) {
File file = new File("src/main/resources/image.png");
System.out.println(isValidImage(file)); // true | false
exampleExcludingExtensions();
example2ExcludingExtensions();
}
public static void exampleExcludingExtensions() {
File file = new File("src/main/resources/image.png");
String[] imageExtensions = {"ico", "jpeg", "png"};
System.out.println(isValidImage(file, imageExtensions)); // false
}
public static void example2ExcludingExtensions() {
File file = new File("src/main/resources/image.png");
String[] imageExtensions = {"ico", "jpeg"};
System.out.println(isValidImage(file, imageExtensions)); // true | false
}
}
import static io.github.multiform_validator.FileValidator.isValidPdf;
import java.io.File;
public class Main {
public static void main(String[] args) {
File file = new File("src/main/resources/file.pdf");
System.out.println(isValidPdf(file)); // true | false
}
}
import static io.github.multiform_validator.FileValidator.isValidTxt;
import java.io.File;
public class Main {
public static void main(String[] args) {
File file = new File("src/main/resources/file.txt");
System.out.println(isValidTxt(file)); // true | false
}
}