Multiform Validator
GitHubToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

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
  • 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
  • isValidPdf
    • file (File) - required
      • pdfExtensions (String) - default: “pdf”
  • isValidTxt
    • file (File) - required
      • txtExtensions (String) - default: “txt”

How to use

isValidAudio

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
    }
}

isValidImage

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
    }
}

isValidPdf

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
    }
}

isValidTxt

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
    }
}

Other classes validation methods