List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:com.collaborne.jsonschema.validator.plugin.ValidateMojo.java
@VisibleForTesting protected URITranslatorConfigurationBuilder addSchemaMappings(URITranslatorConfigurationBuilder builder) throws MojoExecutionException { for (DirectoryURIMapping schemaMapping : schemaMappings) { URI uri = schemaMapping.uri; if (uri.getFragment() != null) { throw new MojoExecutionException("URI " + uri + " must not contain a fragment"); }/* w w w .ja v a2 s . co m*/ if (!uri.isAbsolute()) { throw new MojoExecutionException("URI " + uri + " must be absolute"); } // Check the path (and fix it up for the obvious issues) String path = uri.getPath(); if (path == null) { path = "/"; } if (!path.endsWith("/")) { getLog().warn("URI " + uri + " does not end with '/'"); path += "/"; try { uri = new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { // Basically impossible: it was (syntactically) valid before that. throw new MojoExecutionException("Cannot construct fixed URI", e); } } getLog().debug("Mapping " + schemaMapping.directory + " to " + uri); builder.addPathRedirect(uri, schemaMapping.directory.toURI()); } return builder; }
From source file:org.apache.hadoop.fs.http.client.HttpFSFileSystem.java
/** * Convenience method that creates a <code>HttpURLConnection</code> for the * HttpFSServer file system operations.//from w ww . j a v a 2 s . co m * <p/> * This methods performs and injects any needed authentication credentials * via the {@link #getConnection(URL, String)} method * * @param method * the HTTP method. * @param params * the query string parameters. * @param path * the file path * @param makeQualified * if the path should be 'makeQualified' * * @return a <code>HttpURLConnection</code> for the HttpFSServer server, * authenticated and ready to use for the specified path and file * system operation. * * @throws IOException * thrown if an IO error occurrs. */ private HttpURLConnection getConnection(String method, Map<String, String> params, Path path, boolean makeQualified) throws IOException { // params.put(DO_AS_PARAM, doAs); //todo ? params.put("user.name", doAs); if (makeQualified) { path = makeQualified(path); } URI uri = path.toUri(); StringBuilder sb = new StringBuilder(); sb.append(uri.getScheme()).append("://").append(uri.getAuthority()).append(SERVICE_PREFIX) .append(uri.getPath()); String separator = "?"; for (Map.Entry<String, String> entry : params.entrySet()) { sb.append(separator).append(entry.getKey()).append("=") .append(URLEncoder.encode(entry.getValue(), "UTF8")); separator = "&"; } URL url = new URL(sb.toString()); return getConnection(url, method); }
From source file:org.apache.ignite.hadoop.fs.v2.IgniteHadoopFileSystem.java
/** {@inheritDoc} */ @Override/*from ww w . ja va2 s.c o m*/ public void checkPath(Path path) { URI uri = path.toUri(); if (uri.isAbsolute()) { if (!F.eq(uri.getScheme(), IGFS_SCHEME)) throw new InvalidPathException( "Wrong path scheme [expected=" + IGFS_SCHEME + ", actual=" + uri.getAuthority() + ']'); if (!F.eq(uri.getAuthority(), uriAuthority)) throw new InvalidPathException( "Wrong path authority [expected=" + uriAuthority + ", actual=" + uri.getAuthority() + ']'); } }
From source file:org.apache.hadoop.hive.ql.Context.java
private Path getExternalScratchDir(URI extURI) { return getStagingDir(new Path(extURI.getScheme(), extURI.getAuthority(), extURI.getPath()), !isExplainSkipExecution());//from w ww . j a v a 2 s . co m }
From source file:gobblin.data.management.copy.hive.HiveCopyEntityHelper.java
/** * Get builders for a {@link CopyableFile} for each file referred to by a {@link org.apache.hadoop.hive.metastore.api.StorageDescriptor}. *//* ww w. j ava 2 s . c om*/ List<CopyableFile.Builder> getCopyableFilesFromPaths(Collection<FileStatus> paths, CopyConfiguration configuration, Optional<Partition> partition) throws IOException { List<CopyableFile.Builder> builders = Lists.newArrayList(); List<SourceAndDestination> dataFiles = Lists.newArrayList(); Configuration hadoopConfiguration = new Configuration(); FileSystem actualSourceFs = null; String referenceScheme = null; String referenceAuthority = null; for (FileStatus status : paths) { dataFiles.add(new SourceAndDestination(status, getTargetPathHelper().getTargetPath(status.getPath(), this.targetFs, partition, true))); } for (SourceAndDestination sourceAndDestination : dataFiles) { URI uri = sourceAndDestination.getSource().getPath().toUri(); if (actualSourceFs == null || !StringUtils.equals(referenceScheme, uri.getScheme()) || !StringUtils.equals(referenceAuthority, uri.getAuthority())) { actualSourceFs = sourceAndDestination.getSource().getPath().getFileSystem(hadoopConfiguration); referenceScheme = uri.getScheme(); referenceAuthority = uri.getAuthority(); } if (!this.dataset.getTableRootPath().isPresent()) { // The logic for computing ancestor owner and permissions for hive copies depends on tables having a non-glob // location. Currently, this restriction is also imposed by Hive, so this is not a problem. If this ever changes // on the Hive side, and we try to copy a table with a glob location, this logic will have to change. throw new IOException(String.format("Table %s does not have a concrete table root path.", this.dataset.getTable().getCompleteName())); } List<OwnerAndPermission> ancestorOwnerAndPermission = CopyableFile .resolveReplicatedOwnerAndPermissionsRecursively(actualSourceFs, sourceAndDestination.getSource().getPath().getParent(), this.dataset.getTableRootPath().get().getParent(), configuration); builders.add(CopyableFile .fromOriginAndDestination(actualSourceFs, sourceAndDestination.getSource(), sourceAndDestination.getDestination(), configuration) .ancestorsOwnerAndPermission(ancestorOwnerAndPermission)); } return builders; }
From source file:org.apache.hadoop.hive.ql.Context.java
/** * Create a local scratch directory on demand and return it. *///from w ww .jav a 2 s. c om public Path getLocalScratchDir(boolean mkdir) { try { FileSystem fs = FileSystem.getLocal(conf); URI uri = fs.getUri(); return getScratchDir(uri.getScheme(), uri.getAuthority(), mkdir, localScratchDir); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.aliyun.fs.oss.nat.NativeOssFileSystem.java
@Override public void initialize(URI uri, Configuration conf) throws IOException { super.initialize(uri, conf); if (store == null) { store = createDefaultStore(conf); }/*from w ww . j a v a 2s . c om*/ try { store.initialize(uri, conf); } catch (Exception e) { LOG.warn(e.getMessage()); throw new IOException(e); } setConf(conf); this.uri = URI.create(uri.getScheme() + "://" + uri.getAuthority()); this.bufferSize = conf.getInt("fs.oss.readBuffer.size", 64 * 1024 * 1024); // do not suggest to use too large buffer in case of GC issue or OOM. if (this.bufferSize >= 256 * 1024 * 1024) { LOG.warn("'fs.oss.readBuffer.size' is " + bufferSize + ", it's to large and system will suppress it down " + "to '268435456' automatically."); this.bufferSize = 256 * 1024 * 1024; } this.conf = conf; this.algorithmVersion = conf.getInt(OSSREADER_ALGORITHM_VERSION, OSSREADER_ALGORITHM_VERSION_DEFAULT); if (algorithmVersion != 1 && algorithmVersion != 2) { throw new IOException("Only 1 or 2 algorithm version is supported"); } }
From source file:de.zib.sfs.StatisticsFileSystem.java
private static URI replaceUriScheme(URI uri, String from, String to) { // TODO add cache for replaced URIs? possibly useful for scenarios with // many metadata operations. String scheme = uri.getScheme(); if (scheme != null) { if (scheme.equalsIgnoreCase(from)) { // uri has this scheme, replace it with new scheme // re-create the URI from scratch to avoid escaping of wanted // illegal characters StringBuilder buffer = new StringBuilder(); buffer.append(to).append(":"); String authority = uri.getAuthority(); if (authority != null) { buffer.append("//").append(authority); }// w w w. ja v a2 s. c om String path = uri.getPath(); if (path != null) { buffer.append(path); } String fragment = uri.getFragment(); if (fragment != null) { buffer.append("#").append(fragment); } return URI.create(buffer.toString()); } else if (scheme.equalsIgnoreCase(to)) { // uri already has the correct scheme if (LOG.isDebugEnabled()) { LOG.debug("URI '" + uri + "' already has the correct scheme '" + to + "'."); } return null; } else { // uri has wrong scheme return null; } } // uri has no scheme return null; }
From source file:org.apache.hadoop.hive.ql.Context.java
/** * Create a map-reduce scratch directory on demand and return it. * *///from w w w . j a va 2 s. c o m public Path getMRScratchDir() { // if we are executing entirely on the client side - then // just (re)use the local scratch directory if (isLocalOnlyExecutionMode()) { return getLocalScratchDir(!isExplainSkipExecution()); } try { Path dir = FileUtils.makeQualified(nonLocalScratchPath, conf); URI uri = dir.toUri(); Path newScratchDir = getScratchDir(uri.getScheme(), uri.getAuthority(), !isExplainSkipExecution(), uri.getPath()); LOG.info("New scratch dir is " + newScratchDir); return newScratchDir; } catch (IOException e) { throw new RuntimeException(e); } catch (IllegalArgumentException e) { throw new RuntimeException( "Error while making MR scratch " + "directory - check filesystem config (" + e.getCause() + ")", e); } }
From source file:eu.stratosphere.nephele.fs.s3.S3FileSystem.java
static Path extendPath(final Path parent, final String extension) throws IOException { final URI parentUri = parent.toUri(); if (extension.isEmpty()) { return parent; }/*from www .j a v a2 s. c o m*/ final String path = parentUri.getPath(); String extendedPath; if (path.isEmpty()) { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { extendedPath = extension; } else { extendedPath = Path.SEPARATOR + extension; } } else { if (path.charAt(path.length() - 1) == Path.SEPARATOR_CHAR) { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { if (extension.length() > 1) { extendedPath = path + extension.substring(1); } else { extendedPath = path; } } else { extendedPath = path + extension; } } else { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { extendedPath = path + extension; } else { extendedPath = path + Path.SEPARATOR + extension; } } } try { final URI extendedUri = new URI(parentUri.getScheme(), ((parentUri.getAuthority() != null) ? parentUri.getAuthority() : ""), extendedPath, parentUri.getQuery(), parentUri.getFragment()); return new Path(extendedUri); } catch (URISyntaxException e) { throw new IOException(StringUtils.stringifyException(e)); } }