Java Code Examples for com.google.common.io.Resources#asCharSource()
The following examples show how to use
com.google.common.io.Resources#asCharSource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Authorizer.java From mail-importer with Apache License 2.0 | 5 votes |
private GoogleClientSecrets loadGoogleClientSecrets(JsonFactory jsonFactory) throws IOException { URL url = Resources.getResource("client_secret.json"); CharSource inputSupplier = Resources.asCharSource(url, Charsets.UTF_8); return GoogleClientSecrets.load(jsonFactory, inputSupplier.openStream()); }
Example 2
Source File: IpmiCommandNameTest.java From ipmi4j with Apache License 2.0 | 5 votes |
private void process(Context context, String templateName, String targetPath) throws IOException { URL templateUrl = Resources.getResource(IpmiCommandNameTest.class, templateName); CharSource source = Resources.asCharSource(templateUrl, StandardCharsets.UTF_8); File file = new File(targetPath); CharSink sink = Files.asCharSink(file, StandardCharsets.UTF_8); try (Reader r = source.openBufferedStream()) { try (Writer w = sink.openBufferedStream()) { engine.evaluate(context, w, file.getName(), r); } } }
Example 3
Source File: ConfigurationBuilder.java From sputnik with Apache License 2.0 | 5 votes |
public static Configuration initFromResource(String configurationResource) { notBlank(configurationResource, "You need to provide url with configuration properties"); log.info("Initializing configuration properties from url {}", configurationResource); CharSource charSource = Resources.asCharSource(getResource(configurationResource), Charsets.UTF_8); try (Reader resourceStream = charSource.openStream()) { Properties properties = new Properties(); properties.load(resourceStream); return initFromProperties(properties); } catch (IOException e) { log.error("Configuration initialization failed", e); throw new RuntimeException(e); } }
Example 4
Source File: EREToKBPEventOntologyMapper.java From tac-kbp-eal with MIT License | 4 votes |
private static CharSource resourceAsCharsource(final String resource) throws IOException { return Resources .asCharSource(EREToKBPEventOntologyMapper.class.getResource(resource), Charsets.UTF_8); }
Example 5
Source File: TraceExportHttpService.java From glowroot with Apache License 2.0 | 4 votes |
private static CharSource asCharSource(String exportResourceName) { URL url = TraceExportHttpService.class .getResource("/org/glowroot/ui/export-dist/" + exportResourceName); return Resources.asCharSource(checkNotNull(url), UTF_8); }
Example 6
Source File: NumberParsingBenchmark.java From util with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException { final NumberParser numParser; if (args.length> 0 && "ind".equals(args[0]) ) { numParser = indeedNumberParser; } else { numParser = javaNumberParser; } final CharSource intData = Resources.asCharSource(Resources.getResource("text_with_ints.txt"), Charset.forName("UTF-8")); final CharSource floatData = Resources.asCharSource(Resources.getResource("text_with_floats.txt"), Charset.forName("UTF-8")); final Stopwatch stopwatchA = Stopwatch.createUnstarted(); final Stopwatch stopwatchB = Stopwatch.createUnstarted(); System.out.println("parsing utils results"); doNumberParsingBenchMark(intData, floatData, stopwatchA, stopwatchB, numParser); }
Example 7
Source File: ClassPath.java From codebuff with BSD 2-Clause "Simplified" License | 2 votes |
/** * 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); }
Example 8
Source File: CharSources.java From Strata with Apache License 2.0 | 2 votes |
/** * 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); }
Example 9
Source File: CharSources.java From Strata with Apache License 2.0 | 2 votes |
/** * 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); }
Example 10
Source File: ClassPath.java From codebuff with BSD 2-Clause "Simplified" License | votes |
/** * 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); }
Example 11
Source File: ClassPath.java From codebuff with BSD 2-Clause "Simplified" License | votes |
/** * 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); }
Example 12
Source File: ClassPath.java From codebuff with BSD 2-Clause "Simplified" License | votes |
/** * 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); }
Example 13
Source File: ClassPath.java From codebuff with BSD 2-Clause "Simplified" License | votes |
/** * 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); }