inputstream.java
来自「轻量嵌入JVM,可用于掌上设备手机等手持消息设备.」· Java 代码 · 共 140 行
JAVA
140 行
/************************************************************************
This file is part of java core libraries for the simpleRTJ virtual machine.
This file is covered by the GNU GPL with the following exception:
As a special exception, the copyright holders of this library give you permission
to link this library with independent modules to produce an executable, regardless
of the license terms of these independent modules, and to copy and distribute the
resulting executable under terms of your choice, provided that you also meet, for
each linked independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from or based on
this library. If you modify this library, you may extend this exception to your
version of the library, but you are not obligated to do so. If you do not wish
to do so, delete this exception statement from your version.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Created/modified by:
RTJ Computing
***********************************************************************/
package java.io;
public abstract class InputStream
{
public InputStream()
{
return;
}
public void mark(int readlimit)
{
return;
}
public boolean markSupported()
{
return(false);
}
public void reset() throws IOException
{
throw new IOException("Mark not supported in this class");
}
public int available() throws IOException
{
return(0);
}
public int skip(int num_bytes) throws IOException
{
int buf_size = 256;
byte[] buf = new byte[buf_size];
if(num_bytes <= 0)
return(0);
int loop_count = num_bytes / buf_size;
int extra_bytes = (int)(num_bytes % buf_size);
int bytes_read = 0;
int total_read = 0;
for(int i = 0; i < loop_count; i++)
{
bytes_read = read(buf, 0, buf.length);
if(bytes_read == -1)
return(total_read);
if(bytes_read != buf_size)
return(total_read + bytes_read);
total_read += bytes_read;
}
bytes_read = read(buf, 0, extra_bytes);
if(bytes_read == -1)
return(total_read);
return(total_read + bytes_read);
}
public abstract int read() throws IOException;
public int read(byte[] buf) throws IOException
{
return(read(buf, 0, buf.length));
}
public int read(byte[] buf, int offset, int len) throws IOException
{
if(len == 0)
return(0);
// Read the first byte here in order to allow IOException's to
// propagate up
int byte_read = read();
if(byte_read == -1)
return(-1);
buf[offset] = (byte)byte_read;
int total_read = 1;
// Read the rest of the bytes
try
{
for(int i = 1; i < len; i++)
{
byte_read = read();
if(byte_read == -1)
return(total_read);
buf[offset + i] = (byte)byte_read;
++total_read;
}
}
catch(IOException e)
{
return(total_read);
}
return(total_read);
}
public void close() throws IOException
{
return;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?