List of usage examples for java.io File list
public String[] list()
From source file:com.swordlord.gozer.builder.Parser.java
/** * Retrieve a Class/*w ww .j a v a 2 s .c om*/ * * @param pckgname * @param skipDollarClasses * @return the class */ public static Class<?>[] getClasses(String pckgname, boolean skipDollarClasses) { ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); try { File directory = getClassesHelper(pckgname); if (directory.exists()) { // Get the list of the files contained in the package String[] files = directory.list(); for (int i = 0; i < files.length; i++) { // we are only interested in .class files if (files[i].endsWith(".class")) { // get rid of the ".class" at the end String withoutclass = pckgname + '.' + files[i].substring(0, files[i].length() - 6); // in case we don't want $1 $2 etc. endings (i.e. common // in GUI classes) if (skipDollarClasses) { int dollar_occurence = withoutclass.indexOf("$"); if (dollar_occurence != -1) { withoutclass = withoutclass.substring(0, dollar_occurence); } } // add this class to our list but avoid duplicates boolean already_contained = false; for (Class<?> c : classes) { if (c.getCanonicalName().equals(withoutclass)) { already_contained = true; } } if (!already_contained) { classes.add(Class.forName(withoutclass)); } // REMARK this kind of checking is quite slow using // reflection, it would be better // to do the class.forName(...) stuff outside of this // method and change the method // to only return an ArrayList with fqcn Strings. Also // in reality we have the $1 $2 // etc. classes in our packages, so we are skipping some // "real" classes here } } } else { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } } catch (ClassNotFoundException e) { e.printStackTrace(); } Class<?>[] classesA = new Class[classes.size()]; classes.toArray(classesA); return classesA; }
From source file:net.rim.ejde.internal.builders.ResourceBuilder.java
private static int removeFiles(File dir) throws IOException { int count = 0; String[] inDir = dir.list(); if (inDir != null) { for (int j = 0; j < inDir.length; ++j) { File f = new File(dir.getPath(), inDir[j]); if (f.isDirectory()) { count += removeFiles(f); } else { count += (int) f.length(); if (!f.delete()) { throw new IOException(); }/*from w w w . jav a2 s . c o m*/ } } } if (!dir.delete()) { throw new IOException(); } return count; }
From source file:de.ingrid.portal.global.UtilsMapServiceManager.java
/** * Delete oldest map and gml files if limit is arrives * /*from w ww. j a va 2 s . c om*/ * @throws ConfigurationException * @throws Exception */ public static void countTempServiceNumber() throws ConfigurationException, Exception { File path = new File(getTmpDirectory(getConfig().getString("temp_service_path", null))); ArrayList<Long> fileArray = new ArrayList<Long>(); if (path.exists()) { if (path.list().length > Integer.parseInt(getConfig().getString("temp_service_limit", null))) { File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { fileArray.add(files[i].lastModified()); } } UtilsFileHelper.sortFileByDate(fileArray); for (int i = 0; i < files.length; i++) { if (files[i].lastModified() == fileArray.get(0)) { files[i].delete(); if (log.isDebugEnabled()) { log.debug("Delete temporay service " + files[i].getName()); } } } if (path.list().length > Integer.parseInt(getConfig().getString("temp_service_limit", null))) { countTempServiceNumber(); } } } }
From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java
private static void listFiles(File file, StringBuffer sb) { if (isDebugEnabled) { S_LOGGER.debug("Entering Method DocumentUtil.listFiles(File file,StringBuffer sb)"); }/*from w w w.j av a 2 s. c om*/ String[] list = file.list(); sb.append("<ul>"); //$NON-NLS-1$ for (String fileOrFolder : list) { File newFile = new File(file.toString() + File.separator + fileOrFolder); if (newFile.isHidden()) { continue; } /*if(newFile.isDirectory()){ sb.append("<li>"); //$NON-NLS-1$ sb.append("<a href=./"); //$NON-NLS-1$ sb.append(newFile.getName()); sb.append("\">"); //$NON-NLS-1$ sb.append(newFile.getPath()); sb.append("</a>"); //$NON-NLS-1$ sb.append("</li>"); //$NON-NLS-1$ listFiles(newFile, sb); } else {*/ sb.append("<li>"); //$NON-NLS-1$ sb.append("<a href=" + "\"" + "./"); //$NON-NLS-1$ sb.append(newFile.getName()); sb.append("\">"); //$NON-NLS-1$ sb.append(newFile.getName()); sb.append("</a>"); //$NON-NLS-1$ sb.append("</li>"); //$NON-NLS-1$ // } } sb.append("</ul>"); //$NON-NLS-1$ }
From source file:it.eng.spagobi.tools.downloadFiles.service.DownloadZipAction.java
/** Search all files in directory wich in their name has timestamp from begin date to end date * //w w w . j a v a 2s .c o m * @param vector * @param dir * @param beginDate * @param endDate * @return * @throws ParseException */ static public Vector<File> searchDateFiles(File dir, Date beginDate, Date endDate, String prefix) { Vector<File> toReturn = new Vector<File>(); // if directory ha files if (dir.isDirectory() && dir.list() != null && dir.list().length != 0) { // serach only files starting with prefix // get sorted array File[] files = getSortedArray(dir, prefix); if (files == null) { throw new SpagoBIServiceException(SERVICE_NAME, "Missing files in specified interval"); } // cycle on all files boolean exceeded = false; for (int i = 0; i < files.length && !exceeded; i++) { File childFile = files[i]; // extract date from file Name Date fileDate = null; try { fileDate = extractDate(childFile.getName(), prefix); } catch (ParseException e) { // TODO Auto-generated catch block logger.error("error in parsing log file date, file will be ignored!", e); continue; } // compare beginDate and timeDate, if previous switch file, if later see end date // compare then end date, if previous then endDate add file, else exit // if fileDate later than begin Date if (fileDate != null && fileDate.after(beginDate)) { // if end date later than file date if (endDate.after(fileDate)) { // it is in the interval, add to list! toReturn.add(childFile); } else { // if file date is later then end date, we are exceeding interval exceeded = true; } } } } return toReturn; }
From source file:com.wavemaker.commons.util.IOUtils.java
/** * Get all files (excluding directories) under dir. *//*from w w w. ja va 2 s .co m*/ public static Collection<File> getFiles(File indir) { if (!indir.isDirectory()) { throw new IllegalArgumentException("Expected directory as input"); } Collection<File> rtn = new HashSet<File>(); List<File> dirs = new ArrayList<File>(); dirs.add(indir); while (!dirs.isEmpty()) { File dir = dirs.remove(0); String[] files = dir.list(); for (String s : files) { File f = new File(dir, s); if (f.isDirectory()) { dirs.add(f); } else { rtn.add(f); } } } return rtn; }
From source file:edu.stanford.epad.epadws.dcm4chee.Dcm4CheeOperations.java
public static boolean dcmsnd(File inputDirFile, boolean throwException) throws Exception { InputStream is = null;/*from w ww .ja va 2 s.c o m*/ InputStreamReader isr = null; BufferedReader br = null; FileWriter tagFileWriter = null; boolean success = false; try { String aeTitle = EPADConfig.aeTitle; String dicomServerIP = EPADConfig.dicomServerIP; String dicomServerPort = EPADConfig.dicomServerPort; String dicomServerTitleAndPort = aeTitle + "@" + dicomServerIP + ":" + dicomServerPort; dicomServerTitleAndPort = dicomServerTitleAndPort.trim(); String dirPath = inputDirFile.getAbsolutePath(); if (pathContainsSpaces(dirPath)) dirPath = escapeSpacesInDirPath(dirPath); File dir = new File(dirPath); int nbFiles = -1; if (dir != null) { String[] filePaths = dir.list(); if (filePaths != null) nbFiles = filePaths.length; } log.info("./dcmsnd: sending " + nbFiles + " file(s) - command: ./dcmsnd " + dicomServerTitleAndPort + " " + dirPath); String[] command = { "./dcmsnd", dicomServerTitleAndPort, dirPath }; ProcessBuilder processBuilder = new ProcessBuilder(command); String dicomScriptsDir = EPADConfig.getEPADWebServerDICOMScriptsDir() + "bin/"; File script = new File(dicomScriptsDir, "dcmsnd"); if (!script.exists()) dicomScriptsDir = EPADConfig.getEPADWebServerDICOMBinDir(); script = new File(dicomScriptsDir, "dcmsnd"); if (!script.exists()) throw new Exception("No script found:" + script.getAbsolutePath()); // Java 6 - Runtime.getRuntime().exec("chmod u+x "+script.getAbsolutePath()); script.setExecutable(true); processBuilder.directory(new File(dicomScriptsDir)); processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); is = process.getInputStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); String line; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line).append("\n"); log.info("./dcmsend output: " + line); } try { int exitValue = process.waitFor(); log.info("DICOM send exit value is: " + exitValue); if (exitValue == 0) success = true; } catch (InterruptedException e) { log.warning("Didn't send DICOM files in: " + inputDirFile.getAbsolutePath(), e); } String cmdLineOutput = sb.toString(); if (cmdLineOutput.toLowerCase().contains("error")) throw new IllegalStateException("Failed for: " + parseError(cmdLineOutput)); return success; } catch (Exception e) { log.warning("DicomSendTask failed to send DICOM files", e); if (e instanceof IllegalStateException && throwException) { throw e; } if (throwException) { throw new IllegalStateException("DicomSendTask failed to send DICOM files", e); } return success; } catch (OutOfMemoryError oome) { log.warning("DicomSendTask out of memory: ", oome); if (throwException) { throw new IllegalStateException("DicomSendTask out of memory: ", oome); } return success; } finally { IOUtils.closeQuietly(tagFileWriter); IOUtils.closeQuietly(br); IOUtils.closeQuietly(isr); IOUtils.closeQuietly(is); } }
From source file:DirectoryWalker.java
/** * Get all the files in the starting directory (but NOT sub dirs) * returns only files ending this the filename * @param startingDirectory// ww w. j av a2 s . c o m * @return filesFound (as HashSet) * @exception java.io.IOException */ public static HashSet getFiles(String startingDirectory, String endFileName) throws java.io.IOException { //Local Variables String tmpFullFile; File startDir = new File(startingDirectory); File tmpFile; String[] thisDirContents; HashSet filesFound = new HashSet(); //Check that this is a valid directory if (!startDir.isDirectory()) { throw new java.io.IOException(startingDirectory + " was not a valid directory"); } //Get the contents of the current directory thisDirContents = startDir.list(); if (thisDirContents != null) { //Now loop through , apply filter , or adding them to list of sub dirs for (int a = 0; a < thisDirContents.length; a++) { //Get Handle to (full) file (inc path) tmpFullFile = FileUtil.combineFileAndDirectory(thisDirContents[a], startingDirectory); tmpFile = new File(tmpFullFile); //Add to Output if file if (tmpFile.isFile()) { //Add if file if ((endFileName == null) || (tmpFullFile.endsWith(endFileName))) { filesFound.add(tmpFullFile); } } } } return filesFound; }
From source file:com.easyjf.web.core.FrameworkEngine.java
private static void getAllPages(List allPage, String basePath) { String fileName = Globals.APP_BASE_DIR + basePath.substring(1); File file = new File(fileName); if (file != null && file.isDirectory()) { String[] pages = file.list(); if (pages.length > 0) { for (int i = 0; i < pages.length; i++) { allPage.add(pages[i]);/* w ww . j a v a 2 s .c o m*/ } } } }
From source file:com.ushahidi.android.app.Util.java
/** * Delete content of a folder recursively. * //from w w w . ja v a 2 s . c o m * @param String path - path to the directory. * @return void */ public static void rmDir(String path) { String strName = ""; File dir = new File(path); if (dir.isDirectory()) { String[] children = dir.list(); Log.i("Directory", "dir.list returned some files" + children.length + "--"); for (int i = 0; i < children.length; i++) { File temp = new File(dir, children[i]); strName = children[i] + ","; if (temp.isDirectory()) { rmDir(temp.getName()); } else { temp.delete(); } } dir.delete(); } else { Log.i("Directory", "This is not a directory" + path); } }