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

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

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

Resources.asCharSource介绍

[英]Returns a CharSource that reads from the given URL using the given character set.
[中]

代码示例

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

/**
 * Reads all characters from a URL into a {@link String}, using the given character set.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful
 *     predefined constants
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url, Charset charset) throws IOException {
 return asCharSource(url, charset).read();
}

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

/**
 * Returns a {@link CharSource} view of the resource from which its bytes can be read as
 * characters decoded with the given {@code charset}.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final CharSource asCharSource(Charset charset) {
 return Resources.asCharSource(url(), charset);
}

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

/**
 * Returns a {@link CharSource} view of the resource from which its bytes can be read as
 * characters decoded with the given {@code charset}.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final CharSource asCharSource(Charset charset) {
 return Resources.asCharSource(url(), charset);
}

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

/**
 * Reads all characters from a URL into a {@link String}, using the given character set.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful
 *     predefined constants
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url, Charset charset) throws IOException {
 return asCharSource(url, charset).read();
}

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

/**
 * Reads all characters from a URL into a {@link String}, using the given character set.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful
 *     predefined constants
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url, Charset charset) throws IOException {
 return asCharSource(url, charset).read();
}

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

/**
 * Returns a {@link CharSource} view of the resource from which its bytes can be read as
 * characters decoded with the given {@code charset}.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final CharSource asCharSource(Charset charset) {
 return Resources.asCharSource(url(), charset);
}

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

/**
 * Streams lines from a URL, stopping when our callback returns false, or we have read all of the
 * lines.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful
 *     predefined constants
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
@CanIgnoreReturnValue // some processors won't return a useful result
public static <T> T readLines(URL url, Charset charset, LineProcessor<T> callback)
  throws IOException {
 return asCharSource(url, charset).readLines(callback);
}

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

/**
 * Streams lines from a URL, stopping when our callback returns false, or we have read all of the
 * lines.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful
 *     predefined constants
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
@CanIgnoreReturnValue // some processors won't return a useful result
public static <T> T readLines(URL url, Charset charset, LineProcessor<T> callback)
  throws IOException {
 return asCharSource(url, charset).readLines(callback);
}

代码示例来源:origin: SpongePowered/SpongeAPI

/**
 * Reads all lines from the asset and returns the result.
 *
 * @param charset The charset to read the asset with
 * @return An immutable list of the lines read from the asset
 * @throws IOException If any file exception is thrown
 */
default List<String> readLines(Charset charset) throws IOException {
  checkNotNull(charset, "charset");
  return Resources.asCharSource(getUrl(), charset).readLines();
}

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

@SuppressWarnings("CheckReturnValue") // only using super.createSource to create a file
 @Override
 public CharSource createSource(String string) throws IOException {
  super.createSource(string); // just ignore returned CharSource
  return Resources.asCharSource(getFile().toURI().toURL(), Charsets.UTF_8);
 }
}

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

/**
 * Streams lines from a URL, stopping when our callback returns false, or we have read all of the
 * lines.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful
 *     predefined constants
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
@CanIgnoreReturnValue // some processors won't return a useful result
public static <T> T readLines(URL url, Charset charset, LineProcessor<T> callback)
  throws IOException {
 return asCharSource(url, charset).readLines(callback);
}

代码示例来源:origin: OpenGamma/Strata

/**
 * Obtains an instance of {@link CharSource} from an URL, specified as a {@link URL} object.
 * This also takes in a specific character set, as a {@link Charset}.
 *
 * @param url  the url to create a {@link CharSource} from
 * @param charset  the charset to build the new CharSource based on
 * @return  a new instance of {@link CharSource}.
 */
public static CharSource ofUrl(URL url, Charset charset) {
 return Resources.asCharSource(url, charset);
}

代码示例来源:origin: OpenGamma/Strata

/**
 * Obtains an instance of {@link CharSource} from a URL, specified as a {@link URL} object.
 *
 * @param url  the url to create a {@link CharSource} from
 * @return  a new instance of {@link CharSource} with UTF-8 for charset.
 */
public static CharSource ofUrl(URL url) {
 return Resources.asCharSource(url, Charsets.UTF_8);
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * Reads all characters from a URL into a {@link String}, using the given character set.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link Charsets} for helpful
 *     predefined constants
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url, Charset charset) throws IOException {
 return asCharSource(url, charset).read();
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * Returns a {@link CharSource} view of the resource from which its bytes can be read as
 * characters decoded with the given {@code charset}.
 *
 * @throws NoSuchElementException if the resource cannot be loaded through the class loader,
 *     despite physically existing in the class path.
 * @since 20.0
 */
public final CharSource asCharSource(Charset charset) {
 return Resources.asCharSource(url(), charset);
}

代码示例来源:origin: org.apache.isis.core/isis-core-viewer-restfulobjects-server

private static String versionFromManifest() {
  try {
    URL resource = Resources.getResource(META_INF_POM_PROPERTIES);
    Properties p = new Properties();
    p.load(Resources.asCharSource(resource, Charset.defaultCharset()).openStream());
    return p.getProperty("version");
  } catch (final Exception ex) {
    return "UNKNOWN";
  }
}

代码示例来源:origin: com.facebook.swift/swift-idl-parser

private static CharSource resourceReader(String name)
  {
    return Resources.asCharSource(Resources.getResource(name), Charsets.UTF_8);
  }
}

代码示例来源:origin: org.spongepowered/spongeapi

/**
 * Reads all lines from the asset and returns the result.
 *
 * @param charset The charset to read the asset with
 * @return An immutable list of the lines read from the asset
 * @throws IOException
 */
default List<String> readLines(Charset charset) throws IOException {
  checkNotNull(charset, "charset");
  return Resources.asCharSource(getUrl(), charset).readLines();
}

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

public RestxSpec load(String resource) throws IOException {
  return load(resource, Resources.asCharSource(
      MoreResources.getResource(resource, true),
      Charsets.UTF_8));
}

代码示例来源:origin: com.enonic.xp/core-api

public final P source( final URL url )
{
  systemId( url.toString() );
  source( Resources.asCharSource( url, Charsets.UTF_8 ) );
  return typecastThis();
}

相关文章