... genau... StreamTokenizer... nicht zu verwechseln mit StringTokenizer
[highlight=java]package extended.stream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
public class ExtendedStreamTokenizer
extends StreamTokenizer
{
public static final IOException UNEXPECTED_EOF = new IOException("unexpected end of file");
public static final IOException UNEXPECTED_OPEN = new IOException("unexpected open char");
public static final IOException UNEXPECTED_CLOSE = new IOException("unexpected close char");
public static final int
TT_CLOSE = -5,
TT_OPEN = -6,
TT_INVALID = -7,
TT_DOUBLEQUOTE = '"',
TT_SINGLEQUOTE = '\'';
private final BufferedInputStream in;
private int open = '{', close = '}', markedType;
private String markedString;
private double markedNumber;
public ExtendedStreamTokenizer(BufferedInputStream in)
{
super(new InputStreamReader(in));
this.in = in;
}
public void whitespaceChar(int token)
{
whitespaceChars(token, token);
}
public void parseNumbers(boolean sw)
{
if(sw) {
super.parseNumbers();
} else {
ordinaryChars('0', '9');
ordinaryChar('.');
ordinaryChar('-');
wordChars('0', '9');
wordChar('.');
wordChar('-');
}
}
public void wordChar(int token)
{
wordChars(token, token);
}
public void openChar(int token)
{
open = token & 0xFF;
}
public void closeChar(int token)
{
close = token & 0xFF;
}
public int nextToken()
throws IOException {
super.nextToken();
if(ttype == open) ttype = TT_OPEN;
if(ttype == close) ttype = TT_CLOSE;
return ttype;
}
public void nextLine()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_EOL);
}
public void nextWord()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_WORD);
}
public void nextNumber()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_NUMBER);
}
public void nextClose()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_CLOSE);
}
public void nextOpen()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_OPEN);
}
public void nextQuotedString()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_DOUBLEQUOTE && ttype != TT_SINGLEQUOTE);
}
public void nextSingleQuotedString()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_SINGLEQUOTE);
}
public void nextDoubleQuotedString()
throws IOException
{
do {
if(ttype == TT_EOF) throw UNEXPECTED_EOF;
nextToken();
} while(ttype != TT_DOUBLEQUOTE);
}
public synchronized void mark(int readlimit)
{
in.mark(readlimit);
markedType = ttype;
markedString = sval;
markedNumber = nval;
}
public synchronized void reset()
throws IOException
{
in.reset();
ttype = markedType;
sval = markedString;
nval = markedNumber;
}
public synchronized int available()
throws IOException
{
return in.available();
}
}[/highlight]Dieser Code dürfte der Grund dafür sein, warum ich den StringTokenizer gar nicht mehr brauche. Zeilen zählen, Wörter zählen, Diverse String-Typen (SingleQuoted, DoubleQuoted, 0-Terminiert) lesen, im Prinzip allses was ein entsprechend konfigurierter StreamTokenizer auch kann. Zusätzlich kann an jeder beliebigen der Stream markiert werden, und später an die Stelle zurück gesprungen werden. Deswegen ist dafür auch ein BufferedInputstream nötig. Hier klemmts allerdings noch bei "LINENO", aber man arbeitet dran. Vllt. hilft der ja weiter. Ist aber (wie der grösste teil meines Quellcodes) nicht Dokumentiert.