当前位置:首页 > Java语言编程规范.
Java语言编程规范for ETS Version: <1.0> Date: <2003/3/13> 中经互联网络有限公司
/**
* Read a single character. *
* @exception IOException If an I/O error occurs */
public int read() throws IOException { synchronized (lock) { ensureOpen(); if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1; } return cb[nextChar++]; } }
/**
* Read characters into a portion of an array, reading from the underlying * stream at most once if necessary. */
private int read1(char[] cbuf, int off, int len) throws IOException { if (nextChar >= nChars) { /* If the requested length is at least as large as the buffer, and if there is no mark/reset activity, do not bother to copy the characters into the local buffer. In this way buffered streams will cascade harmlessly. */ if (len >= cb.length && markedChar <= UNMARKED) { return in.read(cbuf, off, len); } fill(); } if (nextChar >= nChars) return -1; int n = Math.min(len, nChars - nextChar); System.arraycopy(cb, nextChar, cbuf, off, n); nextChar += n; return n; }
/**
* Read characters into a portion of an array. *
*
This method implements the general contract of the corresponding Confidential ?中经互联网络有限公司
Page 25 of 31
Java语言编程规范for ETS Version: <1.0> Date: <2003/3/13> 中经互联网络有限公司 {@link Reader#read(char[], int, int) read} method of the * {@link Reader} class. As an additional convenience, it * attempts to read as many characters as possible by repeatedly invoking * the read method of the underlying stream. This iterated * read continues until one of the following conditions becomes * true: *
*
*
read method of the underlying stream returns * -1, indicating end-of-file, or * *
ready method of the underlying stream * returns false, indicating that further input requests * would block. *
* If the first read on the underlying stream returns * -1 to indicate end-of-file then this method returns
* -1. Otherwise this method returns the number of characters * actually read. *
*
Subclasses of this class are encouraged, but not required, to * attempt to read as many characters as possible in the same fashion. *
*
Ordinarily this method takes characters from this stream's character * buffer, filling it from the underlying stream as necessary. If,
* however, the buffer is empty, the mark is not valid, and the requested * length is at least as large as the buffer, then this method will read * characters directly from the underlying stream into the given array. * Thus redundant BufferedReaders will not copy data * unnecessarily. *
* @param cbuf Destination buffer
* @param off Offset at which to start storing characters * @param len Maximum number of characters to read *
* @return The number of characters read, or -1 if the end of the * stream has been reached *
* @exception IOException If an I/O error occurs */
public int read(char cbuf[], int off, int len) throws IOException { synchronized (lock) { ensureOpen();
if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { Confidential ?中经互联网络有限公司
Page 26 of 31
Java语言编程规范for ETS Version: <1.0> Date: <2003/3/13> 中经互联网络有限公司
/**
* Read a line of text. A line is considered to be terminated by any one * of a line feed ('\\n'), a carriage return ('\\r'), or a carriage return * followed immediately by a linefeed. *
* @param skipLF If true, the next '\\n' will be skipped *
* @return A String containing the contents of the line, not including * any line-termination characters, or null if the end of the * stream has been reached *
* @see java.io.LineNumberReader#readLine() *
* @exception IOException If an I/O error occurs */
String readLine(boolean skipLF) throws IOException { StringBuffer s = new StringBuffer(defaultExpectedLineLength); synchronized (lock) { ensureOpen(); bufferLoop: for (;;) { if (nextChar >= nChars) fill(); if (nextChar >= nChars) { /* EOF */ if (s.length() > 0) return s.toString(); else return null; } boolean eol = false; char c = 0; int i; Confidential ?中经互联网络有限公司
Page 27 of 31
Java语言编程规范for ETS Version: <1.0> Date: <2003/3/13> 中经互联网络有限公司
/* Skip a leftover '\\n' */ if (skipLF && (cb[nextChar] == '\\n')) nextChar++; charLoop: for (i = nextChar; i < nChars; i++) { c = cb[i]; if ((c == '\\n') || (c == '\\r')) { eol = true; break charLoop; } } s.append(cb, nextChar, i - nextChar); nextChar = i; if (eol) { nextChar++; if (c == '\\r') { if (nextChar >= nChars) fill(); if ((nextChar < nChars) && (cb[nextChar] == '\\n')) nextChar++; } break bufferLoop; }
skipLF = false; } } return s.toString(); }
/**
* Read a line of text. A line is considered to be terminated by any one * of a line feed ('\\n'), a carriage return ('\\r'), or a carriage return * followed immediately by a linefeed. *
* @return A String containing the contents of the line, not including * any line-termination characters, or null if the end of the * stream has been reached *
* @exception IOException If an I/O error occurs */
public String readLine() throws IOException { return readLine(false); }
Confidential ?中经互联网络有限公司
Page 28 of 31
共分享92篇相关文档