inputstream.java

来自「ALGAE是一个快速创建算法演示的框架。目前支持的算法实现语言包括java和c」· Java 代码 · 共 70 行

JAVA
70 行
字号
package edu.odu.cs.zeil.AlgAE.Server;import java.io.IOException;import edu.odu.cs.zeil.AlgAE.Server.MessageHandler;public class InputStream extends java.io.InputStream{  private String buffer;  private int pos;  private int buflen;  private MessageHandler msgs;    public InputStream(MessageHandler handler)  {    buflen = 0;    pos = 0;    msgs = handler;  }      /**     * Reads the next byte of data from this input stream. The value      * byte is returned as an <code>int</code> in the range      * <code>0</code> to <code>255</code>. If no byte is available      * because the end of the stream has been reached, the value      * <code>-1</code> is returned. This method blocks until input data      * is available, the end of the stream is detected, or an exception      * is thrown.      *     * @return     the next byte of data, or <code>-1</code> if the end of the     *             stream is reached.     * @exception  IOException  if an I/O error occurs.     */  public int read() throws java.io.IOException  {    while (pos >= buflen)      {	buffer = msgs.stdInput ();	buflen = buffer.length();	pos = 0;      }    int ch = buffer.charAt(pos);    ++pos;    return ch;  }    /**     * Returns the number of bytes that can be read from this input      * stream without blocking.      * @return     the number of bytes that can be read from this input stream     *             without blocking.     * @exception  IOException  if an I/O error occurs.     */    public int available() throws IOException {	return buflen - pos;    }    /**     * Closes this input stream and releases any system resources      * associated with the stream.      *     * @exception  IOException  if an I/O error occurs.     */    public void close() throws IOException    { buffer = null; }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?