Example usage for com.google.common.io CharSource CharSource

List of usage examples for com.google.common.io CharSource CharSource

Introduction

In this page you can find the example usage for com.google.common.io CharSource CharSource.

Prototype

protected CharSource() 

Source Link

Document

Constructor for use by subclasses.

Usage

From source file:com.eclipsesource.connect.test.util.FileHelper.java

public static String readFile(ReaderSupplier reader) {
    try {/*  www  . ja va  2 s. co m*/
        return new CharSource() {

            @Override
            public Reader openStream() throws IOException {
                return reader.getReader();
            }
        }.read();
    } catch (IOException e) {
        throw new IllegalStateException("Could not read file from reader lambda");
    }
}

From source file:com.eclipsesource.connect.test.util.FileHelper.java

public static String readFile(String name, Class<?> classPathProvider) {
    try {// ww  w  . jav  a  2  s.  c o m
        return new CharSource() {

            @Override
            public Reader openStream() throws IOException {
                return new InputStreamReader(classPathProvider.getResourceAsStream(name), UTF_8);
            }
        }.read();
    } catch (IOException e) {
        throw new IllegalStateException(
                "Could not read file " + name + " on classpath of " + classPathProvider.getName());
    }
}

From source file:org.dishevelled.compress.Sources.java

/**
 * Create and return a new char source for the specified input stream.
 *
 * @since 1.1//from   ww  w  .  j a  v a  2s  .  c o m
 * @param inputStream input stream, must not be null
 * @return a new char source for the specified input stream
 */
public static CharSource inputStreamCharSource(final InputStream inputStream) {
    checkNotNull(inputStream);
    return new CharSource() {
        @Override
        public Reader openStream() throws IOException {
            return Readers.inputStreamReader(inputStream);
        }
    };
}

From source file:com.eclipsesource.connect.mvc.internal.Compressors.java

private static String uncompressed(InputStream stream) {
    try {//from w w w  .j ava2  s .c o  m
        return new CharSource() {

            @Override
            public Reader openStream() throws IOException {
                return new InputStreamReader(stream, UTF_8);
            }
        }.read();
    } catch (IOException shouldNotHappen) {
        throw new IllegalStateException(shouldNotHappen);
    }
}

From source file:org.dishevelled.compress.Sources.java

/**
 * Create and return a new char source for the specified compressed input stream,
 * autodetecting the compression type from the first few bytes of the stream.
 *
 * @since 1.1/*  w w  w .j av  a  2 s . com*/
 * @param inputStream input stream, must not be null
 * @return a new char source for the specified input stream
 */
public static CharSource compressedInputStreamCharSource(final InputStream inputStream) {
    checkNotNull(inputStream);
    return new CharSource() {
        @Override
        public Reader openStream() throws IOException {
            return Readers.compressedInputStreamReader(inputStream);
        }
    };
}

From source file:com.opengamma.strata.collect.io.UnicodeBom.java

/**
 * Converts a {@code ByteSource} to a {@code CharSource}.
 * <p>//from w  w  w . j a  v  a  2 s  . c  o m
 * This ensures that any Unicode byte order marker is used correctly.
 * The default encoding is UTF-8 if no BOM is found.
 * 
 * @param byteSource  the byte source
 * @return the char source, that uses the BOM to determine the encoding
 */
public static CharSource toCharSource(ByteSource byteSource) {
    return new CharSource() {

        @Override
        public ByteSource asByteSource(Charset charset) {
            return byteSource;
        }

        @Override
        public Reader openStream() throws IOException {
            return toReader(byteSource.openStream());
        }

        @Override
        public String toString() {
            return "UnicodeBom.toCharSource(" + byteSource.toString() + ")";
        }
    };
}

From source file:de.monticore.parsing.Parser.java

/**
 * Parses the given {@link InputStream}.
 * // w w w. ja v a  2 s.c om
 * @return the ast of the resulting model.
 */
public final ASTNode parse(final InputStream model) {
    return parse(new CharSource() {
        @Override
        public Reader openStream() throws IOException {
            return new InputStreamReader(model);
        }
    });
}

From source file:com.eclipsesource.connect.markdown.MarkdownPostProcessor.java

private ImmutableList<String> readLines(String content) {
    try {//from www.  j a va 2 s.co  m
        return new CharSource() {

            @Override
            public Reader openStream() throws IOException {
                return new StringReader(content);
            }
        }.readLines();
    } catch (IOException shouldNotHappen) {
        throw new IllegalStateException(shouldNotHappen);
    }
}

From source file:org.gradle.api.internal.plugins.DefaultTemplateBasedStartScriptGenerator.java

protected static TextResource utf8ClassPathResource(final Class<?> clazz, final String filename) {
    return new CharSourceBackedTextResource(new CharSource() {
        @Override//  w  ww. ja v  a2s .  c  om
        public Reader openStream() throws IOException {
            InputStream stream = clazz.getResourceAsStream(filename);
            if (stream == null) {
                throw new IllegalStateException(
                        "Could not find class path resource " + filename + " relative to " + clazz.getName());
            }
            return new BufferedReader(new InputStreamReader(stream, CharsetUtil.UTF_8));
        }
    });
}

From source file:org.dishevelled.compress.Sources.java

/**
 * Create and return a new block compressed gzip (BGZF) char source for the specified input stream.
 *
 * @since 1.2//from  ww  w .j  av a  2  s  .c  om
 * @param inputStream input stream, must not be null
 * @return a new block compressed gzip (BGZF) char source for the specified input stream
 */
public static CharSource bgzfInputStreamCharSource(final InputStream inputStream) {
    checkNotNull(inputStream);
    return new CharSource() {
        @Override
        public Reader openStream() throws IOException {
            return Readers.bgzfInputStreamReader(inputStream);
        }
    };
}