com.google.common.io.Resources.asByteSource()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中com.google.common.io.Resources.asByteSource方法的一些代码示例,展示了Resources.asByteSource的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.asByteSource方法的具体详情如下:
包路径:com.google.common.io.Resources
类名称:Resources
方法名:asByteSource

Resources.asByteSource介绍

[英]Returns a ByteSource that reads from the given URL.
[中]返回从给定URL读取的字节源。

代码示例

代码示例来源:origin: google/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 asByteSource(url).read();
}

代码示例来源:origin: google/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 {
 asByteSource(from).copyTo(to);
}

代码示例来源:origin: google/guava

/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final ByteSource asByteSource() {
 return Resources.asByteSource(url());
}

代码示例来源:origin: google/guava

/**
 * Returns a {@link CharSource} that reads from the given URL using the given character set.
 *
 * @since 14.0
 */
public static CharSource asCharSource(URL url, Charset charset) {
 return asByteSource(url).asCharSource(charset);
}

代码示例来源:origin: google/j2objc

/**
 * 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 asByteSource(url).read();
}

代码示例来源:origin: google/j2objc

/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final ByteSource asByteSource() {
 return Resources.asByteSource(url());
}

代码示例来源:origin: google/j2objc

/**
 * Returns a {@link CharSource} that reads from the given URL using the given character set.
 *
 * @since 14.0
 */
public static CharSource asCharSource(URL url, Charset charset) {
 return asByteSource(url).asCharSource(charset);
}

代码示例来源:origin: google/j2objc

/**
 * 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 {
 asByteSource(from).copyTo(to);
}

代码示例来源:origin: robolectric/robolectric

private ByteSource getLibraryByteSource() {
 return Resources.asByteSource(Resources.getResource(getLibClasspathResourceName()));
}

代码示例来源:origin: wildfly/wildfly

/**
 * 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 asByteSource(url).read();
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns a {@link CharSource} that reads from the given URL using the given character set.
 *
 * @since 14.0
 */
public static CharSource asCharSource(URL url, Charset charset) {
 return asByteSource(url).asCharSource(charset);
}

代码示例来源:origin: google/guava

private static boolean contentEquals(URL left, URL right) throws IOException {
 return Resources.asByteSource(left).contentEquals(Resources.asByteSource(right));
}

代码示例来源:origin: prestodb/presto

public ExampleRecordSet(ExampleSplit split, List<ExampleColumnHandle> columnHandles)
{
  requireNonNull(split, "split is null");
  this.columnHandles = requireNonNull(columnHandles, "column handles is null");
  ImmutableList.Builder<Type> types = ImmutableList.builder();
  for (ExampleColumnHandle column : columnHandles) {
    types.add(column.getColumnType());
  }
  this.columnTypes = types.build();
  try {
    byteSource = Resources.asByteSource(split.getUri().toURL());
  }
  catch (MalformedURLException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Returns a {@link ByteSource} view of the resource from which its bytes can be read.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final ByteSource asByteSource() {
 return Resources.asByteSource(url());
}

代码示例来源:origin: google/guava

@SuppressWarnings("CheckReturnValue") // only using super.createSource to create a file
 @Override
 public ByteSource createSource(byte[] bytes) throws IOException {
  super.createSource(bytes);
  return Resources.asByteSource(getFile().toURI().toURL());
 }
}

代码示例来源:origin: prestodb/presto

@BeforeTestWithContext
public void setup()
    throws Exception
{
  hdfsClient.createDirectory("/user/hive/warehouse/TestAvroSchemaUrl/schemas");
  try (InputStream inputStream = Resources.asByteSource(Resources.getResource("avro/original_schema.avsc")).openStream()) {
    hdfsClient.saveFile("/user/hive/warehouse/TestAvroSchemaUrl/schemas/original_schema.avsc", inputStream);
  }
}

代码示例来源:origin: prestodb/presto

@Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException
  {
    URL dataUrl = Resources.getResource(TestExampleClient.class, request.getPathInfo());
    Resources.asByteSource(dataUrl).copyTo(response.getOutputStream());
  }
}

代码示例来源:origin: SonarSource/sonarqube

private InputStream getTestResource(String name) throws IOException {
 return Resources.asByteSource(this.getClass().getResource(this.getClass().getSimpleName() + "/" + name))
  .openBufferedStream();
}

代码示例来源:origin: apache/incubator-druid

public static IncrementalIndex makeRealtimeIndex(final String resourceFilename, boolean rollup)
{
 final URL resource = TestIndex.class.getClassLoader().getResource(resourceFilename);
 if (resource == null) {
  throw new IllegalArgumentException("cannot find resource " + resourceFilename);
 }
 log.info("Realtime loading index file[%s]", resource);
 CharSource stream = Resources.asByteSource(resource).asCharSource(StandardCharsets.UTF_8);
 return makeRealtimeIndex(stream, rollup);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void testParseServerResponse() throws IOException {
 ScannerWsClient wsClient = mock(ScannerWsClient.class);
 InputStream is = Resources.asByteSource(this.getClass().getResource("DefaultRulesLoaderTest/response.protobuf")).openBufferedStream();
 WsTestUtil.mockStream(wsClient, is);
 DefaultRulesLoader loader = new DefaultRulesLoader(wsClient);
 List<Rule> ruleList = loader.load();
 assertThat(ruleList).hasSize(318);
}

相关文章