List of usage examples for java.io File toURI
public URI toURI()
From source file:de.cosmocode.palava.core.Palava.java
/** * Creates a new {@link Framework} using the specified module and * a properties file.// w w w . j a v a 2 s . c om * <p> * The loaded properties will be bound using the {@link Settings} annotation. * </p> * * @since 2.4 * @param module the application main module * @param file the file pointing to the properties file * @return a new configured {@link Framework} instance * @throws NullPointerException if module or file is null * @throws IllegalArgumentException if the file does not exist * @throws ConfigurationException if guice configuration failed * @throws ProvisionException if providing an instance during creation failed */ public static Framework newFramework(Module module, File file) { Preconditions.checkNotNull(module, "Module"); Preconditions.checkNotNull(file, "File"); Preconditions.checkArgument(file.exists(), "%s does not exist", file); try { return newFramework(module, file.toURI().toURL()); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } }
From source file:com.datatorrent.contrib.parquet.ParquetFilePOJOReaderTest.java
private static void writeParquetFile(String rawSchema, File outputParquetFile, List<EventRecord> data) throws IOException { Path path = new Path(outputParquetFile.toURI()); MessageType schema = MessageTypeParser.parseMessageType(rawSchema); ParquetPOJOWriter writer = new ParquetPOJOWriter(path, schema, EventRecord.class, true); for (EventRecord eventRecord : data) { writer.write(eventRecord);//ww w . j av a 2 s . c o m } writer.close(); }
From source file:org.wso2.carbon.identity.jwt.client.extension.util.JWTClientUtil.java
private static KeyStore loadKeyStore(final File keystoreFile, final String password, final String keyStoreType) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException { if (null == keystoreFile) { throw new IllegalArgumentException("Keystore url may not be null"); }// w w w. j av a 2 s .com URI keystoreUri = keystoreFile.toURI(); URL keystoreUrl = keystoreUri.toURL(); KeyStore keystore = KeyStore.getInstance(keyStoreType); InputStream is = null; try { is = keystoreUrl.openStream(); keystore.load(is, null == password ? null : password.toCharArray()); } finally { if (null != is) { is.close(); } } return keystore; }
From source file:io.dstream.tez.utils.ClassPathUtils.java
/** * * @param resource/*from ww w .j a v a 2 s .co m*/ */ public static void addResourceToClassPath(File resource) { try { Preconditions.checkState(resource != null && resource.exists(), "'resource' must not be null and it must exist: " + resource); URLClassLoader cl = (URLClassLoader) Thread.currentThread().getContextClassLoader(); Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); addUrlMethod.setAccessible(true); addUrlMethod.invoke(cl, resource.toURI().toURL()); } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:com.datatorrent.stram.client.StramAppLauncher.java
public static Configuration getOverriddenConfig(Configuration conf, String overrideConfFileName, Map<String, String> overrideProperties) throws IOException { if (overrideConfFileName != null) { File overrideConfFile = new File(overrideConfFileName); if (overrideConfFile.exists()) { LOG.info("Loading settings: " + overrideConfFile.toURI()); conf.addResource(new Path(overrideConfFile.toURI())); } else {/* w ww . ja va 2 s .c om*/ throw new IOException("Problem opening file " + overrideConfFile); } } if (overrideProperties != null) { for (Map.Entry<String, String> entry : overrideProperties.entrySet()) { conf.set(entry.getKey(), entry.getValue()); } } StramClientUtils.evalConfiguration(conf); return conf; }
From source file:com.xse.optstack.persconftool.base.persistence.PersConfExport.java
private static void copyDefaultDataFiles(final File targetBaseFolder, final EApplication application, final Function<EConfiguration, EDefaultData> defaultDataProvider) { for (final EResource eResource : application.getResources()) { // copy default data files in case we have a file-based default data configuration with new file refs if (eResource.getConfiguration().getType() == EDefaultDataType.FILE) { final EDefaultData factoryDefaultData = defaultDataProvider.apply(eResource.getConfiguration()); if (!StringUtils.isEmpty(factoryDefaultData.getLocalResourcePath())) { final File dataFile = new File(factoryDefaultData.getLocalResourcePath()); if (dataFile.exists() && dataFile.canRead()) { try { final Path source = Paths.get(dataFile.toURI()); final Path target = Paths.get(new File( targetBaseFolder.getAbsolutePath() + File.separator + eResource.getName()) .toURI()); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); } catch (final IOException | IllegalArgumentException | SecurityException e) { Logger.error(Activator.PLUGIN_ID, "Error copying factory default file to target location: " + eResource.getName(), e);//w w w . ja v a 2 s . co m } } else { Logger.warn(Activator.PLUGIN_ID, "Invalid factory default data path!"); } } } } }
From source file:com.googlecode.loosejar.ClassLoaderAnalyzer.java
private static URL javaHome() { //return normalized URL File jHome = new File(System.getProperty("java.home")); String name = jHome.getName(); // we're trying to get at the root of JDK or JRE here. // java.home system property whould typically be '$JAVA_HOME/jre', // but we want only $JAVA_HOME directory. if (name.equalsIgnoreCase("jre") || name.equalsIgnoreCase("lib")) { jHome = jHome.getParentFile();// w w w . j a va2s.c om } try { return jHome.toURI().toURL(); } catch (MalformedURLException e) { //this shouldn't happen; the value of java.home system property should be always parseable. throw new RuntimeException(e); } }
From source file:Main.java
public static void saveXml(Document dom, File file, boolean omitXmlDeclaration) throws IOException { try {/*from w w w.j a v a2 s. c o m*/ Transformer transformer = getNewTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclaration ? "yes" : "no"); transformer.transform(new DOMSource(dom.getDocumentElement()), new StreamResult(file.toURI().getPath())); } catch (Exception e) { throw new IOException("saveXml failed because : " + e.getMessage()); } }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtils.java
/** * Resolve a location (which can be many things) to an URL. If the location starts with * {@code classpath:} the location is interpreted as a classpath location. Otherwise it is tried * as a URL, file and at last UIMA resource. If the location is treated as a classpath or file * location, an URL is only returned if the target exists. If it is an URL, it is possible that * the target may not actually exist./* w ww . j av a2 s.c o m*/ * * @param aLocation * a location (classpath, URL, file or UIMA resource location). * @param aClassLoader * the class loader to be used for classpath URLs. * @param aContext * a UIMA context. * @return the resolved URL. * @throws IOException * if the target could not be found. */ public static URL resolveLocation(String aLocation, ClassLoader aClassLoader, UimaContext aContext) throws IOException { // if we have a caller, we use it's classloader ClassLoader classLoader = aClassLoader; if (classLoader == null) { classLoader = ResourceUtils.class.getClassLoader(); } // If a location starts with "classpath:" String prefixClasspath = "classpath:"; if (aLocation.startsWith(prefixClasspath)) { String cpLocation = aLocation.substring(prefixClasspath.length()); if (cpLocation.startsWith("/")) { cpLocation = cpLocation.substring(1); } URL url = classLoader.getResource(cpLocation); if (url == null) { throw new FileNotFoundException("No file found at [" + aLocation + "]"); } return url; } // If it is a true well-formed URL, we assume that it is just that. try { return new URL(aLocation); } catch (MalformedURLException e) { // Ok - was not an URL. } // Otherwise we try if it is a file. File file = new File(aLocation); if (file.exists()) { return file.toURI().toURL(); } // Otherwise we look into the context (if there was one) if (aContext != null) { Exception ex = null; URL url = null; try { url = aContext.getResourceURL(aLocation); } catch (ResourceAccessException e) { ex = e; } if (url == null) { FileNotFoundException e = new FileNotFoundException("No file found at [" + aLocation + "]"); if (ex != null) { e.initCause(ex); } throw e; } return url; } // Otherwise bail out throw new FileNotFoundException("No file found at [" + aLocation + "]"); }
From source file:com.google.dart.tools.update.core.internal.UpdateUtils.java
private static boolean isLinkedFile(File file) { try {/* www . j av a 2 s . c o m*/ IFileStore fileStore = EFS.getStore(file.toURI()); IFileInfo info = fileStore.fetchInfo(); return info.getAttribute(EFS.ATTRIBUTE_SYMLINK); } catch (CoreException ce) { return false; } }