当前位置: 首页>>代码示例>>Java>>正文


Java PushbackReader类代码示例

本文整理汇总了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());
}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:21,代码来源:LispReader.java

示例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);
		}
}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:22,代码来源:EdnReader.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:DTDParser.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DTDParser.java

示例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());
}
 
开发者ID:ragnard,项目名称:shen-truffle,代码行数:20,代码来源:Reader.java

示例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;
}
 
开发者ID:mtommila,项目名称:apfloat,代码行数:29,代码来源:ApfloatHelper.java

示例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);
    }
}
 
开发者ID:mtommila,项目名称:apfloat,代码行数:23,代码来源:ApfloatHelper.java

示例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();
}
 
开发者ID:mtommila,项目名称:apfloat,代码行数:34,代码来源:Aprational.java

示例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());
}
 
开发者ID:mtommila,项目名称:apfloat,代码行数:27,代码来源:RawtypeApfloatImpl.java

示例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
   }
}
 
开发者ID:the-im,项目名称:enhanced-vnc-thumbnail-viewer,代码行数:21,代码来源:StdXMLReader.java

示例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;
}
 
开发者ID:the-im,项目名称:enhanced-vnc-thumbnail-viewer,代码行数:29,代码来源:StdXMLReader.java

示例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());
        }
    }
}
 
开发者ID:dittma75,项目名称:compiler-design,代码行数:22,代码来源:Compiler.java

示例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;
}
 
开发者ID:mrange,项目名称:fsharpadvent2016,代码行数:22,代码来源:EdnReader.java

示例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;
}
 
开发者ID:mrange,项目名称:fsharpadvent2016,代码行数:23,代码来源:EdnReader.java

示例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);
}
 
开发者ID:skejserjensen,项目名称:eclojure,代码行数:18,代码来源:EdnReader.java


注:本文中的java.io.PushbackReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。