Sha256: 53a3d2f4393a50763773bcb1ecebdf2d85547725bbdef45ba6a9536189b208a1

Contents?: true

Size: 1.12 KB

Versions: 12

Compression:

Stored size: 1.12 KB

Contents

package org.cx4a.rsense.util;

import java.io.Reader;
import java.io.IOException;

public class HereDocReader extends Reader {
    private Reader reader;
    private char[] end;
    private int checked = 0;

    public HereDocReader(Reader reader, String end) {
        this.reader = reader;
        this.end = end.toCharArray();
    }

    public void close() throws IOException {
        reader.close();
    }

    public boolean markSupported() {
        return false;
    }

    public int read(char[] cbuf, int off, int len) throws IOException {
        if (checked == end.length) {
            return -1;
        }
        
        int read = 0;
        int c;
        while ((c = reader.read()) != -1) {
            if (end[checked] == c) {
                if (++checked == end.length) {
                    // here doc end detected
                    return read - checked;
                }
            } else {
                checked = 0;
            }
            read++;
            cbuf[off++] = (char) c;
            if (read == len) {
                return read - checked;
            }
        }
        return -1;
    }
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rsense-core-0.6.6 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.6.5 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.6.4 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.6.2 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.6.1 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.6.0 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.5.9 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.5.8 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.5.6 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.5.2 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.5.1 src/org/cx4a/rsense/util/HereDocReader.java
rsense-core-0.5.0 src/org/cx4a/rsense/util/HereDocReader.java