List of usage examples for java.net URI compareTo
public int compareTo(URI that)
From source file:Main.java
public static void main(String[] args) throws NullPointerException, URISyntaxException { URI uri = new URI("http://www.java2s.com:8080/yourpath/fileName.htm"); URI uri1 = new URI("http://www.java2s.com:8080/yourpath/fileName.htm"); System.out.println(uri.compareTo(uri1)); }
From source file:com.cognitect.transit.TransitMPTest.java
public void testReadURI() throws URISyntaxException, IOException { URI uri = TransitFactory.uri("http://www.foo.com"); assertEquals(0, uri.compareTo((URI) readerOf("~rhttp://www.foo.com").read())); }
From source file:org.apache.hadoop.hdfs.server.namenode.NNStorage.java
/** * Set the storage directories which will be used. This should only ever be * called from inside NNStorage. However, it needs to remain package private * for testing, as StorageDirectories need to be reinitialised after using * Mockito.spy() on this class, as Mockito doesn't work well with inner * classes, such as StorageDirectory in this case. * * Synchronized due to initialization of storageDirs and removedStorageDirs. * * @param fsNameDirs Locations to store images. * @param fsEditsDirs Locations to store edit logs. * @param locationMap location descriptors * @throws IOException/* w w w. ja v a 2s.c om*/ */ public synchronized void setStorageDirectories(Collection<URI> fsNameDirs, Collection<URI> fsEditsDirs, Map<URI, NNStorageLocation> locationMap) throws IOException { this.storageDirs.clear(); this.removedStorageDirs.clear(); for (URI dirName : fsNameDirs) { boolean isAlsoEdits = false; for (URI editsDirName : fsEditsDirs) { if (editsDirName.compareTo(dirName) == 0) { isAlsoEdits = true; fsEditsDirs.remove(editsDirName); break; } } NameNodeDirType dirType = (isAlsoEdits) ? NameNodeDirType.IMAGE_AND_EDITS : NameNodeDirType.IMAGE; // Add to the list of storage directories, only if the // URI is of type file:// if (dirName.getScheme().compareTo(JournalType.FILE.name().toLowerCase()) == 0) { this.addStorageDir(new NNStorageDirectory(new File(dirName.getPath()), dirType, locationMap == null ? null : locationMap.get(dirName))); } } // Add edits dirs if they are different from name dirs for (URI dirName : fsEditsDirs) { checkSchemeConsistency(dirName); // Add to the list of storage directories, only if the // URI is of type file:// if (dirName.getScheme().compareTo(JournalType.FILE.name().toLowerCase()) == 0) this.addStorageDir(new NNStorageDirectory(new File(dirName.getPath()), NameNodeDirType.EDITS, locationMap == null ? null : locationMap.get(dirName))); } }
From source file:org.apache.jxtadoop.fs.FsShell.java
/** * Move files that match the file pattern <i>srcf</i> * to a destination file.//from w ww. ja v a 2s.c o m * When moving mutiple files, the destination must be a directory. * Otherwise, IOException is thrown. * @param srcf a file pattern specifying source files * @param dstf a destination local file/directory * @throws IOException * @see org.apache.jxtadoop.fs.FileSystem#globStatus(Path) */ void rename(String srcf, String dstf) throws IOException { Path srcPath = new Path(srcf); Path dstPath = new Path(dstf); FileSystem srcFs = srcPath.getFileSystem(getConf()); FileSystem dstFs = dstPath.getFileSystem(getConf()); URI srcURI = srcFs.getUri(); URI dstURI = dstFs.getUri(); if (srcURI.compareTo(dstURI) != 0) { throw new IOException("src and destination filesystems do not match."); } Path[] srcs = FileUtil.stat2Paths(srcFs.globStatus(srcPath), srcPath); Path dst = new Path(dstf); if (srcs.length > 1 && !srcFs.isDirectory(dst)) { throw new IOException("When moving multiple files, " + "destination should be a directory."); } for (int i = 0; i < srcs.length; i++) { if (!srcFs.rename(srcs[i], dst)) { FileStatus srcFstatus = null; FileStatus dstFstatus = null; try { srcFstatus = srcFs.getFileStatus(srcs[i]); } catch (FileNotFoundException e) { throw new FileNotFoundException(srcs[i] + ": No such file or directory"); } try { dstFstatus = dstFs.getFileStatus(dst); } catch (IOException e) { } if ((srcFstatus != null) && (dstFstatus != null)) { if (srcFstatus.isDir() && !dstFstatus.isDir()) { throw new IOException( "cannot overwrite non directory " + dst + " with directory " + srcs[i]); } } throw new IOException("Failed to rename " + srcs[i] + " to " + dst); } } }