java.io.Reader#ready ( )源码实例Demo

下面列出了java.io.Reader#ready ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码2 项目: jdk8u-dev-jdk   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码3 项目: jdk8u60   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码4 项目: openjdk-jdk8u   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码5 项目: openjdk-jdk9   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码6 项目: jdk8u-jdk   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码7 项目: hottub   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码8 项目: openjdk-8-source   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码9 项目: jdk8u_jdk   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码10 项目: jdk8u-jdk   文件: StreamTimeout.java
private static void gobble(InputStream is, Reader rd,
        int ec, boolean force)
                throws Exception
                {
    int a = is.available();
    boolean r = rd.ready();
    log.print("" + a + " bytes available, "
            + "reader " + (r ? "" : "not ") + "ready");
    if (!r && !force) {
        log.println();
        return;
    }
    int c;
    try {
        c = rd.read();
    } catch (InterruptedIOException x) {
        log.println();
        throw x;
    }
    log.println(", read() ==> "
            + (c >= 0 ? ("'" + (char)c + "'" ): "EOF"));
    if (c != ec)
        throw new Exception("Incorrect value read: Expected "
                + ec + ", read " + (char)c);
}
 
源代码11 项目: netbeans   文件: ExecSupport.java
private int read(Reader is, char[] buff, int start, int count) throws InterruptedException, IOException {

            while (!is.ready() && !done) {
                sleep(100);
            }
            return is.read(buff, start, count);
        }
 
源代码12 项目: samsung-tv-control   文件: SamsungRemote.java
/**
 * Reads all messages which are left in the buffer and therefore empties it.
 *
 * @param reader the reader.
 * @throws IOException if an I/O error occurs.
 */
private void emptyReaderBuffer(Reader reader) throws IOException {
    log("Emptying reader buffer.");
    while (reader.ready()) {
        readMessage(reader);
    }
}
 
源代码13 项目: netbeans   文件: ExecSupport.java
private int read(Reader is, char[] buff, int start, int count) throws InterruptedException, IOException {

            while (!is.ready() && !done) {
                sleep(100);
            }
            return is.read(buff, start, count);
        }
 
源代码14 项目: netbeans   文件: ExecSupport.java
private int read(Reader is, char[] buff, int start, int count) 
        throws InterruptedException, IOException {
    
    while (!is.ready() && !done) {
        sleep(100);
    }
    
    return is.read(buff, start, count);
}
 
源代码15 项目: googleads-java-lib   文件: CsvFilesTest.java
@Test
public void testGetCsvDataArray_fromReader() throws IOException {
  Reader reader = Files.newReader(csvStringFile, StandardCharsets.UTF_8);
  List<String[]> actualDataArray = CsvFiles.getCsvDataArray(reader, headerPresent);
  assertEquals(dataList.size(), actualDataArray.size());
  for (int i = 0; i < actualDataArray.size(); i++) {
    assertArrayEquals("Row " + i + " does not match", dataList.get(i), actualDataArray.get(i));
  }

  // Reader should be closed (not ready).
  thrown.expect(IOException.class);
  thrown.expectMessage("Stream closed");
  reader.ready();
}
 
源代码16 项目: angelix   文件: SolverProcess.java
/** Reads the given Reader until the given String is read (or end of input is reached);
 * may block until input is available; the stopping string must occur at the end of the
 * input.  This is typically used to read through a prompt on standard output; when the stopping
 * string (the prompt) is read, one knows that the output from the program is complete and not
 * to wait for any more.
 * 
 * @param r the Reader to read characters from
 * @param end a stopping String
 * @return the String read
 * @throws IOException if an IO failure occurs
 */
static public /*@NonNull*/String listenThru(/*@NonNull*/Reader r, /*@Nullable*/ String end) throws IOException {
	char[] buf = getBuffer();
	try {
		int len = end != null ? end.length() : 0;
		int p = 0; // Number of characters read
		int parens = 0;
		while (end != null || r.ready()) {
			//System.out.println("ABOUT TO READ " + p);
			int i = r.read(buf,p,buf.length-p);
			if (i == -1) break; // End of Input
			for (int ii=0; ii<i; ++ii) {
				if (buf[p+ii] == '(') ++parens; 
				else if (buf[p+ii] == ')') --parens;
			}
			p += i;
			//System.out.println("HEARD: " + new String(buf,0,p));
			if (end != null && p >= len) {
				// Need to compare a String to a part of a char array - we iterate by
				// hand to avoid creating a new String or CharBuffer object
				boolean match = true;
				int k = p-len;
				for (int j=0; j<len; j++) {
					if (end.charAt(j) != buf[k++]) { match = false; break; }
				}
				if (match && (!"\n".equals(end) || parens == 0)) break; // stopping string matched
			}
			if (p == buf.length) { // expand the buffer
				char[] nbuf = new char[2*buf.length];
				System.arraycopy(buf,0,nbuf,0,p);
				buf = nbuf;
			}
		}
		return new String(buf,0,p);
	} finally {
		putBuffer(buf);
	}
}
 
源代码17 项目: james-project   文件: BayesianAnalyzer.java
private String nextToken(Reader reader) throws java.io.IOException {
    StringBuilder token = new StringBuilder();
    int i;
    char ch;
    char ch2;
    boolean previousWasDigit = false;
    boolean tokenCharFound = false;

    if (!reader.ready()) {
        return null;
    }

    while ((i = reader.read()) != -1) {

        ch = (char) i;

        if (ch == ':') {
            String tokenString = token.toString() + ':';
            if (tokenString.equals("From:") || tokenString.equals("Return-Path:") || tokenString.equals("Subject:") || tokenString.equals("To:")) {
                return tokenString;
            }
        }

        if (Character.isLetter(ch) || ch == '-' || ch == '$' || ch == '€'
                || ch == '!' || ch == '\'') {
            tokenCharFound = true;
            previousWasDigit = false;
            token.append(ch);
        } else if (Character.isDigit(ch)) {
            tokenCharFound = true;
            previousWasDigit = true;
            token.append(ch);
        } else if (previousWasDigit && (ch == '.' || ch == ',')) {
            reader.mark(1);
            previousWasDigit = false;
            i = reader.read();
            if (i == -1) {
                break;
            }
            ch2 = (char) i;
            if (Character.isDigit(ch2)) {
                tokenCharFound = true;
                previousWasDigit = true;
                token.append(ch);
                token.append(ch2);
            } else {
                reader.reset();
                break;
            }
        } else if (ch == '\r') {
            // cr found, ignore
        } else if (ch == '\n') {
            // eol found
            tokenCharFound = true;
            previousWasDigit = false;
            token.append(ch);
            break;
        } else if (tokenCharFound) {
            break;
        }
    }

    if (tokenCharFound) {
        // System.out.println("Token read: " + token);
        return token.toString();
    } else {
        return null;
    }
}
 
源代码18 项目: spring4-understanding   文件: XmlBeansMarshaller.java
@Override
public boolean ready() throws IOException {
	Reader rdr = getReader();
	return (rdr != null && rdr.ready());
}
 
源代码19 项目: Repeat   文件: IPCProtocol.java
/**
 * Retrieve a list of messages from the reader.
 * This blocks until there is a message to be read from
 * the reader.
 */
public static List<String> getMessages(Reader reader) throws IOException, InterruptedException {
	/**
	 * Create a blocking read waiting for the next communication.
	 */
	int retryCount = 0;
	int firstCharacter = reader.read();
	while (firstCharacter == -1) {
		retryCount++;
		if (retryCount < MAX_MESSAGE_RETRY) {
			Thread.sleep(READ_LOOP_SLEEP_DURATION_MS);
		} else {
			LOGGER.log(Level.WARNING, "Max retry reached.");
			return null;
		}
		firstCharacter = reader.read();
	}

	/**
	 * Build the request.
	 */
	List<String> output = new LinkedList<>();
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();

	if (firstCharacter != MESSAGE_DELIMITER) {
		buffer.write(firstCharacter);
	}

	while (reader.ready() || output.isEmpty()) {
		int readValue = reader.read();
		if (readValue != -1) {
			if (readValue == MESSAGE_DELIMITER) {
				if (buffer.size() != 0) {
					output.add(IPCCodec.decode(buffer.toByteArray()));
					buffer.reset();
				}
			} else if (readValue != NULL_CHARACTER) {
				buffer.write(readValue);
			}
		} else {
			if (buffer.size() != 0) {
				output.add(IPCCodec.decode(buffer.toByteArray()));
				buffer.reset();
			}
			break;
		}
	}
	return output;
}
 
源代码20 项目: james-project   文件: Tokenizer.java
private String nextToken(Reader reader) throws java.io.IOException {
    StringBuilder token = new StringBuilder();
    int i;
    char ch;
    char ch2;
    boolean previousWasDigit = false;
    boolean tokenCharFound = false;

    if (!reader.ready()) {
        return null;
    }

    while ((i = reader.read()) != -1) {

        ch = (char) i;

        if (ch == ':') {
            String tokenString = token.toString() + ':';
            if (tokenString.equals("From:") || tokenString.equals("Return-Path:") || tokenString.equals("Subject:") || tokenString.equals("To:")) {
                return tokenString;
            }
        }

        if (Character.isLetter(ch) || ch == '-' || ch == '$' || ch == '€'
                || ch == '!' || ch == '\'') {
            tokenCharFound = true;
            previousWasDigit = false;
            token.append(ch);
        } else if (Character.isDigit(ch)) {
            tokenCharFound = true;
            previousWasDigit = true;
            token.append(ch);
        } else if (previousWasDigit && (ch == '.' || ch == ',')) {
            reader.mark(1);
            previousWasDigit = false;
            i = reader.read();
            if (i == -1) {
                break;
            }
            ch2 = (char) i;
            if (Character.isDigit(ch2)) {
                tokenCharFound = true;
                previousWasDigit = true;
                token.append(ch);
                token.append(ch2);
            } else {
                reader.reset();
                break;
            }
        } else if (ch == '\r') { //NOPMD
            // cr found, ignore
        } else if (ch == '\n') {
            // eol found
            tokenCharFound = true;
            previousWasDigit = false;
            token.append(ch);
            break;
        } else if (tokenCharFound) {
            break;
        }
    }

    if (tokenCharFound) {
        // System.out.println("Token read: " + token);
        return token.toString();
    } else {
        return null;
    }
}