本文整理了Java中com.google.common.io.Resources.newInputStreamSupplier
方法的一些代码示例,展示了Resources.newInputStreamSupplier
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.newInputStreamSupplier
方法的具体详情如下:
包路径:com.google.common.io.Resources
类名称:Resources
方法名:newInputStreamSupplier
[英]Returns a factory that will supply instances of InputStream that read from the given URL.
[中]返回一个工厂,该工厂将提供从给定URL读取的InputStream实例。
代码示例来源:origin: com.atlassian.bundles/guava
/**
* Copies all bytes from a URL to an output stream.
*
* @param from the URL to read from
* @param to the output stream
* @throws IOException if an I/O error occurs
*/
public static void copy(URL from, OutputStream to) throws IOException {
ByteStreams.copy(newInputStreamSupplier(from), to);
}
代码示例来源:origin: org.sonatype.sisu/sisu-guava
/**
* Reads all bytes from a URL into a byte array.
*
* @param url the URL to read from
* @return a byte array containing all the bytes from the URL
* @throws IOException if an I/O error occurs
*/
public static byte[] toByteArray(URL url) throws IOException {
return ByteStreams.toByteArray(newInputStreamSupplier(url));
}
代码示例来源:origin: com.atlassian.bundles/guava
/**
* Reads all bytes from a URL into a byte array.
*
* @param url the URL to read from
* @return a byte array containing all the bytes from the URL
* @throws IOException if an I/O error occurs
*/
public static byte[] toByteArray(URL url) throws IOException {
return ByteStreams.toByteArray(newInputStreamSupplier(url));
}
代码示例来源:origin: org.sonatype.sisu/sisu-guava
/**
* Copies all bytes from a URL to an output stream.
*
* @param from the URL to read from
* @param to the output stream
* @throws IOException if an I/O error occurs
*/
public static void copy(URL from, OutputStream to) throws IOException {
ByteStreams.copy(newInputStreamSupplier(from), to);
}
代码示例来源:origin: com.google.guava/guava-io
/**
* Reads all bytes from a URL into a byte array.
*
* @param url the URL to read from
* @return a byte array containing all the bytes from the URL
* @throws IOException if an I/O error occurs
*/
public static byte[] toByteArray(URL url) throws IOException {
return ByteStreams.toByteArray(newInputStreamSupplier(url));
}
代码示例来源:origin: com.google.guava/guava-io
/**
* Copies all bytes from a URL to an output stream.
*
* @param from the URL to read from
* @param to the output stream
* @throws IOException if an I/O error occurs
*/
public static void copy(URL from, OutputStream to) throws IOException {
ByteStreams.copy(newInputStreamSupplier(from), to);
}
代码示例来源:origin: apache/attic-mrunit
private void copy(String resourceName, File dest) throws IOException {
Files.copy(Resources.newInputStreamSupplier(Resources.getResource(resourceName)), dest);
}
代码示例来源:origin: cloudera/crunch
public static String createTempCopyOf(String fileResource) throws IOException {
File tmpFile = File.createTempFile("tmp", "");
tmpFile.deleteOnExit();
Files.copy(newInputStreamSupplier(getResource(fileResource)), tmpFile);
return tmpFile.getAbsolutePath();
}
代码示例来源:origin: caskdata/cdap
private static void copyTempFile(String infileName, File outDir) throws IOException {
URL url = TestBase.class.getClassLoader().getResource(infileName);
if (url == null) {
throw new IOException("Failed to get resource for " + infileName);
}
File outFile = new File(outDir, infileName);
ByteStreams.copy(Resources.newInputStreamSupplier(url), Files.newOutputStreamSupplier(outFile));
}
代码示例来源:origin: org.sonatype.sisu/sisu-guava
/**
* Returns a factory that will supply instances of
* {@link InputStreamReader} that read a URL using the given character set.
*
* @param url the URL to read from
* @param charset the character set used when reading the URL contents
* @return the factory
*/
public static InputSupplier<InputStreamReader> newReaderSupplier(
URL url, Charset charset) {
return CharStreams.newReaderSupplier(newInputStreamSupplier(url), charset);
}
代码示例来源:origin: com.facebook.giraph.hive/hive-io-exp-core
private static void loadLibrary(String name)
throws IOException
{
URL url = Resources.getResource(HadoopNative.class, getLibraryPath(name));
File file = File.createTempFile(name, null);
file.deleteOnExit();
Files.copy(Resources.newInputStreamSupplier(url), file);
System.load(file.getAbsolutePath());
}
代码示例来源:origin: co.cask.cdap/cdap-unit-test
private static void copyTempFile(String infileName, File outDir) throws IOException {
URL url = TestBase.class.getClassLoader().getResource(infileName);
if (url == null) {
throw new IOException("Failed to get resource for " + infileName);
}
File outFile = new File(outDir, infileName);
ByteStreams.copy(Resources.newInputStreamSupplier(url), Files.newOutputStreamSupplier(outFile));
}
代码示例来源:origin: facebookarchive/hive-io-experimental
/**
* Load a library
*
* @param name String name of library
* @throws IOException
*/
protected static void loadLibrary(String name) throws IOException {
URL url = Resources.getResource(HadoopNative.class, getLibraryPath(name));
File file = File.createTempFile(name, null);
file.deleteOnExit();
Files.copy(Resources.newInputStreamSupplier(url), file);
System.load(file.getAbsolutePath());
}
代码示例来源:origin: com.google.guava/guava-io
/**
* Returns a factory that will supply instances of
* {@link InputStreamReader} that read a URL using the given character set.
*
* @param url the URL to read from
* @param charset the character set used when reading the URL contents
* @return the factory
*/
public static InputSupplier<InputStreamReader> newReaderSupplier(
URL url, Charset charset) {
return CharStreams.newReaderSupplier(newInputStreamSupplier(url), charset);
}
代码示例来源:origin: com.atlassian.bundles/guava
/**
* Returns a factory that will supply instances of
* {@link InputStreamReader} that read a URL using the given character set.
*
* @param url the URL to read from
* @param charset the character set used when reading the URL contents
* @return the factory
*/
public static InputSupplier<InputStreamReader> newReaderSupplier(
URL url, Charset charset) {
return CharStreams.newReaderSupplier(newInputStreamSupplier(url), charset);
}
代码示例来源:origin: com.atlassian.httpclient/atlassian-httpclient-apache-httpcomponents
private static InputSupplier<InputStream> getPomInputStreamSupplier(String groupId, String artifactId)
{
return newInputStreamSupplier(getResource(MavenUtils.class, getPomFilePath(groupId, artifactId)));
}
代码示例来源:origin: com.proofpoint.galaxy/galaxy-shared
public static InputSupplier<InputStream> newConfigEntrySupplier(Repository repository, String config, final String entryName)
{
URI uri = repository.configToHttpUri(config);
if (uri == null) {
return null;
}
URL configUrl;
try {
configUrl = uri.toURL();
}
catch (MalformedURLException e) {
throw new RuntimeException("Invalid config bundle location " + uri);
}
return ConfigUtils.newConfigEntrySupplier(Resources.newInputStreamSupplier(configUrl), entryName);
}
代码示例来源:origin: com.github.MoebiusSolutions.jacle/jacle-commons
public Properties fromResource(String resourceName) throws RuntimeIOException {
final URL url = Resources.getResource(resourceName);
InputStream stream = null;
try {
stream = Resources.newInputStreamSupplier(url).getInput();
return fromStream(stream);
} catch (Exception e) {
throw new RuntimeIOException(String.format("Failed to read properties from resource [%s]", resourceName), e);
} finally {
CloseablesExt.closeQuietly(stream);
}
}
}
代码示例来源:origin: io.airlift.airship/airship-agent
private Deployment createDeploymentDir(String name, Assignment assignment)
throws IOException
{
File deploymentDir = new File(slotDir, name);
File dataDir = new File(slotDir, "data");
dataDir.mkdirs();
File launcher = new File(deploymentDir, "bin/launcher");
// copy launcher script
launcher.getParentFile().mkdirs();
Files.copy(newInputStreamSupplier(getResource(ArchiveHelper.class, "launcher")), launcher);
launcher.setExecutable(true, true);
return new Deployment(UUID.randomUUID(), "location", deploymentDir, dataDir, assignment, ImmutableMap.<String, Integer>of("memory", 512));
}
代码示例来源:origin: com.twitter.common/application-http
/**
* Creates a new asset configuration.
*
* @param path HTTP path the asset should be accessible from.
* @param asset Asset resource URL.
* @param contentType HTTP content-type to report for the asset.
* @param silent Whether the asset should be visible on the default index page.
*/
public HttpAssetConfig(String path, URL asset, String contentType, boolean silent) {
this.path = checkNotBlank(path);
this.handler = new AssetHandler(
new StaticAsset(Resources.newInputStreamSupplier(asset), contentType, true));
this.silent = silent;
}
}
内容来源于网络,如有侵权,请联系作者删除!