List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:com.thoughtworks.go.util.FileUtil.java
public static boolean isChildOf(File parent, File subdirectory) throws IOException { File parentFile = parent.getCanonicalFile(); File current = subdirectory.getCanonicalFile(); return !current.equals(parentFile) && isSubdirectoryOf(parent, subdirectory); }
From source file:com.wavemaker.infra.WMTestCase.java
/** * Compare the contents of two files; display the message. * /*w ww . j av a 2 s .co m*/ * @param message The message to display. * @param expected The File containing the expected contents. * @param actual The File containing the resulting contents. * @throws IOException */ public static void assertEquals(String message, File expected, File actual) throws IOException { String msg = "mismatch between expected file \"" + expected + "\" and actual \"" + actual + "\""; if (message != null) { msg = message + ": " + msg; } if (expected.equals(actual)) { // pass } else if (expected.isFile() && actual.isFile()) { String expectedStr = FileUtils.readFileToString(expected); String actualStr = FileUtils.readFileToString(actual); assertEquals(msg, expectedStr, actualStr); } else if (expected.isDirectory() && actual.isDirectory()) { assertEquals(msg, expected.getAbsolutePath(), actual.getAbsolutePath()); } else { fail(msg); } }
From source file:ReflectionUtil.java
private static void getPackageNamesFromDir(File base, File dir, List<String> pkgs) { boolean foundClass = false; for (File file : dir.listFiles()) { if (file.isDirectory()) { getPackageNamesFromDir(base, file, pkgs); } else if (!foundClass && file.getName().endsWith(".class")) { foundClass = true;/*from w w w .j av a 2 s .c om*/ String pkg = ""; file = dir; while (!file.equals(base)) { if (!"".equals(pkg)) { pkg = "." + pkg; } pkg = file.getName() + pkg; file = file.getParentFile(); } if (!pkgs.contains(pkg)) { pkgs.add(pkg); } } } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.io.FileUtils.java
/** * Moves the file from one path to another. This method can rename a file or * move it to a different directory, like the Unix {@code mv} command. * * @param source the source file//from w ww . j ava2 s .c o m * @param destination the destination file * @throws IOException if an I/O error occurs */ public static void move(File source, File destination) throws IOException { Validate.notNull(source, "source is null"); Validate.notNull(destination, "destination is null"); if (source.equals(destination)) { return; } if (!source.renameTo(destination)) { copy(source, destination); if (!source.delete()) { if (!destination.delete()) { throw new IOException(MessageFormat.format(UNABLE_TO_DELETE, destination)); } throw new IOException(MessageFormat.format(UNABLE_TO_DELETE, source)); } } }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.io.FileUtils.java
/** * Copies all the bytes from one file to another. *.// w ww .ja v a 2 s. c om * @param source the source file * @param destination the destination file * @throws IOException if an I/O error occurred */ public static void copy(File source, File destination) throws IOException { Validate.notNull(source, "source is null"); Validate.notNull(destination, "destination is null"); if (source.equals(destination)) { return; } InputStream input = null; OutputStream output = null; try { input = new FileInputStream(source); try { output = new FileOutputStream(destination); copy(input, output); } finally { if (output != null) { output.close(); } } } finally { if (input != null) { input.close(); } } }
From source file:eu.leads.processor.planner.ClassUtil.java
private static String createClassName(File root, File file) { StringBuffer sb = new StringBuffer(); String fileName = file.getName(); sb.append(fileName.substring(0, fileName.lastIndexOf(".class"))); file = file.getParentFile();//from w w w . j a v a2s.c o m while (file != null && !file.equals(root)) { sb.insert(0, '.').insert(0, file.getName()); file = file.getParentFile(); } return sb.toString(); }
From source file:org.rapidcontext.app.Main.java
/** * Sets up the local application directory if it is different * from the built-in application directory. * * @param appDir the built-in application directory * @param localDir the local application directory * * @throws IOException if the local directory couldn't be created *///from w w w .j av a2 s. c o m private static void setupLocalAppDir(File appDir, File localDir) throws IOException { if (!appDir.equals(localDir)) { appDir = new File(appDir, "plugin/local"); localDir = new File(localDir, "plugin/local"); if (!localDir.exists()) { FileUtil.copy(appDir, localDir); } } }
From source file:org.eclipse.jdt.ls.core.internal.JVMConfigurator.java
private static IVMInstall findVM(File jvmHome) { IVMInstallType[] types = JavaRuntime.getVMInstallTypes(); for (IVMInstallType type : types) { IVMInstall[] installs = type.getVMInstalls(); for (IVMInstall install : installs) { if (jvmHome.equals(install.getInstallLocation())) { return install; }// www . j a v a2 s .c o m } } return null; }
From source file:com.nextep.designer.repository.services.impl.RepositoryUpdaterService.java
/** * Recursively search for the directory whose parent is the specified export directory in the * absolute path of the specified archive file. If no such directory is found, return the parent * directory of the specified archive file. * /* w ww . j ava 2 s . c o m*/ * @param archiveFile the delivery file for which we need to find the delivery root directory * @param exportDir the directory in which the delivery is exported * @return the root path of the delivery */ private static String getDeliveryRootPath(File archiveFile, File exportDir) { String currPath = archiveFile.getParent(); File parent = archiveFile; while (parent != null && !parent.equals(exportDir)) { currPath = parent.getAbsolutePath(); parent = parent.getParentFile(); } return (parent == null ? archiveFile.getParent() : currPath); }
From source file:com.thoughtworks.go.util.FileUtil.java
public static boolean isSubdirectoryOf(File parent, File subdirectory) throws IOException { File parentFile = parent.getCanonicalFile(); File current = subdirectory.getCanonicalFile(); while (current != null) { if (current.equals(parentFile)) { return true; }/*from w ww . ja v a 2 s . com*/ current = current.getParentFile(); } return false; }