stringreader.java.svn-base
来自「利用J2ME编写的手机应用程序。 功能包括显示图片」· SVN-BASE 代码 · 共 104 行
SVN-BASE
104 行
package wFramework;
import java.io.IOException;
import java.io.Reader;
/**
* A subclass that allows "streaming" of internal stringdata
* Makes it possible to use the KXML parsing engine...
*
* See the 'Reader' class for documentation on the individual methods..
* @author Marius Bj鴕ge
*
*/
public class StringReader extends Reader
{
private String data;
private int currentpos;
private int length;
public StringReader(String input)
{
data = input;
currentpos = 0;
length = data.length();
}
public void close() throws IOException
{
data = "";
currentpos = 0;
length = 0;
}
public long skip(long n) throws IOException
{
long skipped = n;
if (currentpos + n >= length)
{
skipped = length - currentpos;
currentpos = length - 1;
}
else
currentpos += n;
return skipped;
}
public void reset() throws IOException
{
currentpos = 0;
}
public int read(char[] cbuf) throws IOException
{
if (currentpos == length)
return -1;
int numread = 0;
for (int i = 0; i < cbuf.length; i++)
{
int c = read();
if (c >= 0)
cbuf[i] = (char)c;
else
break;
numread++;
}
return numread;
}
public int read() throws IOException
{
if (currentpos == length)
return -1;
int c = data.charAt(currentpos);
currentpos++;
return c;
}
public int read(char[] cbuf, int offset, int len) throws IOException
{
if (currentpos == length)
return -1;
int numread = 0;
for (int i = 0; i < len; i++)
{
int c = read();
if (c >= 0)
{
cbuf[i + offset] = (char)c;
numread++;
}
else
break;
}
return numread;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?