📄 stringreader.java.svn-base
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -