Returns true if the given resource is either a zip, jar or war file. - Java File Path IO

Java examples for File Path IO:Jar File

Description

Returns true if the given resource is either a zip, jar or war file.

Demo Code

//Licensed under the Apache License, Version 2.0 (the "License");
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String resource = "java2s.com";
        System.out.println(isSupported(resource));
    }/* ww  w . j  a va2 s  .  c  o  m*/

    /**
     * The suffixes of the files to support.
     */
    public static final String[] SUPPORTED_FILES = new String[] { ".zip",
            ".jar", ".war" };

    /**
     * Returns true if the given {@code resource} is either a zip, jar or war file.
     */
    public static boolean isSupported(String resource) {
        int idx = resource.lastIndexOf('.');
        if (resource.length() == idx + 4) {
            for (int i = 0; i < SUPPORTED_FILES.length; i++) {
                if (resource.endsWith(SUPPORTED_FILES[i]))
                    return true;
            }
        }
        return false;
    }
}

Related Tutorials