org.codehaus.swizzle.stream
Class StreamLexer
java.lang.Object
org.codehaus.swizzle.stream.StreamLexer
public class StreamLexer
- extends Object
- Version:
- $Revision$ $Date$
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
StreamLexer
public StreamLexer(InputStream delegate)
readToken
public String readToken(String begin,
String end)
throws Exception
- Seeks in the stream till it finds the start token, reads into a buffer till it finds the end token, then returns the token (the buffer) as a String.
Given the input stream contained the sequence "123ABC456EFG"
InputStream in ... StreamLexer lexer = new StreamLexer(in); String token = lexer.readToken("3","C"); // returns the string "AB" char character = (char)in.read(); // returns the character '4'
Does not support regular expression matching.
- Parameters:
begin - start tokenend - end token
- Returns:
- the token inbetween the start and end token or null if the end of the stream was reached
- Throws:
Exception
readToken
public String readToken(String string)
throws Exception
- Seeks in the stream till it finds and has completely read the token, then stops. Useful for seeking up to a certain point in the stream.
Given the input stream contained the sequence "000[A]111[B]222[C]345[D]"
InputStream in ... StreamLexer lexer = new StreamLexer(in); String token = lexer.readToken("222"); // returns the string "222" token = lexer.readToken("[", "]"); // returns the string "C" char
character = (char)in.read(); // returns the character '3'
Does not support regular expression matching.
- Parameters:
string - the token to find in the stream
- Returns:
- the token if found in the stream or null if the stream was reached (i.e. the token was not found)
- Throws:
Exception
read
public String read(String begin,
String end)
throws IOException
- Throws:
IOException
read
public String read(String string)
throws IOException
- Throws:
IOException
seek
public String seek(String begin,
String end)
throws IOException
- Throws:
IOException
seek
public String seek(String string)
throws IOException
- Throws:
IOException
peek
public String peek(String begin,
String end)
throws IOException
- Throws:
IOException
peek
public String peek(String string)
throws IOException
- Throws:
IOException
mark
public StreamLexer mark()
throws IOException
- Throws:
IOException
unmark
public void unmark()
mark
public StreamLexer mark(String limit)
throws IOException
- Throws:
IOException
readAndMark
public boolean readAndMark(String begin,
String end)
throws IOException
- Throws:
IOException
seekAndMark
public boolean seekAndMark(String begin,
String end)
throws IOException
- Throws:
IOException
readAndUnmark
public boolean readAndUnmark()
throws IOException
- Throws:
IOException
seekAndUnmark
public boolean seekAndUnmark()
throws IOException
- Throws:
IOException
Copyright © 2011 The Codehaus Foundation. All Rights Reserved.