本文整理匯總了Java中java.io.PushbackReader類的典型用法代碼示例。如果您正苦於以下問題:Java PushbackReader類的具體用法?Java PushbackReader怎麽用?Java PushbackReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PushbackReader類屬於java.io包,在下文中一共展示了PushbackReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: invoke
import java.io.PushbackReader; //導入依賴的package包/類
public Object invoke(Object reader, Object pct, Object opts, Object pendingForms) {
PushbackReader r = (PushbackReader) reader;
if(ARG_ENV.deref() == null)
{
return interpretToken(readToken(r, '%'));
}
int ch = read1(r);
unread(r, ch);
//% alone is first arg
if(ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch))
{
return registerArg(1);
}
Object n = read(r, true, null, true, opts, ensurePending(pendingForms));
if(n.equals(Compiler._AMP_))
return registerArg(-1);
if(!(n instanceof Number))
throw new IllegalStateException("arg literal must be %, %& or %integer");
return registerArg(((Number) n).intValue());
}
示例2: readToken
import java.io.PushbackReader; //導入依賴的package包/類
static private String readToken(PushbackReader r, char initch, boolean leadConstituent) {
StringBuilder sb = new StringBuilder();
if(leadConstituent && nonConstituent(initch))
throw Util.runtimeException("Invalid leading character: " + (char)initch);
sb.append(initch);
for(; ;)
{
int ch = read1(r);
if(ch == -1 || isWhitespace(ch) || isTerminatingMacro(ch))
{
unread(r, ch);
return sb.toString();
}
else if(nonConstituent(ch))
throw Util.runtimeException("Invalid constituent character: " + (char)ch);
sb.append((char) ch);
}
}
示例3: parseComment
import java.io.PushbackReader; //導入依賴的package包/類
/** Parser that eats everything until two consecutive dashes (inclusive) */
private void parseComment( PushbackReader in ) throws IOException, WrongDTDException {
int state = COMM_TEXT;
for( ;; ) {
int i = in.read();
if( i == -1 ) break; // EOF
switch( state ) {
case COMM_TEXT:
if( i == '-' ) state = COMM_DASH;
break;
case COMM_DASH:
if( i == '-' ) return; // finished eating comment
state = COMM_TEXT;
break;
}
}
throw new WrongDTDException( "Premature end of DTD" ); // NOI18N
}
示例4: parseEntityReference
import java.io.PushbackReader; //導入依賴的package包/類
/** Parser that reads the name of entity reference and replace it with
* the content of that entity (using the pushback capability of input).
* It gets the control just after starting '%'
* @returns the name of reference which was replaced. */
private String parseEntityReference( PushbackReader in ) throws IOException, WrongDTDException {
StringBuffer sb = new StringBuffer();
for( ;; ) {
int i = in.read();
if( i == -1 ) break; // EOF
if( isNameChar( (char)i ) ) {
sb.append( (char)i ); // next char of name
} else {
String entValue = (String)entityMap.get( sb.toString() ); //get the entity content
if( entValue == null )
throw new WrongDTDException( "No such entity: \"" + sb + "\"" ); // NOI18N
if( i != ';' ) in.unread( i );
in.unread( entValue.toCharArray() ); // push it back to stream
return sb.toString();
}
}
throw new WrongDTDException( "Premature end of DTD" ); // NOI18N
}
示例5: readToken
import java.io.PushbackReader; //導入依賴的package包/類
private static Object readToken(PushbackReader r, IEOFHandler ieofHandler, int ch) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append((char)ch);
while(true) {
ch = r.read();
if (ch == -1) {
ieofHandler.eof();
break;
} else if (Character.isWhitespace(ch)) {
break;
} else if (ch == ')') {
r.unread(ch);
break;
} else {
sb.append((char)ch);
}
}
return interpretToken(sb.toString());
}
示例6: readMatch
import java.io.PushbackReader; //導入依賴的package包/類
/**
* Extracts matching character from stream.
* A non-matching character is pushed back to the stream.
*
* @param in The input.
* @param c The character to expect from the stream.
*
* @return <code>true</code> if the specified character was extracted from the stream, <code>false</code> otherwise.
*
* @exception java.io.IOException In case of read error in the stream.
*/
public static boolean readMatch(PushbackReader in, int c)
throws IOException
{
int i = in.read();
if (i != c)
{
if (i != -1)
{
in.unread(i);
}
return false;
}
return true;
}
示例7: extractWhitespace
import java.io.PushbackReader; //導入依賴的package包/類
/**
* Extracts whitespace from stream.
*
* @param in The input.
*
* @exception java.io.IOException In case of read error in the stream.
*/
public static void extractWhitespace(PushbackReader in)
throws IOException
{
int c;
while (Character.isWhitespace((char) (c = in.read())))
{
// Extracts any whitespace
}
if (c != -1)
{
in.unread(c);
}
}
示例8: Aprational
import java.io.PushbackReader; //導入依賴的package包/類
/**
* Reads an aprational from a reader. The specified radix is used.
*
* @param in The input stream.
* @param radix The radix to be used.
*
* @exception java.io.IOException In case of I/O error reading the stream.
* @exception java.lang.NumberFormatException In case the number is invalid.
* @exception java.lang.IllegalArgumentException In case the denominator is zero.
*
* @see #Aprational(PushbackReader)
*/
public Aprational(PushbackReader in, int radix)
throws IOException, NumberFormatException, IllegalArgumentException, ApfloatRuntimeException
{
this.numerator = new Apint(in, radix);
ApfloatHelper.extractWhitespace(in);
if (!ApfloatHelper.readMatch(in, '/'))
{
this.denominator = ONES[radix];
return;
}
ApfloatHelper.extractWhitespace(in);
this.denominator = new Apint(in, radix);
checkDenominator();
reduce();
}
示例9: readExponent
import java.io.PushbackReader; //導入依賴的package包/類
private static long readExponent(PushbackReader in)
throws IOException, NumberFormatException
{
StringBuilder buffer = new StringBuilder(20);
int input;
for (long i = 0; (input = in.read()) != -1; i++)
{
char c = (char) input;
int digit = Character.digit(c, 10); // Exponent is always in base 10
if (i == 0 && c == '-' ||
digit != -1)
{
buffer.append(c);
}
else
{
// Stop at first invalid character and put it back
in.unread(input);
break;
}
}
return Long.parseLong(buffer.toString());
}
示例10: StdXMLReader
import java.io.PushbackReader; //導入依賴的package包/類
/**
* Initializes the XML reader.
*
* @param reader the input for the XML data.
*/
public StdXMLReader(Reader reader)
{
this.currentReader = new StackedReader();
this.readers = new Stack();
this.currentReader.lineReader = new LineNumberReader(reader);
this.currentReader.pbReader
= new PushbackReader(this.currentReader.lineReader, 2);
this.currentReader.publicId = "";
try {
this.currentReader.systemId = new URL("file:.");
} catch (MalformedURLException e) {
// never happens
}
}
示例11: startNewStream
import java.io.PushbackReader; //導入依賴的package包/類
/**
* Starts a new stream from a Java reader. The new stream is used
* temporary to read data from. If that stream is exhausted, control
* returns to the parent stream.
*
* @param reader the non-null reader to read the new data from
* @param isInternalEntity true if the reader is produced by resolving
* an internal entity
*/
public void startNewStream(Reader reader,
boolean isInternalEntity)
{
StackedReader oldReader = this.currentReader;
this.readers.push(this.currentReader);
this.currentReader = new StackedReader();
if (isInternalEntity) {
this.currentReader.lineReader = null;
this.currentReader.pbReader = new PushbackReader(reader, 2);
} else {
this.currentReader.lineReader = new LineNumberReader(reader);
this.currentReader.pbReader
= new PushbackReader(this.currentReader.lineReader, 2);
}
this.currentReader.systemId = oldReader.systemId;
this.currentReader.publicId = oldReader.publicId;
}
示例12: main
import java.io.PushbackReader; //導入依賴的package包/類
public static void main(String[] args) {
for (String filename : args)
{
File file = new File(filename);
Translation translation = new Translation(filename + ".parse");
try {
Parser p = new Parser(
new Lexer(
new PushbackReader(new FileReader(file), 1024)
)
);
Start tree = p.parse();
tree.apply(translation);
System.out.println(filename + " parsed successfully.");
} catch (ParserException | LexerException | IOException e) {
System.err.println("Error parsing " + filename + ": " +
e.getMessage());
translation.die(e.getMessage());
}
}
}
示例13: readNumber
import java.io.PushbackReader; //導入依賴的package包/類
static private Object readNumber(PushbackReader r, char initch) {
StringBuilder sb = new StringBuilder();
sb.append(initch);
for(; ;)
{
int ch = read1(r);
if(ch == -1 || isWhitespace(ch) || isMacro(ch))
{
unread(r, ch);
break;
}
sb.append((char) ch);
}
String s = sb.toString();
Object n = matchNumber(s);
if(n == null)
throw new NumberFormatException("Invalid number: " + s);
return n;
}
示例14: readUnicodeChar
import java.io.PushbackReader; //導入依賴的package包/類
static private int readUnicodeChar(PushbackReader r, int initch, int base, int length, boolean exact) {
int uc = Character.digit(initch, base);
if(uc == -1)
throw new IllegalArgumentException("Invalid digit: " + (char) initch);
int i = 1;
for(; i < length; ++i)
{
int ch = read1(r);
if(ch == -1 || isWhitespace(ch) || isMacro(ch))
{
unread(r, ch);
break;
}
int d = Character.digit(ch, base);
if(d == -1)
throw new IllegalArgumentException("Invalid digit: " + (char) ch);
uc = uc * base + d;
}
if(i != length && exact)
throw new IllegalArgumentException("Invalid character length: " + i + ", should be: " + length);
return uc;
}
示例15: readTagged
import java.io.PushbackReader; //導入依賴的package包/類
private Object readTagged(PushbackReader reader, Symbol tag, IPersistentMap opts){
Object o = read(reader, true, null, true, opts);
ILookup readers = (ILookup)RT.get(opts, READERS);
IFn dataReader = (IFn)RT.get(readers, tag);
if(dataReader == null)
dataReader = (IFn)RT.get(RT.DEFAULT_DATA_READERS.deref(),tag);
if(dataReader == null){
IFn defaultReader = (IFn)RT.get(opts, DEFAULT);
if(defaultReader != null)
return defaultReader.invoke(tag, o);
else
throw new RuntimeException("No reader function for tag " + tag.toString());
}
else
return dataReader.invoke(o);
}