Java Resource Load getResourceScripts(String path)

Here you can find the source of getResourceScripts(String path)

Description

Gets the resource scripts.

License

Mozilla Public License

Parameter

Parameter Description
path the path

Exception

Parameter Description
IOException Signals that an I/O exception has occurred.

Return

the resource scripts

Declaration

public static Collection<String> getResourceScripts(String path) throws IOException 

Method Source Code

//package com.java2s;
/**//from  w  ww. j  a  v a  2  s  .  c o m
 * Copyright (c) 2016 TermMed SA
 * Organization
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

import java.util.zip.ZipEntry;

import java.util.zip.ZipInputStream;

public class Main {
    /**
     * Gets the resource scripts.
     *
     * @param path the path
     * @return the resource scripts
     * @throws IOException Signals that an I/O exception has occurred.
     */
    public static Collection<String> getResourceScripts(String path) throws IOException {
        System.out.println("getting files from " + path);
        List<String> strFiles = new ArrayList<String>();

        //      InputStream is=ResourceUtils.class.getResourceAsStream("/" + path);
        //      InputStreamReader risr = new InputStreamReader(is);
        //      BufferedReader br=new BufferedReader(risr);
        //      String line;
        //      while((line=br.readLine())!=null){
        //         strFiles.add(line);
        //      }

        String file = null;
        if (new File("stats-gen.jar").exists()) {
            file = "stats-gen.jar";
        } else {
            file = "target/stats-gen.jar";
        }
        ZipInputStream zip = new ZipInputStream(new FileInputStream(file));
        while (true) {
            ZipEntry e = zip.getNextEntry();
            if (e == null)
                break;
            String name = e.getName();
            if (name.startsWith(path) && !name.endsWith("/")) {
                //            if (!name.startsWith("/")){
                //               name="/" + name;
                //            }
                strFiles.add(name);
            }
        }

        System.out.println("files:" + strFiles.toString());
        return strFiles;
    }
}

Related

  1. getResourcePath()
  2. getResourcePath(Class c, String name)
  3. getResourceReader(final String aResName)
  4. getResources(File root, File path, Vector result)
  5. getResources(final Pattern pattern)
  6. getResourcesFromDirectory(File directory)
  7. getResourcesFromDirectory(final File directory, final Pattern pattern)
  8. getResourcesFromJarFile(File file, String resName)
  9. getResourcesFromJarFile(final File file, final Pattern pattern)