List of usage examples for com.google.common.io Resources asByteSource
public static ByteSource asByteSource(URL url)
From source file:com.zenika.doclipser.api.ReadPropertiesWithGuava.java
public final static void main(final String[] args) { final URL url = Resources.getResource(Constants.PROPERTY_FILE_NAME); final ByteSource byteSource = Resources.asByteSource(url); final Properties properties = new Properties(); InputStream inputStream = null; try {//from w ww. j a va 2 s.c om inputStream = byteSource.openBufferedStream(); properties.load(inputStream); properties.list(System.out); } catch (final IOException ioException) { ioException.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (final IOException ioException) { ioException.printStackTrace(); } } } }
From source file:com.bouncestorage.chaoshttpproxy.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); CmdLineParser parser = new CmdLineParser(options); try {// w ww . j av a 2 s. com parser.parseArgument(args); } catch (CmdLineException cle) { usage(parser); } if (options.version) { System.err.println(Main.class.getPackage().getImplementationVersion()); System.exit(0); } ByteSource byteSource; if (options.propertiesFile == null) { byteSource = Resources.asByteSource(Resources.getResource("chaos-http-proxy.conf")); } else { byteSource = Files.asByteSource(options.propertiesFile); } ChaosConfig config; try (InputStream is = byteSource.openStream()) { config = ChaosConfig.loadFromPropertyStream(is); } catch (IOException ioe) { System.err.println(ioe.getMessage()); System.exit(1); return; } URI proxyEndpoint = new URI("http", null, options.address, options.port, null, null, null); ChaosHttpProxy proxy = new ChaosHttpProxy(proxyEndpoint, config); try { proxy.start(); } catch (Exception e) { System.err.println(e.getMessage()); System.exit(1); } }
From source file:io.github.mike10004.vhs.testsupport.MakeFileUploadHar.java
public static void main(String[] args) throws Exception { File binaryFile = File.createTempFile("image-file-for-upload", ".jpeg"); Resources.asByteSource(MakeFileUploadHar.class.getResource("/image-for-upload.jpg")) .copyTo(Files.asByteSink(binaryFile)); main(StandardCharsets.UTF_8, binaryFile); binaryFile.deleteOnExit();//from w w w . jav a 2s . c o m }
From source file:google.registry.rde.imports.RdeImportsTestData.java
/** Returns {@link ByteSource} for file in {@code rde/imports/testdata/} directory. */ public static ByteSource get(String filename) { return Resources.asByteSource(getUrl(filename)); }
From source file:com.epam.reportportal.utils.SslUtils.java
/** * Load keystore// w ww . j a v a2 s . c om * * @param keyStore keystore resource * @param password keystore password * @return JKD keystore representation */ public static KeyStore loadKeyStore(String keyStore, String password) { InputStream is = null; try { is = Resources.asByteSource(Resources.getResource(keyStore)).openStream(); KeyStore trustStore = KeyStore.getInstance("JKS"); trustStore.load(is, password.toCharArray()); return trustStore; } catch (Exception e) { throw new RuntimeException("Unable to load trust store", e); } finally { IOUtils.closeQuietly(is); } }
From source file:com.github.steveash.jg2p.util.ReadWrite.java
public static <T> T readFromClasspath(Class<T> clazz, String resourceName) throws IOException, ClassNotFoundException { ByteSource bs = Resources.asByteSource(Resources.getResource(resourceName)); return (T) readFromSource(bs); }
From source file:com.zenika.doclipser.api.DockerClientFactory.java
private static String getDockerClientClassName() { final URL url = Resources.getResource(Constants.PROPERTY_FILE_NAME); final ByteSource byteSource = Resources.asByteSource(url); final Properties properties = new Properties(); InputStream inputStream = null; try {//from w w w . j a v a2 s. c o m inputStream = byteSource.openBufferedStream(); properties.load(inputStream); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (final IOException ioException) { ioException.printStackTrace(); } } } return properties.getProperty(Constants.PROPERTY_DOCKER_CLIENT_LIB); }
From source file:org.gradle.tooling.internal.consumer.DefaultProviderClasspathUpdater.java
private static ByteSource createPatchSource() { URL resource = DistributionFactory.class.getResource("gradle-tooling-api-provider-patch.jar"); return Resources.asByteSource(resource); }
From source file:org.trnltk.tokenizer.data.TokenizerTrainingData.java
public static TokenizerTrainingData createDefaultTrainingData() throws IOException { URL resourceURL = Resources.getResource("tokenizer/training-data.yaml"); ByteSource byteSource = Resources.asByteSource(resourceURL); return createFromYamlByteSource(byteSource); }
From source file:br.com.objectos.way.io.WayIOFakes.java
public static File gunzip(Class<?> contextClass, String resourceName) { try {//from w w w . java 2 s. co m File file = File.createTempFile("way-io-", ".fak"); URL url = getUrl(contextClass, resourceName); InputStream input = Resources.asByteSource(url).openStream(); GZIPInputStream gzip = new GZIPInputStream(input); Files.copyFile(gzip, file); return file; } catch (IOException e) { throw Throwables.propagate(e); } }