Example usage for com.google.common.io Resources asByteSource

List of usage examples for com.google.common.io Resources asByteSource

Introduction

In this page you can find the example usage for com.google.common.io Resources asByteSource.

Prototype

public static ByteSource asByteSource(URL url) 

Source Link

Document

Returns a ByteSource that reads from the given URL.

Usage

From source file:com.opengamma.collect.io.ResourceLocator.java

/**
 * Creates a resource from a {@code URL}.
 * //from w w w .java 2s. co  m
 * @param url  the URL to wrap
 * @return the resource
 */
public static ResourceLocator ofClasspathUrl(URL url) {
    ArgChecker.notNull(url, "url");
    String locator = CLASSPATH_URL_PREFIX + url.toString();
    return new ResourceLocator(locator, Resources.asByteSource(url));
}

From source file:org.n52.youngs.impl.SourceRecordHelper.java

public static SourceRecord getSourceRecordFromFile(String filename) throws Exception {
    try (InputStream is = Resources.asByteSource(Resources.getResource(filename)).openStream();) {
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = documentBuilder.parse(is);
        Element elem = doc.getDocumentElement();
        elem.normalize();//from   w  w w  . ja v  a2 s . c  o m
        NodeSourceRecord record = new NodeSourceRecord(elem);
        return record;
    }
}

From source file:com.arcbees.beestore.server.servlets.RootServlet.java

private Properties loadVelocityProperties() {
    Properties properties = new Properties();

    try {/*w  ww.j a v a 2  s.  c o  m*/
        URL url = Resources.getResource(VELOCITY_PROPERTIES);
        ByteSource byteSource = Resources.asByteSource(url);

        properties.load(byteSource.openStream());
    } catch (IOException e) {
        throw new RuntimeException("Unable to load velocity properties from '" + VELOCITY_PROPERTIES + "'.", e);
    }

    return properties;
}

From source file:de.ii.ldproxy.rest.filter.RestRootFilter.java

private void writeContent(ContainerResponse response, final String file, final String mimeType) {
    response.reset();/*  www  . j  a  v  a2s.c o  m*/

    StreamingOutput stream = new StreamingOutput() {
        @Override
        public void write(OutputStream output) throws IOException, WebApplicationException {
            Resources.asByteSource(Resources.getResource(DatasetView.class, file)).copyTo(output);
        }
    };

    Response r = Response.ok(stream, mimeType).build();

    response.setResponse(r);
}

From source file:com.zxy.commons.hystrix.web.HystrixInitializer.java

/**
 * webspringproperties??/*from   w w w  . jav a  2 s. c  o m*/
 * 
 * @return Properties
*/
private Properties load() {
    Properties properties = new Properties();
    InputStream inputStream = null;
    try {
        final URL url = Resources.getResource("hystrix.properties");
        final ByteSource byteSource = Resources.asByteSource(url);

        inputStream = byteSource.openBufferedStream();
        properties.load(inputStream);
        // properties.list(System.out);
    } catch (Exception e) {
        // do nothing
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException ioException) {
                // do nothing
            }
        }
    }
    return properties;
}

From source file:w3bigdata.downloader.DriveSample.java

/**
 * Authorizes the installed application to access user's protected data.
 *///  www  .  jav  a  2  s.  c o  m
private static Credential authorize() throws Exception {
    // load client secrets
    URL resource = Resources.getResource("client_secrets.json");
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(Resources.asByteSource(resource).getInput()));
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, Collections.singleton(DriveScopes.DRIVE)).setDataStoreFactory(dataStoreFactory)
                    .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:eu.esdihumboldt.hale.io.jdbc.msaccess.test.MsAccessDataReaderTestSuit.java

/**
 * Copies the source database to a temporary file.
 * /* w  w  w . ja  v  a 2  s . c om*/
 * @throws IOException if temp file can't be created
 */
public void createSourceTempFile() throws IOException {
    ByteSource source = Resources
            .asByteSource(MsAccessDataReaderTestSuit.class.getClassLoader().getResource(SOURCE_DB_PATH));
    ByteSink dest = Files.asByteSink(getSourceTempFilePath());
    source.copyTo(dest);
}

From source file:org.apache.drill.exec.store.ClassPathFileSystem.java

@Override
public FileStatus getFileStatus(Path arg0) throws IOException {
    String file = getFileName(arg0);
    URL url;/*from   ww  w . j a v a  2s .  c o m*/

    try {
        url = Resources.getResource(file);
    } catch (IllegalArgumentException e) {
        throw new FileNotFoundException(String.format("Unable to find path %s.", arg0.toString()));
    }

    return new FileStatus(Resources.asByteSource(url).size(), false, 1, 8096, System.currentTimeMillis(), arg0);
}

From source file:uk.ac.ebi.fg.annotare2.magetabcheck.efo.EfoLoader.java

public EfoDag load(final URL url) throws IOException, OWLOntologyCreationException {
    if (url == null) {
        log.error("Given EFO url is null; please use the config file to specify the proper one");
        return null;
    }//ww w .j  av  a 2 s  .  co  m

    File cacheFile = getCacheFile(url);
    if (!cacheFile.exists()) {
        log.debug("The cache file doesn't exist; creating one [file={}]", cacheFile);
        if (!cacheDir.exists() && !cacheDir.mkdirs()) {
            throw new IOException("Can't create EFO cache directory: " + cacheDir.getAbsolutePath());
        }

        log.debug("Downloading EFO file [url={}]", url);
        Resources.asByteSource(url).copyTo(Files.asByteSink(cacheFile));
        log.debug("EFO file download successfully completed.");
    } else {
        log.debug("Loading EFO graph from cache [file={}]", cacheFile);
    }
    return load(cacheFile);
}

From source file:com.gwtplatform.dispatch.rest.rebind.DispatchRestRebindModule.java

@Provides
@Singleton/*from w w w.jav a2  s. c  om*/
@VelocityProperties
Properties getVelocityProperties(Logger logger) throws UnableToCompleteException {
    Properties properties = new Properties();

    try {
        URL url = Resources.getResource(VELOCITY_PROPERTIES);
        ByteSource byteSource = Resources.asByteSource(url);

        properties.load(byteSource.openStream());
    } catch (Exception e) {
        logger.die("Unable to load velocity properties from '%s'.", e, VELOCITY_PROPERTIES);
    }

    return properties;
}