List of usage examples for java.io File isFile
public boolean isFile()
From source file:net.redstonelamp.gui.RedstoneLampGUI.java
private static List<File> getServerDirectories() { File config = new File("redstonelamp-gui-config.json"); if (!config.isFile()) { try {/*from w w w.j a v a 2 s. c o m*/ InputStream is = RedstoneLampGUI.class.getResourceAsStream("redfstonelamp-gui-config.json"); OutputStream os = new FileOutputStream(config); IOUtils.copy(is, os); } catch (IOException e) { e.printStackTrace(); } } List<File> out = new ArrayList<>(); StringBuilder configContents = new StringBuilder(); try { InputStream is = new FileInputStream(config); byte[] buffer = new byte[is.available()]; is.read(buffer); is.close(); try { JSONObject json = new JSONObject(new String(buffer)); JSONArray array = json.getJSONArray("history"); for (int i = 0; i < array.length(); i++) { JSONObject object = array.getJSONObject(i); out.add(new File(object.getString("path"))); } } catch (JSONException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } return out; }
From source file:com.datasalt.pangool.solr.TupleSolrOutputFormat.java
private static void listFiles(File dir, Set<File> files) throws IOException { File[] list = dir.listFiles(); for (File f : list) { if (f.isFile()) { files.add(f);//from w ww. j av a 2s . c o m } else { listFiles(f, files); } } }
From source file:com.hw.util.CompressUtils.java
private static void unzipFolder(File uncompressFile, File descPathFile, boolean override) { ZipFile zipFile = null;//ww w . java 2 s .c o m try { zipFile = new ZipFile(uncompressFile, "GBK"); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry zipEntry = entries.nextElement(); String name = zipEntry.getName(); name = name.replace("\\", "/"); File currentFile = new File(descPathFile, name); //? if (currentFile.isFile() && currentFile.exists() && !override) { continue; } if (name.endsWith("/")) { currentFile.mkdirs(); continue; } else { currentFile.getParentFile().mkdirs(); } FileOutputStream fos = null; try { fos = new FileOutputStream(currentFile); InputStream is = zipFile.getInputStream(zipEntry); IOUtils.copy(is, fos); } finally { IOUtils.closeQuietly(fos); } } } catch (IOException e) { throw new RuntimeException("", e); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { } } } }
From source file:it.serasoft.pdi.PDITools.java
private static void getFilesList(File f, ArrayList<File> completeFilesList, boolean recurse) { File[] files = f.listFiles(); for (File item : files) { if (recurse && item.isDirectory() && !item.isHidden()) { getFilesList(item, completeFilesList, recurse); } else if (item.isFile() && !item.isHidden() && (item.getName().endsWith(EXT_PDI_JOB) || item.getName().endsWith(EXT_PDI_TRANSFORMATION))) { completeFilesList.add(item); }// w ww .j ava2s. co m } }
From source file:eu.qualimaster.adaptation.platform.ToolBase.java
/** * Returns whether <code>file</code> is readable. * /* w ww . j av a 2 s . c om*/ * @param file the file to be checked * @return <code>true</code> if <code>file</code> is readable, <code>false</code> else */ protected static boolean isReadable(File file) { return file.exists() && file.isFile() && file.canRead(); }
From source file:com.magnet.tools.tests.WebLogicStepDefs.java
public static void ensureBuildSuccessful(String filePath) { File logFile = new File(filePath); Assert.assertTrue(logFile + " should exist", logFile.exists() && logFile.isFile()); try {/* ww w . ja v a 2s .c o m*/ FileInputStream fis = new FileInputStream(logFile); String content = IOUtils.toString(fis); File savedFile = new File(filePath + System.currentTimeMillis() + ".log"); FileUtils.copyFile(logFile, savedFile); Assert.assertTrue("build from log: " + savedFile.getAbsolutePath() + " should be successful", content.contains("BUILD SUCCESS")); Assert.assertFalse("build from log: " + savedFile.getAbsolutePath() + " should not fail", content.contains("BUILD FAILURE")); if (!savedFile.delete()) { ScenarioUtils.log("Couldn't delete " + savedFile); } // logFile.delete(); } catch (Exception e) { Assert.fail("An exception occurred: " + e); } }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.util.SerializationUtils.java
/** * @param object/* ww w . j a v a2 s . co m*/ * object to be serialized * @param filePath * the object will be written at this location, directories will be * created according to path * @throws Exception exception */ public static void serializeToDisk(Serializable object, String filePath) throws Exception { File dir = new File(FilenameUtils.getFullPathNoEndSeparator(filePath)); if (!dir.exists()) { FileUtils.forceMkdir(dir); } else { if (dir.isFile()) { throw new IOException("Path to dir is a file!"); } } ObjectOutputStream objOut = null; objOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filePath))); objOut.writeObject(object); objOut.flush(); objOut.close(); }
From source file:info.servertools.core.util.FileUtils.java
/** * Check the size of a directory//from w w w. j a v a2 s . c o m * * @param directory * the directory to check * * @return the size of the directory in bytes */ public static long getFolderSize(File directory) { long length = 0; if (directory.exists() && directory.isDirectory()) { File[] files = directory.listFiles(); if (files != null) { for (File file : files) { if (file.isFile()) length += file.length(); else length += getFolderSize(file); } } } return length; }
From source file:jterm.command.Dir.java
@Command(name = "rmdir", minOptions = 1, syntax = "rm [-h] [-r] dirName") public static void rm(List<String> options) { List<String> filesToBeRemoved = new ArrayList<>(); final boolean[] recursivelyDeleteFlag = { false }; options.forEach(option -> {/*from w w w . ja v a 2 s . c o m*/ switch (option) { case "-r": recursivelyDeleteFlag[0] = true; break; default: filesToBeRemoved.add(option); break; } }); filesToBeRemoved.forEach(fileName -> { File file = new File(JTerm.currentDirectory, fileName); if (!file.isFile() && !file.isDirectory()) { JTerm.out.printf(TextColor.ERROR, "%s is not a file or directory%n", fileName); } else if (file.isDirectory()) { if (recursivelyDeleteFlag[0]) { try { FileUtils.deleteDirectory(file); } catch (IOException e) { JTerm.out.printf(TextColor.ERROR, "Error when deleting %s%n", fileName); } } else { JTerm.out.println(TextColor.ERROR, "Attempting to delete a directory. Run the command again with -r."); return; } } file.delete(); }); }
From source file:com.clustercontrol.repository.factory.AgentLibDownloader.java
/** * ?????????//w w w . j a v a 2 s .c o m * @return * @throws HinemosUnknown */ public static HashMap<String, String> getAgentLibMap() throws HinemosUnknown { HashMap<String, String> fileMap = new HashMap<String, String>(); String agentLibDir = System.getProperty("hinemos.manager.home.dir", "/opt/hinemos/") + "/lib/agent"; File dir = new File(agentLibDir); File[] files = dir.listFiles(); if (files != null) { for (File file : files) { if (file.isFile()) { fileMap.put(file.getName(), getMD5(file.getAbsolutePath())); } } } else { m_log.info("files is null, agentLibDir=" + agentLibDir); } return fileMap; }