Java Code Examples for com.google.common.io.ByteSource#asCharSource()

The following examples show how to use com.google.common.io.ByteSource#asCharSource() . These examples are extracted from open source projects. 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 Project: n4js   File: TestCodeProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/***/
public static String getContentsFromFileEntry(final ZipEntry entry, String rootName) throws IOException,
		URISyntaxException {
	URL rootURL = Thread.currentThread().getContextClassLoader().getResource(rootName);
	try (final ZipFile root = new ZipFile(new File(rootURL.toURI()));) {
		ByteSource byteSource = new ByteSource() {
			@Override
			public InputStream openStream() throws IOException {
				return root.getInputStream(entry);
			}
		};

		CharSource charSrc = byteSource.asCharSource(Charsets.UTF_8);
		return charSrc.read();
	}
}
 
Example 2
/**
 * @param resourceName
 *            the classpath-relative location of the to-be-read resource
 */
private static List<String> getFileLines(final String resourceName) throws IOException {
	ByteSource byteSource = new ByteSource() {
		@Override
		public InputStream openStream() throws IOException {
			return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
		}
	};

	CharSource charSrc = byteSource.asCharSource(Charsets.UTF_8);
	return charSrc.readLines();
}
 
Example 3
Source Project: purplejs   File: IOHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static CharSource toCharSource( final ByteSource source )
{
    return source.asCharSource( Charsets.UTF_8 );
}