List of usage examples for java.nio.file Path equals
boolean equals(Object other);
From source file:Test.java
public static void main(String[] args) throws Exception { Path path = Paths.get(new URI("file:///C:/home/docs/users.txt")); File file = new File("C:\\home\\docs\\users.txt"); Path toPath = file.toPath(); System.out.println(toPath.equals(path)); }
From source file:Main.java
public static void main(String[] args) { Path path01 = Paths.get("/tutorial/Java/JavaFX/Topic.txt"); Path path02 = Paths.get("C:/tutorial/Java/JavaFX/Topic.txt"); //compare using Path.equals if (path01.equals(path02)) { System.out.println("The paths are equal!"); } else {/*w w w .j a va2s. com*/ System.out.println("The paths are not equal!"); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Path p1 = Paths.get("C:\\Java_Dev\\test1.txt"); Path p2 = Paths.get("C:\\Java_Dev\\LUCI1.TXT"); Path p3 = Paths.get("C:\\Java_Dev\\..\\Java_Dev\\test1.txt"); boolean b1 = p1.equals(p2); System.out.println(b1);/*from w ww. j a va2 s.co m*/ boolean b2 = p1.equals(p3); System.out.println(b2); }
From source file:Test.java
private static void testEquals(Path path1, Path path2) { if (path1.equals(path2)) { System.out.println("equal"); } else {/* w w w. ja v a2s . c o m*/ System.out.println("NOT equal"); } }
From source file:org.sonarsource.commandlinezip.ZipUtils7.java
public static void zipDir(final Path srcDir, Path zip) throws IOException { try (final OutputStream out = FileUtils.openOutputStream(zip.toFile()); final ZipOutputStream zout = new ZipOutputStream(out)) { Files.walkFileTree(srcDir, new SimpleFileVisitor<Path>() { @Override//from w ww.j a v a 2 s . c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try (InputStream in = new BufferedInputStream(new FileInputStream(file.toFile()))) { String entryName = srcDir.relativize(file).toString(); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); IOUtils.copy(in, zout); zout.closeEntry(); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.equals(srcDir)) { return FileVisitResult.CONTINUE; } String entryName = srcDir.relativize(dir).toString(); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); zout.closeEntry(); return FileVisitResult.CONTINUE; } }); } }
From source file:org.sonarsource.commandlinezip.ZipUtils7.java
public static void fastZip(final Path srcDir, Path zip) throws IOException { try (final OutputStream out = FileUtils.openOutputStream(zip.toFile()); final ZipOutputStream zout = new ZipOutputStream(out)) { zout.setMethod(ZipOutputStream.STORED); Files.walkFileTree(srcDir, new SimpleFileVisitor<Path>() { @Override// w ww . j av a 2 s .c om public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try (InputStream in = new BufferedInputStream(new FileInputStream(file.toFile()))) { String entryName = srcDir.relativize(file).toString(); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); IOUtils.copy(in, zout); zout.closeEntry(); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.equals(srcDir)) { return FileVisitResult.CONTINUE; } String entryName = srcDir.relativize(dir).toString(); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); zout.closeEntry(); return FileVisitResult.CONTINUE; } }); } }
From source file:org.sonarsource.commandlinezip.ZipUtils7.java
public static void smartReportZip(final Path srcDir, Path zip) throws IOException { try (final OutputStream out = FileUtils.openOutputStream(zip.toFile()); final ZipOutputStream zout = new ZipOutputStream(out)) { Files.walkFileTree(srcDir, new SimpleFileVisitor<Path>() { @Override/*w ww . jav a 2s . co m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try (InputStream in = new BufferedInputStream(new FileInputStream(file.toFile()))) { String entryName = srcDir.relativize(file).toString(); int level = file.toString().endsWith(".pb") ? ZipOutputStream.STORED : Deflater.DEFAULT_COMPRESSION; zout.setLevel(level); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); IOUtils.copy(in, zout); zout.closeEntry(); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.equals(srcDir)) { return FileVisitResult.CONTINUE; } String entryName = srcDir.relativize(dir).toString(); ZipEntry entry = new ZipEntry(entryName); zout.putNextEntry(entry); zout.closeEntry(); return FileVisitResult.CONTINUE; } }); } }
From source file:io.cloudslang.content.database.services.databases.MSSqlDatabase.java
private static void validateLibraryPath(String sqlJdbcAuthLibraryPath) { final List<String> exceptions = new ArrayList<>(); if (StringUtils.isEmpty(sqlJdbcAuthLibraryPath)) { throw new RuntimeException(EMPTY_DRIVER_PATH_EXCEPTION); }// w w w . j a va 2s . c o m final Path libraryPath = Paths.get(sqlJdbcAuthLibraryPath); try { if (!libraryPath.equals(libraryPath.toRealPath())) { exceptions.add(SYMBOLIC_PATH_EXCEPTION); } if (!Files.isDirectory(libraryPath)) { exceptions.add(INVALID_DIRECTORY_PATH_EXCEPTION); } if (!libraryPath.isAbsolute()) { exceptions.add(DRIVER_PATH_NOT_ABSOLUTE_EXCEPTION); } if (!libraryPath.equals(libraryPath.normalize())) { exceptions.add(NOT_THE_SHORTEST_PATH_EXCEPTION); } } catch (IOException e) { exceptions.add(INVALID_PATH); } finally { if (exceptions.size() != 0) { throw new RuntimeException(join(exceptions, NEW_LINE)); } } }
From source file:org.wso2.carbon.launcher.test.OSGiLibBundleDeployerTest.java
private static void delete(Path path) throws IOException { Path osgiRepoPath = Paths.get(carbonHome, Constants.OSGI_REPOSITORY); Files.list(path).filter(child -> !osgiRepoPath.equals(child) && Files.isDirectory(child)).forEach(child -> { try {/*from ww w. j av a 2 s.co m*/ FileUtils.deleteDirectory(child.toFile()); } catch (IOException e) { throw new UncheckedIOException(e); } }); }
From source file:org.elasticsearch.bootstrap.JarHell.java
static void checkClass(Map<String, Path> clazzes, String clazz, Path jarpath) { Path previous = clazzes.put(clazz, jarpath); if (previous != null) { if (previous.equals(jarpath)) { if (clazz.startsWith("org.apache.xmlbeans")) { return; // https://issues.apache.org/jira/browse/XMLBEANS-499 }/*w ww . j a v a 2 s .c o m*/ // throw a better exception in this ridiculous case. // unfortunately the zip file format allows this buggy possibility // UweSays: It can, but should be considered as bug :-) throw new IllegalStateException("jar hell!" + System.lineSeparator() + "class: " + clazz + System.lineSeparator() + "exists multiple times in jar: " + jarpath + " !!!!!!!!!"); } else { if (clazz.startsWith("org.apache.log4j") || clazz.startsWith("org.slf4j.impl")) { return; // go figure, jar hell for what should be System.out.println... } if (clazz.equals("org.joda.time.base.BaseDateTime")) { return; // apparently this is intentional... clean this up } if (clazz.startsWith("org.apache.lucene.util.LuceneTestCase")) { return; // for modified version of LuceneTestCase to ignore cassandra static variables leaks. } // workaround for cassandra thrift if (clazz.startsWith("org.apache.cassandra.thrift")) { return; // Because org.apache.commons.collections.FastHashMap in commons-collections and commons-beanutils } // workaround for hadoop if (clazz.startsWith("org.apache.commons")) { return; // Because org.apache.commons.collections.FastHashMap in commons-collections and commons-beanutils } if (clazz.startsWith("org.apache.jasper")) { return; // Because of Hadoop } throw new IllegalStateException( "jar hell!" + System.lineSeparator() + "class: " + clazz + System.lineSeparator() + "jar1: " + previous + System.lineSeparator() + "jar2: " + jarpath); } } }