List of usage examples for java.nio.file Path compareTo
@Override
int compareTo(Path other);
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\\Test1.txt"); Path p3 = Paths.get("C:\\Java_Dev\\..\\Java_Dev\\test1.txt"); int v1 = p1.compareTo(p2); System.out.println(v1);/*from ww w.ja va2 s . co m*/ int v2 = p1.compareTo(p3); System.out.println(v2); }
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.compareTo int compare = path01.compareTo(path02); System.out.println(compare);//from w w w. j a va 2s .c o m }
From source file:Main.java
private static void testCompareTo(Path path1, Path path2) { if (path1.compareTo(path2) == 0) { System.out.println("identical"); } else {/* ww w . j a va 2 s . c om*/ System.out.println("NOT identical"); } }
From source file:ezbake.deployer.publishers.artifact.ArtifactContentsPublisher.java
protected boolean doesResourceAlreadyExistInArtifact(java.nio.file.Path artifactPath, java.nio.file.Path artifactBasePath, byte[] artifact) throws DeploymentException { try (org.apache.commons.compress.archivers.tar.TarArchiveInputStream tais = new org.apache.commons.compress.archivers.tar.TarArchiveInputStream( new org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream( new java.io.ByteArrayInputStream(artifact)))) { org.apache.commons.compress.archivers.ArchiveEntry nextEntry; while ((nextEntry = tais.getNextEntry()) != null) { if (nextEntry.isDirectory()) continue; java.nio.file.Path entryPath = java.nio.file.Paths.get(nextEntry.getName()); if (!entryPath.startsWith(artifactBasePath)) continue; if (entryPath.compareTo(artifactPath) == 0) { return true; }/* www. j ava 2s. com*/ } } catch (java.io.IOException e) { throw new DeploymentException(e.getMessage()); } return false; }
From source file:de.teamgrit.grit.checking.compile.HaskellCompileChecker.java
/** * This Method generates the command required to start the compiler. It * generates a list of strings that can be passed to a process builder. * //from w w w. j a va 2 s.c om * @param pathToProgramFile * Where to look for the main file that will be compiled. * @param compilerName * Which compiler to call * @param compilerFlags * User supplied flags to be passed * @return List of string with the command for the process builder. * @throws BadCompilerSpecifiedException * When no compiler is given. * @throws FileNotFoundException * When the file to be compiled does not exist * @throws CompilerOutputFolderExistsException * Due to slightly uncompatible CompileCheckerInterface this * exception is in the declaration but it is never thrown. * JavaCompileChecker uses this exception. */ private List<String> createCompilerInvocation(Path pathToProgramFile, String compilerName, List<String> compilerFlags) throws BadCompilerSpecifiedException, FileNotFoundException, CompilerOutputFolderExistsException { List<String> compilerInvocation = new LinkedList<>(); // We need a compiler name. Without it we cannot compile anything and // abort. if (("".equals(compilerName)) || (compilerName == null)) { throw new BadCompilerSpecifiedException("No compiler specified."); } else { compilerInvocation.add(compilerName); } // If compiler flags are passed, append them after the compiler name. // If we didn't get any we append nothing. if ((compilerFlags != null) && (!(compilerFlags.isEmpty()))) { compilerInvocation.addAll(compilerFlags); } // now we tell ghc to stop after compilation because we just want to // see if there are syntax errors in the code compilerInvocation.add("-c"); // Check for the existence of the program file we are trying to // compile. if ((pathToProgramFile == null) || (pathToProgramFile.compareTo(Paths.get("")) == 0)) { throw new FileNotFoundException("No file to compile specified"); } else { if (Files.isDirectory(pathToProgramFile, LinkOption.NOFOLLOW_LINKS)) { // we are supposed to compile a folder. Hence we'll scan for // lhs files and pass them to the compiler. RegexDirectoryWalker dirWalker = new RegexDirectoryWalker(".+\\.([Ll])?[Hh][Ss]"); try { Files.walkFileTree(pathToProgramFile, dirWalker); } catch (IOException e) { LOGGER.severe("Could not walk submission " + pathToProgramFile.toString() + " while building compiler invocation: " + e.getMessage()); } for (Path matchedFile : dirWalker.getFoundFiles()) { compilerInvocation.add(matchedFile.toFile().getAbsolutePath()); } } else if (Files.exists(pathToProgramFile, LinkOption.NOFOLLOW_LINKS)) { // if the file exists, just pass the file name, since the // compiler will // be confined to the directory the file is in a few lines // down. compilerInvocation.add(pathToProgramFile.toString()); } else { throw new FileNotFoundException("Program file that should be compiled does not exist." + "Filename : \"" + pathToProgramFile.toString() + "\""); } } return compilerInvocation; }
From source file:de.teamgrit.grit.checking.compile.GccCompileChecker.java
/** * This Method generates the command required to start the compiler. It * generates a list of strings that can be passed to a process builder. * /* w ww .j a va 2 s.co m*/ * @param pathToProgramFile * Where to look for the main file that will be compiled. * @param compilerName * Which compiler to call * @param compilerFlags * User supplied flags to be passed * @throws BadCompilerSpecifiedException * When no compiler is given. * @throws FileNotFoundException * When the file to be compiled does not exist * @return List of string with the command for the process builder. */ private List<String> createCompilerInvocation(Path pathToProgramFile, String compilerName, List<String> compilerFlags) throws BadCompilerSpecifiedException, FileNotFoundException { List<String> compilerInvocation = new LinkedList<>(); // We need a compiler name. Without it we cannot compile anything and // abort. if (("".equals(compilerName)) || (compilerName == null)) { throw new BadCompilerSpecifiedException("No compiler specified."); } else { // search for a makefile Path programDirectory = null; if (!Files.isDirectory(pathToProgramFile)) { programDirectory = pathToProgramFile.getParent(); } else { programDirectory = pathToProgramFile; } Collection<File> fileList = FileUtils.listFiles(programDirectory.toFile(), FileFilterUtils.fileFileFilter(), null); boolean hasMakefile = false; for (File f : fileList) { if (f.getName().matches("[Mm][Aa][Kk][Ee][Ff][Ii][Ll][Ee]")) { hasMakefile = true; } } if (hasMakefile) { // add the necessary flags for make and return the invocation - // we don't need more flags or parameters LOGGER.info("Found make-file. Compiling c-code with make."); compilerInvocation.add("make"); compilerInvocation.add("-k"); compilerInvocation.add("-s"); return compilerInvocation; } else { compilerInvocation.add(compilerName); LOGGER.info("Compiling c-code with " + compilerName); } } // If compiler flags are passed, append them after the compiler name. // If we didn't get any we append nothing. if ((compilerFlags != null) && !(compilerFlags.isEmpty())) { if (!compilerFlags.contains("-c")) { compilerFlags.add("-c"); } compilerInvocation.addAll(compilerFlags); } // Check for the existance of the program file we are trying to // compile. if ((pathToProgramFile == null) || (pathToProgramFile.compareTo(Paths.get("")) == 0)) { throw new FileNotFoundException("No file to compile specified"); } else { if (Files.isDirectory(pathToProgramFile, LinkOption.NOFOLLOW_LINKS)) { // we have to be able to compile several .c files at the same // time so we need to find them RegexDirectoryWalker dirWalker = new RegexDirectoryWalker(".+\\.[Cc][Pp]?[Pp]?"); try { Files.walkFileTree(pathToProgramFile, dirWalker); } catch (IOException e) { LOGGER.severe("Could not walk submission " + pathToProgramFile.toString() + " while building compiler invocation: " + e.getMessage()); } for (Path matchedFile : dirWalker.getFoundFiles()) { compilerInvocation .add(matchedFile.toString().substring(pathToProgramFile.toString().length() + 1)); } } else { throw new FileNotFoundException("Program file that should be compiled does not exist." + "Filename : \"" + pathToProgramFile.toString() + "\""); } } return compilerInvocation; }