List of usage examples for java.net URI relativize
public URI relativize(URI uri)
From source file:stargate.drivers.temporalstorage.hdfs.HDFSTemporalStorageDriver.java
@Override public Collection<TemporalFileMetadata> listDirectoryWithMetadata(URI path) throws IOException, FileNotFoundException { if (path == null) { throw new IllegalArgumentException("path is null"); }//from w ww . jav a 2s . co m Path hdfsPath = getAbsPath(path); if (!this.filesystem.exists(hdfsPath)) { throw new FileNotFoundException("directory (" + hdfsPath.toString() + ") not exist"); } FileStatus[] listStatus = this.filesystem.listStatus(hdfsPath); List<TemporalFileMetadata> entries = new ArrayList<TemporalFileMetadata>(); if (listStatus != null && listStatus.length > 0) { for (FileStatus status : listStatus) { URI entryPath = status.getPath().toUri(); URI relativePath = entryPath.relativize(this.rootPath.toUri()); TemporalFileMetadata metadata = new TemporalFileMetadata(relativePath, status.isDir(), status.getLen(), status.getModificationTime()); entries.add(metadata); } } return entries; }
From source file:com.infosupport.ellison.core.archive.ApplicationArchiveTest.java
@Test(expected = IllegalArgumentException.class) public void testFindFilesByGlobPattern_NotADirectory() throws Exception { applicationArchive.unpackJar();//from w w w . jav a 2 s .co m URI unpackedPathURI = ((File) PrivateAccessor.getField(applicationArchive, "unpackedPath")).toURI(); String existingFile = unpackedPathURI .relativize(applicationArchive.findFilesByGlobPattern(null, "*").iterator().next()).toString(); applicationArchive.findFilesByGlobPattern(existingFile, ""); }
From source file:org.deegree.workspace.standard.DefaultLocationHandler.java
@Override public <T extends Resource> List<ResourceLocation<T>> findResourceLocations( ResourceManagerMetadata<T> metadata) { List<ResourceLocation<T>> list = new ArrayList<ResourceLocation<T>>(); if (extraResources.get(metadata.getProviderClass()) != null) { list.addAll((Collection) extraResources.get(metadata.getProviderClass())); }/*from w ww. ja v a2 s.c om*/ File dir = new File(directory, metadata.getWorkspacePath()); if (!dir.isDirectory()) { return list; } URI base = dir.getAbsoluteFile().toURI(); for (File f : FileUtils.listFiles(dir, new String[] { "xml", "ignore" }, true)) { URI uri = f.getAbsoluteFile().toURI(); uri = base.relativize(uri); String p = uri.getPath(); ResourceState state = null; if (p.endsWith("xml")) { p = p.substring(0, p.length() - 4); } else { p = p.substring(0, p.length() - 7); state = ResourceState.Deactivated; } DefaultResourceIdentifier<T> identifier = new DefaultResourceIdentifier<T>(metadata.getProviderClass(), p); if (state != null) { states.setState(identifier, state); } list.add(new DefaultResourceLocation<T>(f, identifier)); } return list; }
From source file:org.structr.schema.export.StructrSchemaDefinition.java
@Override public Object resolveURI(final URI uri) { final URI id = getId(); if (id != null) { final URI rel = id.relativize(uri); if (!rel.isAbsolute()) { final String relString = "#/" + rel.toString(); return resolveJsonPointer(relString); }/*from w w w. j a va 2 s . c om*/ } return null; }
From source file:org.esigate.impl.UrlRewriter.java
/** * Fixes a referer url in a request.//from www . j a va 2 s. c om * * @param referer * the url to fix (can be anything found in an html page, relative, absolute, empty...) * @param baseUrl * The base URL selected for this request. * @param visibleBaseUrl * The base URL viewed by the browser. * * @return the fixed url. */ public String rewriteReferer(String referer, String baseUrl, String visibleBaseUrl) { URI uri = UriUtils.createURI(referer); // Base url should end with / if (!baseUrl.endsWith("/")) { baseUrl = baseUrl + "/"; } URI baseUri = UriUtils.createURI(baseUrl); // If no visible url base is defined, use base url as visible base url if (!visibleBaseUrl.endsWith("/")) { visibleBaseUrl = visibleBaseUrl + "/"; } URI visibleBaseUri = UriUtils.createURI(visibleBaseUrl); // Relativize url to visible base url URI relativeUri = visibleBaseUri.relativize(uri); // If the url is unchanged do nothing if (relativeUri.equals(uri)) { LOG.debug("url kept unchanged: [{}]", referer); return referer; } // Else rewrite replacing baseUrl by visibleBaseUrl URI result = baseUri.resolve(relativeUri); LOG.debug("referer fixed: [{}] -> [{}]", referer, result); return result.toString(); }
From source file:edu.stolaf.cs.wmrserver.TransformProcessor.java
private File relativizeFile(File file, File relativeToFile) { URI fileURI = file.toURI();// ww w. ja va 2s .co m URI rtURI = relativeToFile.getAbsoluteFile().toURI(); return new File(rtURI.relativize(fileURI).getPath()); }
From source file:org.mule.endpoint.MuleEndpointURI.java
public URI relativize(URI uri) { return uri.relativize(uri); }
From source file:com.collaborne.jsonschema.generator.driver.GeneratorDriver.java
/** * Calculate type URIs for all the given {@code schemaFiles}. * * @param rootUri/*from w ww. j ava2s .c o m*/ * @param baseDirectory * @param schemaFiles * @return */ public Set<URI> getInitialTypes(URI rootUri, Path baseDirectory, List<Path> schemaFiles) { Set<URI> types = new HashSet<>(); URI baseDirectoryUri = baseDirectory.toAbsolutePath().normalize().toUri(); for (Path schemaFile : schemaFiles) { URI schemaFileUri = schemaFile.toAbsolutePath().normalize().toUri(); URI relativeSchemaUri = baseDirectoryUri.relativize(schemaFileUri); URI schemaUri = rootUri.resolve(relativeSchemaUri); types.add(schemaUri.resolve("#")); } return types; }
From source file:com.carrotgarden.maven.scr.CarrotOsgiScrGenerate.java
/** * Generate full java class name./*from w w w .ja v a 2 s . c o m*/ * * @return java class FQN */ protected String makeClassName(final File classesDirectory, final File classFile) { final URI folderURI = absolute(classesDirectory).toURI(); final URI fileURI = absolute(classFile).toURI(); final String path = folderURI.relativize(fileURI).getPath(); /** * Cut out file extension and convert to java class FQN. * <p> * from: com/carrotgarden/test/TestComp.class * <p> * into: com.carrotgarden.test.TestComp */ final int index = path.lastIndexOf("."); final String name = path.substring(0, index).replace("/", "."); return name; }
From source file:it.greenvulcano.util.zip.ZipHelper.java
private void internalZipFile(File srcFile, ZipOutputStream zos, URI base) throws IOException { String zipEntryName = base.relativize(srcFile.toURI()).getPath(); if (srcFile.isDirectory()) { zipEntryName = zipEntryName.endsWith("/") ? zipEntryName : zipEntryName + "/"; ZipEntry anEntry = new ZipEntry(zipEntryName); anEntry.setTime(srcFile.lastModified()); zos.putNextEntry(anEntry);//from w w w.java2s . c o m File[] dirList = srcFile.listFiles(); for (File file : dirList) { internalZipFile(file, zos, base); } } else { ZipEntry anEntry = new ZipEntry(zipEntryName); anEntry.setTime(srcFile.lastModified()); zos.putNextEntry(anEntry); FileInputStream fis = null; try { fis = new FileInputStream(srcFile); IOUtils.copy(fis, zos); zos.closeEntry(); } finally { try { if (fis != null) { fis.close(); } } catch (IOException exc) { // Do nothing } } } }