Example usage for com.google.common.io CharStreams readLines

List of usage examples for com.google.common.io CharStreams readLines

Introduction

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

Prototype

public static <T> T readLines(Readable readable, LineProcessor<T> processor) throws IOException 

Source Link

Document

Streams lines from a Readable object, stopping when the processor returns false or all lines have been read and returning the result produced by the processor.

Usage

From source file:org.excalibur.core.io.utils.IOUtils2.java

/**
 * Reads all of the lines from an {@link InputStream} object. The lines include the line-termination characters, and also include other leading
 * and trailing whitespace./*w  ww  .j  a va2s.c om*/
 * 
 * <p>
 * Does not close the {@code InputStream}.
 * 
 * @param is
 *            The stream to read from.
 * 
 * @throws IOException
 *             if an I/O error occurs.
 */
public static String readLines(InputStream is) throws IOException {
    InputStreamReader isr = new InputStreamReader(is);
    try {
        return CharStreams.readLines(isr, new LineProcessor<String>() {
            final StringBuilder lines = new StringBuilder();

            @Override
            public boolean processLine(String line) throws IOException {
                lines.append(line).append(Strings2.NEW_LINE);
                return true;
            }

            @Override
            public String getResult() {
                return lines.toString();
            }
        });
    } finally {
        closeQuietly(isr);
    }
}

From source file:org.dishevelled.bio.variant.vcf.VcfParser.java

/**
 * Parse the specified readable.//  w w  w. ja  va 2s. co m
 *
 * @param readable readable, must not be null
 * @param listener low-level event based parser callback, must not be null
 * @throws IOException if an I/O error occurs
 */
public static void parse(final Readable readable, final VcfParseListener listener) throws IOException {
    checkNotNull(readable);
    VcfLineProcessor lineProcessor = new VcfLineProcessor(listener);
    CharStreams.readLines(readable, lineProcessor);
}

From source file:org.dishevelled.bio.alignment.sam.SamParser.java

/**
 * Parse the specified readable.// w ww.j  ava2 s .co  m
 *
 * @param readable readable, must not be null
 * @param listener low-level event based parser callback, must not be null
 * @throws IOException if an I/O error occurs
 */
public static void parse(final Readable readable, final SamParseListener listener) throws IOException {
    checkNotNull(readable);
    SamLineProcessor lineProcessor = new SamLineProcessor(listener);
    CharStreams.readLines(readable, lineProcessor);
}

From source file:org.dishevelled.variation.vcf.VcfParser.java

/**
 * Parse the specified input supplier./*from w w w .ja v a2 s.co m*/
 *
 * @param supplier input supplier, must not be null
 * @param listener low-level event based parser callback, must not be null
 * @throws IOException if an I/O error occurs
 */
static <R extends Readable & Closeable> void parse(final InputSupplier<R> supplier,
        final VcfParseListener listener) throws IOException {
    checkNotNull(supplier);
    VcfLineProcessor lineProcessor = new VcfLineProcessor(listener);
    CharStreams.readLines(supplier, lineProcessor);
}

From source file:com.axelor.web.tags.ScriptTag.java

private List<String> files(final String manifest) throws IOException {

    final List<String> files = new ArrayList<>();
    final URL resource = this.getResource(manifest);
    if (resource == null) {
        return files;
    }// ww  w  . j  a v  a 2 s .  c om

    try (final InputStream is = resource.openStream()) {
        return CharStreams.readLines(new InputStreamReader(is), new LineProcessor<List<String>>() {
            @Override
            public boolean processLine(String line) throws IOException {
                if (line.startsWith("//= ")) {
                    line = line.substring(3).trim();
                    files.add(line);
                }
                return true;
            }

            @Override
            public List<String> getResult() {
                return files;
            }
        });
    }
}

From source file:org.nmdp.ngs.align.HspReader.java

/**
 * Stream zero or more high-scoring segment pairs from the specified readable.
 *
 * @param readable readable to stream from, must not be null
 * @param listener event based listener callback, must not be null
 * @throws IOException if an I/O error occurs
 *///from  w w w  .j av  a  2s .c  o  m
public static void stream(final Readable readable, final HspListener listener) throws IOException {
    checkNotNull(readable);
    checkNotNull(listener);

    HspLineProcessor lineProcessor = new HspLineProcessor(listener);
    CharStreams.readLines(readable, lineProcessor);
}

From source file:org.dishevelled.bio.feature.BedReader.java

/**
 * Stream zero or more BED records from the specified readable.
 *
 * @param readable readable to stream from, must not be null
 * @param listener event based listener callback, must not be null
 * @throws IOException if an I/O error occurs
 *//*from  w w w .  ja  v a  2s .  c  o m*/
public static void stream(final Readable readable, final BedListener listener) throws IOException {
    checkNotNull(readable);
    checkNotNull(listener);

    BedLineProcessor lineProcessor = new BedLineProcessor(listener);
    CharStreams.readLines(readable, lineProcessor);
}

From source file:org.dishevelled.bio.feature.Gff3Reader.java

/**
 * Stream zero or more GFF3 records from the specified readable.
 *
 * @param readable readable to stream from, must not be null
 * @param listener event based listener callback, must not be null
 * @throws IOException if an I/O error occurs
 *//*w  ww. j  a  v  a2s. c o m*/
public static void stream(final Readable readable, final Gff3Listener listener) throws IOException {
    checkNotNull(readable);
    checkNotNull(listener);

    Gff3LineProcessor lineProcessor = new Gff3LineProcessor(listener);
    CharStreams.readLines(readable, lineProcessor);
}

From source file:org.dishevelled.bio.assembly.gfa1.Gfa1Reader.java

/**
 * Stream zero or more GFA 1.0 records from the specified readable.
 *
 * @param readable readable to stream from, must not be null
 * @param listener event based listener callback, must not be null
 * @throws IOException if an I/O error occurs
 *///from  w ww. j a  v  a 2  s  . c  o  m
public static void stream(final Readable readable, final Gfa1Listener listener) throws IOException {
    checkNotNull(readable);
    checkNotNull(listener);

    Gfa1LineProcessor lineProcessor = new Gfa1LineProcessor(listener);
    CharStreams.readLines(readable, lineProcessor);
}

From source file:org.dishevelled.bio.assembly.gfa2.Gfa2Reader.java

/**
 * Stream zero or more GFA 2.0 records from the specified readable.
 *
 * @param readable readable to stream from, must not be null
 * @param listener event based listener callback, must not be null
 * @throws IOException if an I/O error occurs
 *//* ww w . j  a  va 2  s.c o m*/
public static void stream(final Readable readable, final Gfa2Listener listener) throws IOException {
    checkNotNull(readable);
    checkNotNull(listener);

    Gfa2LineProcessor lineProcessor = new Gfa2LineProcessor(listener);
    CharStreams.readLines(readable, lineProcessor);
}