List of usage examples for java.net URI getScheme
public String getScheme()
From source file:at.ac.ait.ubicity.fileloader.FileLoader.java
/** * /* w ww . j a va2s .co m*/ * @param _uri the uri we must "patrol" * @param keySpace the Cassandra keyspace to use * @param host the Cassandra host / node * @param batchSize MutationBatch size for ingests * @param millisToWait the number of milliseconds we are supposed to wait before visiting the uri again * @throws FileNotFoundException if there is a problem with the given uri * @throws Exception if actually loading ( ingesting ) from some file under the uri leads to a problem * */ public final static void invigilate(URI _uri, String keySpace, String host, int batchSize, long millisToWait) throws FileNotFoundException, Exception { logger.info("[FILELOADER] invigilating URI: " + _uri); if (_uri.getScheme().equals("file")) { //we don't know yet if the URI is a directory or a file File _startingPoint = new File(_uri); File[] _files = getLogFilesFor(_startingPoint); FileCache cache = useCache ? LogFileCache.get().loadCache() : null; for (File file : _files) { logger.info("[FILELOADER] found file under " + _uri.toString() + " : " + file.getName()); doLoad(file, cache, keySpace, host, batchSize); } return; } logger.info("[FILELOADER] URI " + _uri.toString() + " is not something FileLoader can currently handle"); }
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 ava 2s . co m 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:net.certifi.audittablegen.AuditTableGen.java
/** * Convert the command arguments to properties must contain either a decipherable jdbc url or database and server * params, plus a username and password. * * @param cmd/*from w ww .j a v a 2 s . co m*/ * @return */ static Properties getRunTimeProperties(CommandLine cmd) { Boolean isValid = true; Properties prop = new Properties(); String driver = ""; String subSchema = ""; //should indicate the JDBC driver //set url property if (cmd.hasOption("url")) { String url = cmd.getOptionValue("url"); String subschema_uri = url.substring(5); //strip jdbc: //rudimentary url validation URI uri = URI.create(url); if (!uri.getScheme().equalsIgnoreCase("jdbc")) { logger.warn("Invalid url: '{}'", url); isValid = false; } else { uri = URI.create(subschema_uri); subSchema = uri.getScheme(); //driver reference hopefully } prop.setProperty("url", url); } //set driver property String cmdArgDriver = cmd.getOptionValue("driver", ""); if (subSchema.equalsIgnoreCase("postgresql")) { prop.setProperty("driver", "org.postgresql.Driver"); } else if (subSchema.equalsIgnoreCase("hsqldb")) { prop.setProperty("driver", "org.hsqldb.jdbcDriver"); } else if (cmdArgDriver.isEmpty()) { //best guess - this will almost certainly fail... prop.setProperty("driver", subSchema); } else { //unrecognized driver passed on command arg //will use it if it resolves on the class-path prop.setProperty("driver", cmd.getOptionValue("driver", "")); } //not going to worry about parsing db,server for now //just require a url, or connect to the in mem database List<String> argList = Arrays.asList("driver", "database", "server"); for (String arg : argList) { if (cmd.hasOption(arg)) { prop.setProperty(arg, cmd.getOptionValue(arg)); } else { logger.warn("Missing parameter: {}", arg); isValid = false; } } //more params (for now) //do not require - these can also be passed on the url if (true) { //(prop.containsKey("url")) { argList = Arrays.asList("username", "password", "schema"); for (String arg : argList) { if (cmd.hasOption(arg)) { prop.setProperty(arg, cmd.getOptionValue(arg)); // } else { // logger.warn("Missing parameter: {}", arg); // isValid = false; } } } //optional params - this is for the output script if (cmd.hasOption("filename")) { prop.setProperty("filename", cmd.getOptionValue("filename")); } prop.setProperty("validArgs", isValid ? "true" : "false"); return prop; }
From source file:com.aaasec.sigserv.cscommon.xmldsig.OfflineResolver.java
private static URI getNewURI(String uri, String baseURI) throws URISyntaxException { URI newUri = null; if (baseURI == null || "".equals(baseURI)) { newUri = new URI(uri); } else {/*from w ww . j av a 2 s. com*/ newUri = new URI(baseURI).resolve(uri); } // if the URI contains a fragment, ignore it if (newUri.getFragment() != null) { URI uriNewNoFrag = new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null); return uriNewNoFrag; } return newUri; }
From source file:com.ibm.amc.FileManager.java
/** * Resolve an input URI to one suitable for WAMT. If the URI represents a temporary file, * converts it to the real file location. * /*from w w w . j a v a2 s . c om*/ * @param uri * the input URI * @return the output URI */ public static URI resolveUri(URI uri) { return (SCHEME.equals(uri.getScheme())) ? getFileForUri(uri).toURI() : uri; }
From source file:com.dianping.resource.io.util.ResourceUtils.java
/** * Resolve the given resource URI to a {@code java.io.File}, * i.e. to a file in the file system.// w w w. j a v a2 s. c om * @param resourceUri the resource URI to resolve * @param description a description of the original resource that * the URI was created for (for example, a class path location) * @return a corresponding File object * @throws java.io.FileNotFoundException if the URL cannot be resolved to * a file in the file system */ public static File getFile(URI resourceUri, String description) throws FileNotFoundException { Assert.notNull(resourceUri, "Resource URI must not be null"); if (!URL_PROTOCOL_FILE.equals(resourceUri.getScheme())) { throw new FileNotFoundException(description + " cannot be resolved to absolute file path " + "because it does not reside in the file system: " + resourceUri); } return new File(resourceUri.getSchemeSpecificPart()); }
From source file:com.ibm.amc.FileManager.java
/** * If the URI represents a temporary file, attempt to delete the corresponding file. * // w w w . j ava2 s . co m * @param uri */ public static void deleteIfTemporaryFile(URI uri) { if (uri != null && uri.getScheme().equals(SCHEME)) { if (getFileForUri(uri).delete()) { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Deleted temporary file " + uri.toString()); } else { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Failed to delete temporary file " + uri.toString()); } // Check for unzip directory final File unzipDirectory = new File(getDownloadDirectory(), uri.getSchemeSpecificPart()); if (unzipDirectory.exists()) { try { FileUtils.deleteDirectory(unzipDirectory); if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Deleted temporary directory " + unzipDirectory); } catch (final IOException e) { if (logger.isDebugEnabled()) logger.debug("deleteIfTemporaryFile", "Failed to delete temporary directory " + unzipDirectory); } } } }
From source file:com.taobao.datax.plugins.common.DFSUtils.java
/** * Initialize handle of {@link FileSystem}. * /*from w w w.ja v a 2s . c om*/ * @param uri * URI * * @param conf * {@link Configuration} * * @return an FileSystem instance */ public static FileSystem createFileSystem(URI uri, Configuration conf) throws IOException { Class<?> clazz = conf.getClass("fs." + uri.getScheme() + ".impl", null); if (clazz == null) { throw new IOException("No FileSystem for scheme: " + uri.getScheme()); } FileSystem fs = (FileSystem) ReflectionUtils.newInstance(clazz, conf); fs.initialize(uri, conf); return fs; }
From source file:com.microsoft.tfs.client.common.ui.protocolhandler.ProtocolHandler.java
static URI findProtocolHandlerUriArgument(final String[] applicationArgs) { if (applicationArgs == null) { return null; }/* w w w. ja va2 s .co m*/ boolean found = false; /* * @formatter:off * We're looking for a protocol handler argument among all command line * arguments passed by eclipse.launcher to the Eclipse application. The * protocol handler argument should have the following syntax: * * -clonefromtfs <uri> * * At this point we do not parse the value of the argument. We'll do it later. * @formatter:on */ for (final String arg : applicationArgs) { if (found) { log.info(MessageFormat.format("Found the protocol handler argument: {0} {1}", //$NON-NLS-1$ PROTOCOL_HANDLER_ARG, arg)); try { final URI foundUrl = URIUtils.newURI(arg); if (foundUrl != null && PROTOCOL_HANDLER_SCHEME.equalsIgnoreCase(foundUrl.getScheme())) { return foundUrl; } } catch (final Exception e) { log.error(" Incorrect URL in the protocol handler argument", e); //$NON-NLS-1$ } break; } else if (arg.equalsIgnoreCase(PROTOCOL_HANDLER_ARG)) { found = true; } else { found = false; } } return null; }
From source file:org.eclipse.virgo.ide.manifest.core.BundleManifestUtils.java
/** * Converts a given {@link IResource} into a full qualified {@link URI} honoring eventual used Eclipse variables in * the path expression./* w w w .ja v a2 s.c o m*/ */ private static URI convertResourceToUrl(IResource resource) { if (resource != null) { URI uri = resource.getRawLocationURI(); if (uri != null) { String scheme = uri.getScheme(); if (FILE_SCHEME.equalsIgnoreCase(scheme)) { return uri; } else if ("sourcecontrol".equals(scheme)) { // special case of Rational Team Concert IPath path = resource.getLocation(); File file = path.toFile(); if (file.exists()) { return file.toURI(); } } else { IPathVariableManager variableManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); return variableManager.resolveURI(uri); } } } return null; }