云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Java语言编程规范.

Java语言编程规范.

  • 62 次阅读
  • 3 次下载
  • 2026/4/27 4:24:09

Java语言编程规范for ETS Version: <1.0> Date: <2003/3/13> 中经互联网络有限公司 nChars = dst + n; nextChar = dst; } }

/**

* 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:

    *

    *

  • The specified number of characters have been read, *

    *

  • The read method of the underlying stream returns * -1, indicating end-of-file, or *

    *

  • The 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> 中经互联网络有限公司 return 0; } int n = read1(cbuf, off, len); if (n <= 0) return n; while ((n < len) && in.ready()) { int n1 = read1(cbuf, off + n, len - n); if (n1 <= 0) break; n += n1; } return n; } }

/**

* 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

搜索更多关于: Java语言编程规范. 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

Java语言编程规范for ETS Version: Date: 中经互联网络有限公司 nChars = dst + n; nextChar = dst; } } /** * Read a single character. * * @exception IOException If an I/O error occurs */ public int read() throws IOException { synchronized (lock) { ensureOpen(); if (nextChar >= nChars) {

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com