List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:org.fcrepo.apix.integration.StreamingIT.java
/** * Appends the path to the URI. All other components of the URI are preserved. * * @param uri the URI with the path being appended to * @param toAppend the path to be appended to the URI * @return a new URI with a path component ending with {@code toAppend} * @throws URISyntaxException/*from w w w. ja v a2 s. c o m*/ */ private static URI appendToPath(final URI uri, final String toAppend) throws URISyntaxException { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath() + toAppend, uri.getRawQuery(), uri.getRawFragment()); }
From source file:org.esigate.util.UriUtils.java
/** * Interpret the url relatively to the request url (may be relative). Due to a bug in {@link URI} class when using a * relUri containing only a query string, we cannot use directly the method provided by {@link URI} class. * /*from w w w . ja v a 2 s . co m*/ * @param relUri * the relative URI * @param base * the reference {@link URI} * @return the resolved {@link URI} */ public static URI resolve(String relUri, URI base) { URI uri = createURI(relUri); if (uri.getScheme() == null && uri.getUserInfo() == null && uri.getHost() == null && uri.getPort() == -1 && StringUtils.isEmpty(uri.getPath()) && uri.getQuery() != null) { try { return new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new InvalidUriException(e); } } else { return base.resolve(uri); } }
From source file:org.esigate.util.UriUtils.java
/** * Removes the query and fragment at the end of a URI. * /*from ww w .j a va 2 s . co m*/ * @param uriString * the original URI as a String * * @return the URI without querystring nor fragment */ public static String removeQuerystring(String uriString) { URI uri = createURI(uriString); try { return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null).toASCIIString(); } catch (URISyntaxException e) { throw new InvalidUriException(e); } }
From source file:com.jaeksoft.searchlib.util.LinkUtils.java
public final static URL getLink(URL currentURL, String href, UrlFilterItem[] urlFilterList, boolean removeFragment) { if (href == null) return null; href = href.trim();/*from ww w .ja va 2 s . co m*/ if (href.length() == 0) return null; String fragment = null; try { URI u = URIUtils.resolve(currentURL.toURI(), href); href = u.toString(); href = UrlFilterList.doReplace(u.getHost(), href, urlFilterList); URI uri = URI.create(href); uri = uri.normalize(); String p = uri.getPath(); if (p != null) if (p.contains("/./") || p.contains("/../")) return null; if (!removeFragment) fragment = uri.getRawFragment(); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), fragment).normalize().toURL(); } catch (MalformedURLException e) { Logging.info(e.getMessage()); return null; } catch (URISyntaxException e) { Logging.info(e.getMessage()); return null; } catch (IllegalArgumentException e) { Logging.info(e.getMessage()); return null; } }
From source file:org.apache.activemq.artemis.utils.uri.URISchema.java
protected static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception { synchronized (beanUtils) { beanUtils.setProperty(obj, "host", uri.getHost()); beanUtils.setProperty(obj, "port", uri.getPort()); beanUtils.setProperty(obj, "userInfo", uri.getUserInfo()); beanUtils.populate(obj, query);// w ww . j a v a 2 s . c o m } return obj; }
From source file:org.bibalex.gallery.storage.BAGStorage.java
public static boolean putFile(String remoteUrlStr, File localFile, String contentType, int timeout) throws BAGException { HttpPut httpput = null;// ww w.j a v a2 s . c o m DefaultHttpClient httpclient = null; try { BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, timeout); httpclient = new DefaultHttpClient(httpParams); URI remoteUrl = new URI(remoteUrlStr); String userInfo = remoteUrl.getUserInfo(); if ((userInfo != null) && !userInfo.isEmpty()) { int colonIx = userInfo.indexOf(':'); httpclient.getCredentialsProvider().setCredentials( new AuthScope(remoteUrl.getHost(), remoteUrl.getPort()), new UsernamePasswordCredentials( userInfo.substring(0, colonIx), userInfo.substring(colonIx + 1))); } if ((contentType == null) || contentType.isEmpty()) { contentType = "text/plain; charset=\"UTF-8\""; } FileEntity entity = new FileEntity(localFile, contentType); httpput = new HttpPut(remoteUrlStr); httpput.setEntity(entity); HttpResponse response = httpclient.execute(httpput); return response.getStatusLine().getStatusCode() - 200 < 100; } catch (IOException ex) { // In case of an IOException the connection will be released // back to the connection manager automatically throw new BAGException(ex); } catch (RuntimeException ex) { // In case of an unexpected exception you may want to abort // the HTTP request in order to shut down the underlying // connection and release it back to the connection manager. httpput.abort(); throw ex; } catch (URISyntaxException e) { // will be still null: httpput.abort(); throw new BAGException(e); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.igormaznitsa.zxpoly.utils.ROMLoader.java
public static RomData getROMFrom(final String url) throws IOException { final URI uri; try {//ww w .j a va2 s. co m uri = new URI(url); } catch (URISyntaxException ex) { throw new IOException("Error in URL '" + url + "\'", ex); } final String scheme = uri.getScheme(); final String userInfo = uri.getUserInfo(); final String name; final String password; if (userInfo != null) { final String[] splitted = userInfo.split("\\:"); name = splitted[0]; password = splitted[1]; } else { name = null; password = null; } final byte[] loaded; if (scheme.startsWith("http")) { loaded = loadHTTPArchive(url); } else if (scheme.startsWith("ftp")) { loaded = loadFTPArchive(uri.getHost(), uri.getPath(), name, password); } else { throw new IllegalArgumentException("Unsupported scheme [" + scheme + ']'); } final ZipArchiveInputStream in = new ZipArchiveInputStream(new ByteArrayInputStream(loaded)); byte[] rom48 = null; byte[] rom128 = null; byte[] romTrDos = null; while (true) { final ZipArchiveEntry entry = in.getNextZipEntry(); if (entry == null) { break; } if (entry.isDirectory()) { continue; } if (ROM_48.equalsIgnoreCase(entry.getName())) { final int size = (int) entry.getSize(); if (size > 16384) { throw new IOException("ROM 48 has too big size"); } rom48 = new byte[16384]; IOUtils.readFully(in, rom48, 0, size); } else if (ROM_128TR.equalsIgnoreCase(entry.getName())) { final int size = (int) entry.getSize(); if (size > 16384) { throw new IOException("ROM 128TR has too big size"); } rom128 = new byte[16384]; IOUtils.readFully(in, rom128, 0, size); } else if (ROM_TRDOS.equalsIgnoreCase(entry.getName())) { final int size = (int) entry.getSize(); if (size > 16384) { throw new IOException("ROM TRDOS has too big size"); } romTrDos = new byte[16384]; IOUtils.readFully(in, romTrDos, 0, size); } } if (rom48 == null) { throw new IOException(ROM_48 + " not found"); } if (rom128 == null) { throw new IOException(ROM_128TR + " not found"); } if (romTrDos == null) { throw new IOException(ROM_TRDOS + " not found"); } return new RomData(rom48, rom128, romTrDos); }
From source file:com.collective.celos.Util.java
public static String augmentHdfsPath(String hdfsPrefix, String path) throws URISyntaxException { if (hdfsPrefix.isEmpty() || hdfsPrefix.equals("/")) { return path; }/*from ww w . j a va2 s . c om*/ for (String ch : conversions.keySet()) { path = path.replace(ch.toString(), conversions.get(ch).toString()); } URI oldUri = URI.create(path); String host = oldUri.getHost(); if (oldUri.getRawSchemeSpecificPart().startsWith("///") && host == null) { host = ""; } URI newUri = new URI(oldUri.getScheme(), oldUri.getUserInfo(), host, oldUri.getPort(), hdfsPrefix + oldUri.getPath(), oldUri.getQuery(), oldUri.getFragment()); path = newUri.toString(); for (String ch : backConversions.keySet()) { path = path.replace(ch.toString(), backConversions.get(ch).toString()); } return path; }
From source file:org.moe.cli.utils.GrabUtils.java
private static @Nullable String[] parseGitURI(@NonNull URI git) throws URISyntaxException { String path = git.getPath();/* www . j ava 2 s .com*/ if (path.endsWith(".git")) { String[] toRet = new String[3]; //{git,tag,path} toRet[0] = new URI(git.getScheme(), git.getUserInfo(), git.getHost(), git.getPort(), path, null, null) .toString(); //git String fragment = git.getFragment(); if (fragment != null) { int colonIdx = fragment.indexOf(':'); if (colonIdx > 0) { //tag exists toRet[1] = fragment.substring(0, colonIdx); toRet[2] = fragment.substring(colonIdx + 1); } else { toRet[2] = fragment; } } return toRet; } else { return null; } }
From source file:org.dhatim.resource.URIResourceLocator.java
/** * Extract the base URI from the supplied resource URI. * @param resourceURI The resource URI.//w w w . j a va 2 s .co m * @return The base URI for the supplied resource URI. */ public static URI extractBaseURI(URI resourceURI) { File resFile = new File(resourceURI.getPath()); try { File configFolder = resFile.getParentFile(); if (configFolder != null) { return new URI(resourceURI.getScheme(), resourceURI.getUserInfo(), resourceURI.getHost(), resourceURI.getPort(), configFolder.getPath().replace('\\', '/'), resourceURI.getQuery(), resourceURI.getFragment()); } } catch (URISyntaxException e) { logger.debug("Error extracting base URI.", e); } return DEFAULT_BASE_URI; }