Java Code Examples for java.io.Reader#markSupported()

The following examples show how to use java.io.Reader#markSupported() . 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
private static char[] readCharArray(Reader reader) throws IOException {
    if (reader.markSupported()) {
        reader.mark(1024);
    }
    int length = reader.read();
    int delimiter = reader.read();
    if (delimiter != 0) {
        if (reader.markSupported()) {
            reader.reset();
        }
        throw new IOException("Unsupported reply exception");
    }
    char[] buffer = new char[length];
    reader.read(buffer);
    return buffer;
}
 
Example 2
Source Project: j2objc   File: AVA.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean trailingSpace(Reader in) throws IOException {

        boolean trailing = false;

        if (!in.markSupported()) {
            // oh well
            return true;
        } else {
            // make readAheadLimit huge -
            // in practice, AVA was passed a StringReader from X500Name,
            // and StringReader ignores readAheadLimit anyways
            in.mark(9999);
            while (true) {
                int nextChar = in.read();
                if (nextChar == -1) {
                    trailing = true;
                    break;
                } else if (nextChar == ' ') {
                    continue;
                } else if (nextChar == '\\') {
                    int followingChar = in.read();
                    if (followingChar != ' ') {
                        trailing = false;
                        break;
                    }
                } else {
                    trailing = false;
                    break;
                }
            }

            in.reset();
            return trailing;
        }
    }
 
Example 3
/**
 * Construct a JSONTokener from a Reader.
 *
 * @param reader     A reader.
 */
public SortedJSONTokener(Reader reader) {
    this.reader = reader.markSupported()
            ? reader
            : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 4
Source Project: equalize-xpi-modules   File: JSONTokener.java    License: MIT License 5 votes vote down vote up
/**
 * Construct a JSONTokener from a Reader.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported()
        ? reader
        : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 5
/**
 * Construct a JSONTokener from a Reader.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported()
        ? reader
        : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 6
Source Project: jdk8u-jdk   File: AVA.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static boolean trailingSpace(Reader in) throws IOException {

        boolean trailing = false;

        if (!in.markSupported()) {
            // oh well
            return true;
        } else {
            // make readAheadLimit huge -
            // in practice, AVA was passed a StringReader from X500Name,
            // and StringReader ignores readAheadLimit anyways
            in.mark(9999);
            while (true) {
                int nextChar = in.read();
                if (nextChar == -1) {
                    trailing = true;
                    break;
                } else if (nextChar == ' ') {
                    continue;
                } else if (nextChar == '\\') {
                    int followingChar = in.read();
                    if (followingChar != ' ') {
                        trailing = false;
                        break;
                    }
                } else {
                    trailing = false;
                    break;
                }
            }

            in.reset();
            return trailing;
        }
    }
 
Example 7
Source Project: openjdk-jdk8u   File: AVA.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static boolean trailingSpace(Reader in) throws IOException {

        boolean trailing = false;

        if (!in.markSupported()) {
            // oh well
            return true;
        } else {
            // make readAheadLimit huge -
            // in practice, AVA was passed a StringReader from X500Name,
            // and StringReader ignores readAheadLimit anyways
            in.mark(9999);
            while (true) {
                int nextChar = in.read();
                if (nextChar == -1) {
                    trailing = true;
                    break;
                } else if (nextChar == ' ') {
                    continue;
                } else if (nextChar == '\\') {
                    int followingChar = in.read();
                    if (followingChar != ' ') {
                        trailing = false;
                        break;
                    }
                } else {
                    trailing = false;
                    break;
                }
            }

            in.reset();
            return trailing;
        }
    }
 
Example 8
/**
 * Construct a JSONTokener from a Reader. The caller must close the Reader.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported()
            ? reader
                    : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.characterPreviousLine = 0;
    this.line = 1;
}
 
Example 9
Source Project: sc2gears   File: JSONTokener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct a JSONTokener from a reader.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported() ? 
    		reader : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 10
Source Project: mil-sym-java   File: JSONTokener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct a JSONTokener from a Reader.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported() ? 
    		reader : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 11
Source Project: RipplePower   File: JSONTokener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct a JSONTokener from a Reader.
 * 
 * @param reader
 *            A reader.
 */
public JSONTokener(Reader reader) {
	this.reader = reader.markSupported() ? reader : new BufferedReader(
			reader);
	this.eof = false;
	this.usePrevious = false;
	this.previous = 0;
	this.index = 0;
	this.character = 1;
	this.line = 1;
}
 
Example 12
Source Project: alipay-java-sdk   File: JSONTokener.java    License: MIT License 5 votes vote down vote up
/**
 * Construct a JSONTokener from a Reader.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported()
        ? reader
        : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 13
Source Project: hottub   File: AVA.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static boolean trailingSpace(Reader in) throws IOException {

        boolean trailing = false;

        if (!in.markSupported()) {
            // oh well
            return true;
        } else {
            // make readAheadLimit huge -
            // in practice, AVA was passed a StringReader from X500Name,
            // and StringReader ignores readAheadLimit anyways
            in.mark(9999);
            while (true) {
                int nextChar = in.read();
                if (nextChar == -1) {
                    trailing = true;
                    break;
                } else if (nextChar == ' ') {
                    continue;
                } else if (nextChar == '\\') {
                    int followingChar = in.read();
                    if (followingChar != ' ') {
                        trailing = false;
                        break;
                    }
                } else {
                    trailing = false;
                    break;
                }
            }

            in.reset();
            return trailing;
        }
    }
 
Example 14
private static boolean trailingSpace(Reader in) throws IOException {

        boolean trailing = false;

        if (!in.markSupported()) {
            // oh well
            return true;
        } else {
            // make readAheadLimit huge -
            // in practice, AVA was passed a StringReader from X500Name,
            // and StringReader ignores readAheadLimit anyways
            in.mark(9999);
            while (true) {
                int nextChar = in.read();
                if (nextChar == -1) {
                    trailing = true;
                    break;
                } else if (nextChar == ' ') {
                    continue;
                } else if (nextChar == '\\') {
                    int followingChar = in.read();
                    if (followingChar != ' ') {
                        trailing = false;
                        break;
                    }
                } else {
                    trailing = false;
                    break;
                }
            }

            in.reset();
            return trailing;
        }
    }
 
Example 15
/**
 * Construct a JSONTokener from a string.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported() ? 
    		reader : new BufferedReader(reader);
    this.useLastChar = false;
    this.index = 0;
}
 
Example 16
Source Project: JMCCC   File: JSONTokener.java    License: MIT License 5 votes vote down vote up
/**
 * Construct a JSONTokener from a Reader.
 *
 * @param reader A reader.
 */
public JSONTokener(Reader reader) {
	this.reader = reader.markSupported()
			? reader
			: new BufferedReader(reader);
	this.eof = false;
	this.usePrevious = false;
	this.previous = 0;
	this.index = 0;
	this.character = 1;
	this.line = 1;
}
 
Example 17
public JSONTokenizer(Reader reader) {
    this.reader = reader.markSupported()
            ? reader
            : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 18
Source Project: mil-sym-android   File: JSONTokener.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct a JSONTokener from a Reader.
 *
 * @param reader     A reader.
 */
public JSONTokener(Reader reader) {
    this.reader = reader.markSupported() ? 
    		reader : new BufferedReader(reader);
    this.eof = false;
    this.usePrevious = false;
    this.previous = 0;
    this.index = 0;
    this.character = 1;
    this.line = 1;
}
 
Example 19
Source Project: commons-jexl   File: TemplateEngine.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Read lines from a (buffered / mark-able) reader keeping all new-lines and line-feeds.
 * @param reader the reader
 * @return the line iterator
 */
protected static Iterator<CharSequence> readLines(final Reader reader) {
    if (!reader.markSupported()) {
        throw new IllegalArgumentException("mark support in reader required");
    }
    return new Iterator<CharSequence>() {
        private CharSequence next = doNext();

        private CharSequence doNext() {
            StringBuffer strb = new StringBuffer(64); // CSOFF: MagicNumber
            int c;
            boolean eol = false;
            try {
                while ((c = reader.read()) >= 0) {
                    if (eol) {// && (c != '\n' && c != '\r')) {
                        reader.reset();
                        break;
                    }
                    if (c == '\n') {
                        eol = true;
                    }
                    strb.append((char) c);
                    reader.mark(1);
                }
            } catch (IOException xio) {
                return null;
            }
            return strb.length() > 0 ? strb : null;
        }

        @Override
        public boolean hasNext() {
            return next != null;
        }

        @Override
        public CharSequence next() {
            CharSequence current = next;
            if (current != null) {
                next = doNext();
            }
            return current;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Not supported.");
        }
    };
}
 
Example 20
Source Project: groovy   File: IOGroovyMethods.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Read a single, whole line from the given Reader. This method is designed for use with
 * Readers that support the {@code mark()} operation like BufferReader. It has a fallback
 * behavior for Readers that don't support mark() but the behavior doesn't correctly
 * detect multi-character line termination (e.g. carriage return followed by linefeed).
 * We recommend for Readers that don't support mark() you consider using one of the
 * following methods instead: eachLine, readLines, or iterator.
 *
 * @param self a Reader
 * @return a line
 * @throws IOException if an IOException occurs.
 * @see #readLines(java.io.Reader)
 * @see #iterator(java.io.Reader)
 * @see #eachLine(java.io.Reader, groovy.lang.Closure)
 * @since 1.0
 */
public static String readLine(Reader self) throws IOException {
    if (self instanceof BufferedReader) {
        BufferedReader br = (BufferedReader) self;
        return br.readLine();
    }
    if (self.markSupported()) {
        return readLineFromReaderWithMark(self);
    }
    return readLineFromReaderWithoutMark(self);
}