All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dragome.web.serverside.compile.FileUtils Maven / Gradle / Ivy

There is a newer version: 0.96-beta4
Show newest version
/*******************************************************************************
 * Copyright (c) 2011-2014 Fernando Petrola
 * 
 * This file is part of Dragome SDK.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 ******************************************************************************/
package com.dragome.web.serverside.compile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class FileUtils
{

	/**
	 * list files in the given directory and subdirs (with recursion)
	 * @param paths
	 * @return
	 */
	public static List getFiles(String paths)
	{
		List filesList= new ArrayList();
		for (final String path : paths.split(File.pathSeparator))
		{
			final File file= new File(path);
			if (file.isDirectory())
			{
				recurse(filesList, file);
			}
			else
			{
				filesList.add(file);
			}
		}
		return filesList;
	}

	private static void recurse(List filesList, File f)
	{
		File list[]= f.listFiles();
		for (File file : list)
		{
			if (file.isDirectory())
			{
				recurse(filesList, file);
			}
			else
			{
				filesList.add(file);
			}
		}
	}

	/**
	 * List the content of the given jar
	 * @param jarPath
	 * @return
	 * @throws IOException
	 */
	public static List getJarContent(String jarPath) throws IOException
	{
		List content= new ArrayList();
		JarFile jarFile= new JarFile(jarPath);
		Enumeration e= jarFile.entries();
		while (e.hasMoreElements())
		{
			JarEntry entry= (JarEntry) e.nextElement();
			String name= entry.getName();
			content.add(name);
		}
		return content;
	}

	public static void main(String args[]) throws Exception
	{
		List list= FileUtils.getFiles(System.getProperty("java.class.path"));
		for (File file : list)
		{
			System.out.println(file.getPath());
		}
		//
		//	list= FileUtils.getFiles(System.getProperty("sun.boot.class.path"));
		//	for (File file : list)
		//	{
		//	    System.out.println(file.getPath());
		//	}
		//	list= FileUtils.getFiles(System.getProperty("java.ext.dirs"));
		//	for (File file : list)
		//	{
		//	    System.out.println(file.getPath());
		//	}
		//
		//	List content= FileUtils.getJarContent("c:/temp/DirWatch.jar");
		//	for (String file : content)
		//	{
		//	    System.out.println(file);
		//	}

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy