List of usage examples for java.net URL getFile
public String getFile()
From source file:net.rim.ejde.internal.model.BlackBerryVMInstallType.java
/** * Returns the default javadoc location specified in the properties or <code>null</code> if none. * * @param properties//from w w w . j av a 2 s . co m * properties map * * @return javadoc location specified in the properties or <code>null</code> if none */ public static URL getJavadocLocation(final Map properties) { final String javadoc = BlackBerryVMInstallType.getProperty(ExecutionEnvironmentDescription.JAVADOC_LOC, properties); if ((javadoc != null) && (javadoc.length() > 0)) { try { URL url = new URL(javadoc); if ("file".equalsIgnoreCase(url.getProtocol())) { //$NON-NLS-1$ final File file = new File(url.getFile()); url = file.getCanonicalFile().toURL(); } return url; } catch (final MalformedURLException e) { BlackBerryVMInstallType.log.error("", e); //$NON-NLS-1$ return null; } catch (final IOException e) { BlackBerryVMInstallType.log.error("", e); //$NON-NLS-1$ return null; } } final String version = BlackBerryVMInstallType.getProperty(ExecutionEnvironmentDescription.LANGUAGE_LEVEL, properties); if (version != null) return StandardVMType.getDefaultJavadocLocation(version); return null; }
From source file:io.github.bonigarcia.wdm.Downloader.java
public static final String getTarget(String version, URL url) throws IOException { log.trace("getTarget {} {}", version, url); String zip = url.getFile().substring(url.getFile().lastIndexOf("/")); int iFirst = zip.indexOf("_"); int iSecond = zip.indexOf("-"); int iLast = iFirst != zip.lastIndexOf("_") ? zip.lastIndexOf("_") : iSecond != -1 ? iSecond : zip.length(); String folder = zip.substring(0, iLast).replace(".zip", "").replace(".tar.bz2", "").replace(".tar.gz", "") .replace(".msi", "").replace(".exe", "").replace("_", File.separator); String target = getTargetPath() + folder + File.separator + version + zip; // Exception for PhantomJS if (target.contains("phantomjs")) { int iSeparator = target.indexOf(version) - 1; int iDash = target.lastIndexOf(version) + version.length(); int iPoint = target.lastIndexOf(".tar") != -1 ? target.lastIndexOf(".tar") : target.lastIndexOf(".zip"); target = target.substring(0, iSeparator + 1) + target.substring(iDash + 1, iPoint) + target.substring(iSeparator); }// ww w. j av a2 s . c o m // Exception for Marionette else if (target.contains("wires") || target.contains("geckodriver")) { int iSeparator = target.indexOf(version) - 1; int iDash = target.lastIndexOf(version) + version.length(); int iPoint = target.lastIndexOf("tar.gz") != -1 ? target.lastIndexOf(".tar.gz") : target.lastIndexOf(".gz") != -1 ? target.lastIndexOf(".gz") : target.lastIndexOf(".zip"); target = target.substring(0, iSeparator + 1) + target.substring(iDash + 1, iPoint).toLowerCase() + target.substring(iSeparator); } log.trace("Target file for URL {} version {} = {}", url, version, target); return target; }
From source file:jp.go.nict.langrid.management.logic.service.ProcessDeployer.java
static InputStream openStream(URL url, String userName, String password) throws IOException { HttpClient client = HttpClientUtil.createHttpClientWithHostConfig(url); SimpleHttpConnectionManager manager = new SimpleHttpConnectionManager(true); client.setHttpConnectionManager(manager); GetMethod m = new GetMethod(url.getFile()); if ((userName != null) && (userName.length() > 0)) { client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password)); client.getParams().setAuthenticationPreemptive(true); m.setDoAuthentication(true);/*w ww. j av a2s. c o m*/ } try { client.executeMethod(m); if (m.getStatusCode() != 200) { throw new IOException("failed to get vaild http response: " + m.getStatusCode()); } return new ByteArrayInputStream(StreamUtil.readAsBytes(m.getResponseBodyAsStream())); } finally { manager.shutdown(); } }
From source file:com.zotoh.maedr.device.HttpIOTrait.java
/** * @param createContext/*from w ww . java 2 s. c o m*/ * @param sslType * @param key * @param pwd * @return * @throws NoSuchAlgorithmException * @throws UnrecoverableEntryException * @throws KeyStoreException * @throws CertificateException * @throws IOException * @throws KeyManagementException */ protected static Tuple cfgSSL(boolean createContext, String sslType, URL key, String pwd) throws NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException, CertificateException, IOException, KeyManagementException { boolean jks = key.getFile().endsWith(".jks"); InputStream inp = key.openStream(); CryptoStore s; try { s = jks ? new JKSStore() : new PKCSStore(); s.init(pwd); s.addKeyEntity(inp, pwd); } finally { StreamUte.close(inp); } SSLContext c = null; if (createContext) { c = SSLContext.getInstance(sslType); c.init(s.getKeyManagerFactory().getKeyManagers(), s.getTrustManagerFactory().getTrustManagers(), Crypto.getInstance().getSecureRandom()); } return new Tuple(s, c); }
From source file:org.jboss.as.test.integration.security.loginmodules.usersroles.UsersRolesLoginModuleTestCase1.java
protected static void createSecurityDomains(final ModelControllerClient client) throws Exception { List<ModelNode> updates = new ArrayList<ModelNode>(); ModelNode op = new ModelNode(); String securityDomain = "users-roles-login-module"; op.get(OP).set(ADD);//from www. ja va2s.c o m op.get(OP_ADDR).add(SUBSYSTEM, "security"); op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain); updates.add(op); op = new ModelNode(); op.get(OP).set(ADD); op.get(OP_ADDR).add(SUBSYSTEM, "security"); op.get(OP_ADDR).add(SECURITY_DOMAIN, securityDomain); op.get(OP_ADDR).add(Constants.AUTHENTICATION, Constants.CLASSIC); ModelNode loginModule = op.get(Constants.LOGIN_MODULES).add(); loginModule.get(ModelDescriptionConstants.CODE).set(UsersRolesLoginModule.class.getName()); loginModule.get(FLAG).set("required"); op.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); URL usersProp = tccl.getResource("users-roles-login-module.war/users.properties"); URL rolesProp = tccl.getResource("users-roles-login-module.war/roles.properties"); ModelNode moduleOptions = loginModule.get("module-options"); moduleOptions.get("usersProperties").set(usersProp.getFile()); moduleOptions.get("rolesProperties").set(rolesProp.getFile()); moduleOptions.get("unauthenticatedIdentity").set(ANNONYMOUS_USER_NAME); updates.add(op); applyUpdates(updates, client); }
From source file:com.hypersocket.client.hosts.HostsFileManager.java
public static URL sanitizeURL(String url) throws MalformedURLException { URL u = new URL(url); String hostname = IPAddressValidator.getInstance().getGuaranteedHostname(u.getHost()); return new URL(u.getProtocol(), hostname, u.getPort(), u.getFile()); }
From source file:org.apache.hadoop.gateway.GatewayMultiFuncTest.java
public static void setupGateway() throws Exception { File targetDir = new File(System.getProperty("user.dir"), "target"); File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID()); gatewayDir.mkdirs();/*from w w w . j av a 2s .co m*/ config = new GatewayTestConfig(); config.setGatewayHomeDir(gatewayDir.getAbsolutePath()); URL svcsFileUrl = TestUtils.getResourceUrl(DAT, "services/readme.txt"); File svcsFile = new File(svcsFileUrl.getFile()); File svcsDir = svcsFile.getParentFile(); config.setGatewayServicesDir(svcsDir.getAbsolutePath()); URL appsFileUrl = TestUtils.getResourceUrl(DAT, "applications/readme.txt"); File appsFile = new File(appsFileUrl.getFile()); File appsDir = appsFile.getParentFile(); config.setGatewayApplicationsDir(appsDir.getAbsolutePath()); File topoDir = new File(config.getGatewayTopologyDir()); topoDir.mkdirs(); File deployDir = new File(config.getGatewayDeploymentDir()); deployDir.mkdirs(); startGatewayServer(); }
From source file:com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfigurationTest.java
/** * Return the classes inside the specified package and its sub-packages. * @param klass a class inside that package * @return a list of class names//from www .j a v a 2s . co m */ public static List<String> getClassesForPackage(final Class<?> klass) { final List<String> list = new ArrayList<>(); File directory = null; final String relPath = klass.getName().replace('.', '/') + ".class"; final URL resource = JavaScriptConfiguration.class.getClassLoader().getResource(relPath); if (resource == null) { throw new RuntimeException("No resource for " + relPath); } final String fullPath = resource.getFile(); try { directory = new File(resource.toURI()).getParentFile(); } catch (final URISyntaxException e) { throw new RuntimeException(klass.getName() + " (" + resource + ") does not appear to be a valid URL", e); } catch (final IllegalArgumentException e) { directory = null; } if (directory != null && directory.exists()) { addClasses(directory, klass.getPackage().getName(), list); } else { try { String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", ""); if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win")) { jarPath = jarPath.replace("%20", " "); } final JarFile jarFile = new JarFile(jarPath); for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { final String entryName = entries.nextElement().getName(); if (entryName.endsWith(".class")) { list.add(entryName.replace('/', '.').replace('\\', '.').replace(".class", "")); } } jarFile.close(); } catch (final IOException e) { throw new RuntimeException(klass.getPackage().getName() + " does not appear to be a valid package", e); } } return list; }
From source file:dynamicrefactoring.util.io.FileManager.java
/** * Copia un directorio empaquetado en el plugin en un directorio del sistema * de ficheros./* w w w .ja v a2 s.c om*/ * * @param bundleDir ruta del directorio en el bundle * @param fileSystemDir ruta del directorio del sistema * @throws IOException si ocurre algun problema al acceder a las rutas */ public static void copyBundleDirToFileSystem(String bundleDir, String fileSystemDir) throws IOException { final Bundle bundle = Platform.getBundle(RefactoringPlugin.BUNDLE_NAME); final Enumeration<?> entries = bundle.findEntries(FilenameUtils.separatorsToUnix(bundleDir), "*", true); final List<?> lista = Collections.list(entries); for (Object entrada : lista) { URL entry = (URL) entrada; File fichero = new File(entry.getFile()); if (!entry.toString().endsWith("/")) { FileUtils.copyURLToFile(entry, new File(fileSystemDir + entry.getFile())); } } }
From source file:net.sf.joost.trax.TrAXHelper.java
/** * HelperMethod for initiating StxEmitter. * @param result A <code>Result</code> object. * @return An <code>StxEmitter</code>. * @throws javax.xml.transform.TransformerException *///from w w w .j av a 2 s .c om public static StxEmitter initStxEmitter(Result result, Processor processor, Properties outputProperties) throws TransformerException { if (outputProperties == null) outputProperties = processor.outputProperties; if (DEBUG) log.debug("init StxEmitter"); // Return the content handler for this Result object try { // Result object could be SAXResult, DOMResult, or StreamResult if (result instanceof SAXResult) { final SAXResult target = (SAXResult) result; final ContentHandler handler = target.getHandler(); if (handler != null) { if (DEBUG) log.debug("return SAX specific Implementation for " + "StxEmitter"); //SAX specific Implementation return new SAXEmitter(handler); } } else if (result instanceof DOMResult) { if (DEBUG) log.debug("return DOM specific Implementation for " + "StxEmitter"); //DOM specific Implementation return new DOMEmitter((DOMResult) result); } else if (result instanceof StreamResult) { if (DEBUG) log.debug("return StreamResult specific Implementation " + "for StxEmitter"); // Get StreamResult final StreamResult target = (StreamResult) result; // StreamResult may have been created with a java.io.File, // java.io.Writer, java.io.OutputStream or just a String // systemId. // try to get a Writer from Result object final Writer writer = target.getWriter(); if (writer != null) { if (DEBUG) log.debug("get a Writer object from Result object"); return StreamEmitter.newEmitter(writer, DEFAULT_ENCODING, outputProperties); } // or try to get an OutputStream from Result object final OutputStream ostream = target.getOutputStream(); if (ostream != null) { if (DEBUG) log.debug("get an OutputStream from Result object"); return StreamEmitter.newEmitter(ostream, outputProperties); } // or try to get just a systemId string from Result object String systemId = result.getSystemId(); if (DEBUG) log.debug("get a systemId string from Result object"); if (systemId == null) { if (DEBUG) log.debug("JAXP_NO_RESULT_ERR"); throw new TransformerException("JAXP_NO_RESULT_ERR"); } // System Id may be in one of several forms, (1) a uri // that starts with 'file:', (2) uri that starts with 'http:' // or (3) just a filename on the local system. OutputStream os = null; URL url = null; if (systemId.startsWith("file:")) { url = new URL(systemId); os = new FileOutputStream(url.getFile()); return StreamEmitter.newEmitter(os, outputProperties); } else if (systemId.startsWith("http:")) { url = new URL(systemId); URLConnection connection = url.openConnection(); os = connection.getOutputStream(); return StreamEmitter.newEmitter(os, outputProperties); } else { // system id is just a filename File tmp = new File(systemId); url = tmp.toURL(); os = new FileOutputStream(url.getFile()); return StreamEmitter.newEmitter(os, outputProperties); } } // If we cannot create the file specified by the SystemId } catch (IOException iE) { if (DEBUG) log.debug(iE); throw new TransformerException(iE); } catch (ParserConfigurationException pE) { if (DEBUG) log.debug(pE); throw new TransformerException(pE); } return null; }