List of usage examples for java.net URI getPath
public String getPath()
From source file:com.shmsoft.dmass.main.ActionStaging.java
private boolean downloadUri(String[] dirs) throws Exception { boolean anyDownload = false; File downloadDirFile = new File(ParameterProcessing.DOWNLOAD_DIR); if (downloadDirFile.exists()) { Util.deleteDirectory(downloadDirFile); }/* w w w . j ava 2 s .co m*/ new File(ParameterProcessing.DOWNLOAD_DIR).mkdirs(); List<DownloadItem> downloadItems = new ArrayList<>(); for (String dir : dirs) { URI uri = null; String path; String savePath; try { uri = new URI(dir); path = uri.getPath(); path = StringUtils.replace(path, "/", ""); savePath = ParameterProcessing.DOWNLOAD_DIR + "/" + path; DownloadItem di = new DownloadItem(); di.uri = uri; di.file = dir; di.savePath = savePath; downloadItems.add(di); } catch (URISyntaxException e) { History.appendToHistory("Incorrect URI syntax, skipping that: " + uri); continue; } } setDownloadState(downloadItems.size()); for (DownloadItem di : downloadItems) { try { if (interrupted) { return anyDownload; } setProcessingFile(di.uri.toString()); URL url = new URL(di.file); URLConnection con = url.openConnection(); BufferedInputStream in = new BufferedInputStream(con.getInputStream()); FileOutputStream out = new FileOutputStream(di.savePath); History.appendToHistory("Download from " + di.uri + " to " + di.savePath); int i; byte[] bytesIn = new byte[1024]; while ((i = in.read(bytesIn)) >= 0) { out.write(bytesIn, 0, i); } out.close(); in.close(); anyDownload = true; File downloadedFile = new File(di.savePath); totalSize += downloadedFile.length(); progress(1); } catch (Exception e) { System.out.println(e.getMessage()); } } return anyDownload; }
From source file:org.semantictools.frame.api.OntologyManager.java
private File repoDir(String assetURI) { try {//from w w w.j a va2 s. c o m URI uri = new URI(assetURI); String path = uri.getAuthority() + "/" + uri.getPath(); return new File(localRepository, path); } catch (Throwable oops) { return null; } }
From source file:com.switchfly.inputvalidation.sanitizer.UrlStripHtmlSanitizer.java
@Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; }//from w w w. ja v a2s . co m URI uri; try { uri = new URI(content); } catch (URISyntaxException e) { throw new RuntimeException(e); } List<NameValuePair> cleanedPairs = parse(uri); String queryString = cleanedPairs.isEmpty() ? null : URLEncodedUtils.format(cleanedPairs, ENCODING); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryString, uri.getFragment()).toString(); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:org.dkpro.lab.engine.impl.DefaultTaskContextFactory.java
protected void resolveImports(TaskContext aContext) { for (Entry<String, String> e : aContext.getMetadata().getImports().entrySet()) { URI uri = URI.create(e.getValue()); // Try resolving by type if (LATEST_CONTEXT_SCHEME.equals(uri.getScheme()) || CONTEXT_ID_SCHEME.equals(uri.getScheme())) { String uuid;/*from w w w. j a v a2 s . c o m*/ uuid = aContext.resolve(uri).getId(); if (!getStorageService().containsKey(uuid, uri.getPath())) { throw new UnresolvedImportException(aContext, e.getKey(), e.getValue(), "Key not found"); } String resolvedUri = CONTEXT_ID_SCHEME + "://" + uuid + uri.getPath(); log.debug("Resolved import [" + e.getValue() + "] -> [" + resolvedUri + "]"); e.setValue(resolvedUri); } } }
From source file:org.droidparts.http.CookieJar.java
private List<Cookie> parseCookies(URI uri, List<String> cookieHeaders) { ArrayList<Cookie> cookies = new ArrayList<Cookie>(); int port = (uri.getPort() < 0) ? 80 : uri.getPort(); boolean secure = "https".equals(uri.getScheme()); CookieOrigin origin = new CookieOrigin(uri.getHost(), port, uri.getPath(), secure); for (String cookieHeader : cookieHeaders) { BasicHeader header = new BasicHeader(SM.SET_COOKIE, cookieHeader); try {/* w ww .ja v a 2 s. c om*/ cookies.addAll(cookieSpec.parse(header, origin)); } catch (MalformedCookieException e) { L.d(e); } } return cookies; }
From source file:com.almende.eve.transport.http.embed.JettyLauncher.java
@Override public void add(final Servlet servlet, final URI servletPath, final ObjectNode config) throws ServletException { // TODO: config hierarchy... if (server == null) { if (config != null) { initServer((ObjectNode) config.get("jetty")); } else {//from w w w. j a v a2 s . c o m initServer(JOM.createObjectNode()); } } LOG.info("Registering servlet:" + servletPath.getPath()); ServletHolder sh = new ServletHolder(servlet); if (config.has("initParams")) { ArrayNode params = (ArrayNode) config.get("initParams"); for (JsonNode param : params) { LOG.warning("Setting init param:" + param.toString()); sh.setInitParameter(param.get("key").asText(), param.get("value").asText()); } } context.addServlet(sh, servletPath.getPath() + "*"); }
From source file:com.jrodeo.remote.TestHttpCore.java
Stats execute(final URI target, final byte[] content, int n, int c) throws Exception { this.pool.setMaxTotal(2000); this.pool.setDefaultMaxPerRoute(c); HttpHost targetHost = new HttpHost(target.getHost(), target.getPort()); StringBuilder buffer = new StringBuilder(); buffer.append(target.getPath()); if (target.getQuery() != null) { buffer.append("?"); buffer.append(target.getQuery()); }//from w w w . j a va2 s .c o m String requestUri = buffer.toString(); Stats stats = new Stats(n, c); WorkerThread[] workers = new WorkerThread[c]; for (int i = 0; i < workers.length; i++) { workers[i] = new WorkerThread(stats, targetHost, requestUri, content); } for (int i = 0; i < workers.length; i++) { workers[i].start(); } for (int i = 0; i < workers.length; i++) { workers[i].join(); } return stats; }
From source file:org.elasticsearch.plugin.PluginManagerTests.java
/** * Retrieve a URL string that represents the resource with the given {@code resourceName}. * @param resourceName The resource name relative to {@link PluginManagerTests}. * @return Never {@code null}.//from w ww .java 2 s . c o m * @throws NullPointerException if {@code resourceName} does not point to a valid resource. */ private String getPluginUrlForResource(String resourceName) { URI uri = URI.create(PluginManagerTests.class.getResource(resourceName).toString()); return "file://" + uri.getPath(); }
From source file:com.metamx.druid.indexing.common.index.StaticS3FirehoseFactory.java
@Override public Firehose connect() throws IOException { Preconditions.checkNotNull(s3Client, "null s3Client"); return new Firehose() { LineIterator lineIterator = null; final Queue<URI> objectQueue = Lists.newLinkedList(uris); // Rolls over our streams and iterators to the next file, if appropriate private void maybeNextFile() throws Exception { if (lineIterator == null || !lineIterator.hasNext()) { // Close old streams, maybe. if (lineIterator != null) { lineIterator.close(); }//ww w . jav a 2 s. c o m // Open new streams, maybe. final URI nextURI = objectQueue.poll(); if (nextURI != null) { final String s3Bucket = nextURI.getAuthority(); final S3Object s3Object = new S3Object( nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath()); log.info("Reading from bucket[%s] object[%s] (%s)", s3Bucket, s3Object.getKey(), nextURI); int ntry = 0; try { final InputStream innerInputStream = s3Client.getObject(s3Bucket, s3Object.getKey()) .getDataInputStream(); final InputStream outerInputStream = s3Object.getKey().endsWith(".gz") ? new GZIPInputStream(innerInputStream) : innerInputStream; lineIterator = IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (IOException e) { log.error(e, "Exception reading from bucket[%s] object[%s] (try %d) (sleeping %d millis)", s3Bucket, s3Object.getKey(), ntry, retryMillis); ntry++; if (ntry <= retryCount) { Thread.sleep(retryMillis); } } } } } @Override public boolean hasMore() { try { maybeNextFile(); } catch (Exception e) { throw Throwables.propagate(e); } return lineIterator != null && lineIterator.hasNext(); } @Override public InputRow nextRow() { try { maybeNextFile(); } catch (Exception e) { throw Throwables.propagate(e); } if (lineIterator == null) { throw new NoSuchElementException(); } return parser.parse(lineIterator.next()); } @Override public Runnable commit() { // Do nothing. return new Runnable() { public void run() { } }; } @Override public void close() throws IOException { objectQueue.clear(); if (lineIterator != null) { lineIterator.close(); } } }; }
From source file:com.sina.cloudstorage.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.schemeSpecificPart = uri.getSchemeSpecificPart(); this.authority = uri.getAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.userInfo = uri.getUserInfo(); this.path = uri.getPath(); this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8); this.fragment = uri.getFragment(); }