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


Java PushbackReader.read方法代码示例

本文整理汇总了Java中java.io.PushbackReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java PushbackReader.read方法的具体用法?Java PushbackReader.read怎么用?Java PushbackReader.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.PushbackReader的用法示例。


在下文中一共展示了PushbackReader.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: parseMarkup

import java.io.PushbackReader; //导入方法依赖的package包/类
/** Parser that reads the markup type after <!. Recognizes ENTITY, ELEMENT
 * and ATTLIST markup and forwards their processing to proper parser.
 * It gets the control just after starting "<!" and releases after eating
 * final '>' */
private void parseMarkup( PushbackReader in ) throws IOException, WrongDTDException {
    StringBuffer sb = new StringBuffer();
    for( ;; ) {
        int i = in.read();
        if( i == -1 ) throw new WrongDTDException( "Premature end of DTD" ); // NOI18N EOF
        if( i == ' ' ) break;
        sb.append( (char)i );                 // next char of name
    }
    
    String markup = sb.toString();
    switch (markup) {
        case "ENTITY":
            // NOI18N
            parseEntityDefinition( in );
            break;
        case "ELEMENT":
            // NOI18N
            parseElement( in );
            break;
        case "ATTLIST":
            // NOI18N
            parseAttlist( in );
            break;
        default:
            throw new WrongDTDException( "Wrong DTD markup <!" + markup );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:DTDParser.java

示例7: readLine

import java.io.PushbackReader; //导入方法依赖的package包/类
/** Reads a line and returns the char sequence for newline */
private static String readLine(PushbackReader r, StringBuffer nl) throws IOException {
    StringBuffer line = new StringBuffer();
    int ic = r.read();
    if (ic == -1) return null;
    char c = (char) ic;
    while (c != '\n' && c != '\r') {
        line.append(c);
        ic = r.read();
        if (ic == -1) break;
        c = (char) ic;
    }
    if (nl != null) {
        nl.append(c);
    }
    if (c == '\r') {
        try {
            ic = r.read();
            if (ic != -1) {
                c = (char) ic;
                if (c != '\n') r.unread(c);
                else if (nl != null) nl.append(c);
            }
        } catch (IOException ioex) {}
    }
    return line.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:Patch.java

示例8: compareText

import java.io.PushbackReader; //导入方法依赖的package包/类
private boolean compareText(PushbackReader source, String text) throws IOException {
    if (text == null || text.length() == 0) return true;
    text = adjustTextNL(text);
    char[] chars = new char[text.length()];
    int pos = 0;
    int n;
    String readStr = "";
    do {
        n = source.read(chars, 0, chars.length - pos);
        if (n > 0) {
            pos += n;
            readStr = readStr + new String(chars, 0, n);
        }
        if (readStr.endsWith("\r")) {
            try {
                char c = (char) source.read();
                if (c != '\n') source.unread(c);
                else readStr += c;
            } catch (IOException ioex) {}
        }
        readStr = adjustTextNL(readStr);
        pos = readStr.length();
    } while (n > 0 && pos < chars.length);
    readStr.getChars(0, readStr.length(), chars, 0);
    line += numChars('\n', chars);
    //System.out.println("Comparing text of the diff:\n'"+text+"'\nWith the read text:\n'"+readStr+"'\n");
    //System.out.println("  EQUALS = "+readStr.equals(text));
    return readStr.equals(text);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:Patch.java

示例9: read

import java.io.PushbackReader; //导入方法依赖的package包/类
public static Object read(PushbackReader r, IEOFHandler eofHandler) throws IOException {
    int ch;

    do {
        ch = r.read();
    } while (Character.isWhitespace(ch));

    switch(ch) {
        case -1:  return eofHandler.eof();
        case ')': throw new RuntimeException("unmatched ')'");
        case '(': return readList(r);
        case '"': return readString(r);
        default:  return readToken(r, eofHandler, ch);
    }
}
 
开发者ID:ragnard,项目名称:shen-truffle,代码行数:16,代码来源:Reader.java

示例10: readList

import java.io.PushbackReader; //导入方法依赖的package包/类
private static List readList(PushbackReader r) throws IOException {
    ArrayList list = new ArrayList();

    while(true) {
        int ch = r.read();
        if (ch == -1) throw new EOFException();
        if (ch == ')') break;
        r.unread(ch);
        list.add(read(r, ThrowOnEof));
    }
    return list;
}
 
开发者ID:ragnard,项目名称:shen-truffle,代码行数:13,代码来源:Reader.java

示例11: parse

import java.io.PushbackReader; //导入方法依赖的package包/类
public static Token[] parse(String str) throws IOException, ParseException
{
    Reader reader = new StringReader(str);
    PushbackReader pushbackreader = new PushbackReader(reader);
    List<Token> list = new ArrayList();

    while (true)
    {
        int i = pushbackreader.read();

        if (i < 0)
        {
            Token[] atoken = (Token[])((Token[])list.toArray(new Token[list.size()]));
            return atoken;
        }

        char c0 = (char)i;

        if (!Character.isWhitespace(c0))
        {
            EnumTokenType enumtokentype = EnumTokenType.getTypeByFirstChar(c0);

            if (enumtokentype == null)
            {
                throw new ParseException("Invalid character: \'" + c0 + "\', in: " + str);
            }

            Token token = readToken(c0, enumtokentype, pushbackreader);
            list.add(token);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:33,代码来源:TokenParser.java

示例12: readToken

import java.io.PushbackReader; //导入方法依赖的package包/类
private static Token readToken(char chFirst, EnumTokenType type, PushbackReader pr) throws IOException
{
    StringBuffer stringbuffer = new StringBuffer();
    stringbuffer.append(chFirst);

    while (type.getMaxLen() <= 0 || stringbuffer.length() < type.getMaxLen())
    {
        int i = pr.read();

        if (i < 0)
        {
            break;
        }

        char c0 = (char)i;

        if (!type.hasChar(c0))
        {
            pr.unread(c0);
            break;
        }

        stringbuffer.append(c0);
    }

    return new Token(type, stringbuffer.toString());
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:28,代码来源:TokenParser.java

示例13: parseDTD

import java.io.PushbackReader; //导入方法依赖的package包/类
private void parseDTD( PushbackReader in ) throws IOException, WrongDTDException {
    int state = DTD_INIT;
    for( ;; ) {
        int i = in.read();
        if( i == -1 ) {
            break;
        }
        switch( state ) {
            case DTD_INIT:
                switch( i ) {
                    case '<':
                        state = DTD_LT;
                        break;
                    case '%':
                        parseEntityReference( in );
                        break; // Stay in DTD_INIT
                }
                break;
                
            case DTD_LT:
                if( i != '!' ) throw new WrongDTDException( "Unexpected char '" + (char)i + "' after '<'" ); // NOI18N
                state = DTD_EXC;
                break;
                
            case DTD_EXC:
                switch( i ) {
                    case '-':
                        state = DTD_MINUS;
                        break;
                    case '[':
                        parseOptional( in );
                        state = DTD_INIT;
                        break;
                    default:
                        in.unread( i );
                        parseMarkup( in );
                        state = DTD_INIT;
                        break;
                }
                break;
                
            case DTD_MINUS:
                if( i != '-' ) throw new WrongDTDException( "Unexpected char '" + (char)i + "' after \"<!-\"" ); // NOI18N
                parseComment( in );
                state = DTD_ACOMMENT;
                break;
                
            case DTD_ACOMMENT:
                if( i != '>' ) throw new WrongDTDException( "Unexpected char '" + (char)i + "' after comment" ); // NOI18N
                state = DTD_INIT;
                break;
                
        }
    }        
    if( state != DTD_INIT ) throw new WrongDTDException( "Premature end of DTD" ); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:57,代码来源:DTDParser.java

示例14: parseGroup

import java.io.PushbackReader; //导入方法依赖的package包/类
/** Parse group of names separated by '|' character and optional spaces
 * @return List of Strings containing names */
private List parseGroup( PushbackReader in ) throws IOException, WrongDTDException {
    int state = GR_INIT;
    StringBuffer name = new StringBuffer();
    List list = new ArrayList();
    
    for( ;; ) {
        int i = in.read();
        if( i == -1 ) throw new WrongDTDException( "Premature end of DTD" ); // NOI18N EOF
        switch( state ) {
            case GR_INIT:
                if( Character.isWhitespace( (char)i ) ) break;
                if( i == '%' ) {
                    parseEntityReference( in );
                } else {
                    name.append( (char)i );
                    state = GR_NAME;
                }
                break;
                
            case GR_NAME:
                if( isNameChar( (char)i ) ) {
                    name.append( (char)i );
                    break;
                }
                switch( i ) {
                    case ')':
                        list.add( name.toString() );
                        return list;
                    case '|':
                        list.add( name.toString() );
                        name.setLength( 0 );
                        state = GR_INIT;
                        break;
                    default:
                        if( Character.isWhitespace( (char)i ) ) {
                            list.add( name.toString() );
                            name.setLength( 0 );
                            state = GR_ANAME;
                            break;
                        } else {
                            throw new WrongDTDException( "Unexpected char '" + (char)i + "' in group definition." ); // NOI18N
                        }
                }
                break;
                
            case GR_ANAME:
                if( Character.isWhitespace( (char)i ) ) break;
                switch( i ) {
                    case ')':
                        return list;
                    case '|':
                        state = GR_INIT;
                        break;
                    default:
                        throw new WrongDTDException( "Unexpected char '" + (char)i + "' in group definition." ); // NOI18N
                }
                break;
        }
    }
                
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:64,代码来源:DTDParser.java

示例15: parseOptional

import java.io.PushbackReader; //导入方法依赖的package包/类
/** Parser that takes care of conditional inclusion/exclusion of part
 * of DTD. Gets the control just after "<![" */
private void parseOptional( PushbackReader in ) throws IOException, WrongDTDException {
    int state = OPT_INIT;
    StringBuffer process = new StringBuffer();
    StringBuffer content = new StringBuffer();
    boolean ignore = false;
    
    for( ;; ) {
        int i = in.read();
        if( i == -1 ) break; // EOF
        switch( state ) {
            case OPT_INIT:
                if( Character.isWhitespace( (char)i ) ) break;
                if( i == '%' ) {
                    parseEntityReference( in );
                    break;
                }
                process.append( (char)i );
                state = OPT_PROCESS;
                break;
                
            case OPT_PROCESS:
                if( Character.isWhitespace( (char)i ) ) {
                    String s = process.toString();
                    if( "IGNORE".equals( s ) ) ignore = true; // NOI18N
                    else if( ! "INCLUDE".equals( s ) ) throw new WrongDTDException( "Unexpected processing instruction " + s ); // NOI18N
                    state = OPT_APROCESS;
                } else {
                    process.append( (char)i );
                }
                break;
                
            case OPT_APROCESS:
                if( Character.isWhitespace( (char)i ) ) break;
                if( i == '[' ) state = OPT_CONTENT;
                else throw new WrongDTDException( "Unexpected char '" + (char)i + "' in processing instruction." ); // NOI18N
                break;
                
            case OPT_CONTENT:
                if( i == ']' ) state = OPT_BRAC1;
                else content.append( (char)i );
                break;
                
            case OPT_BRAC1:
                if( i == ']' ) state = OPT_BRAC2;
                else {
                    content.append( ']' ).append( (char)i );
                    state = OPT_CONTENT;
                }
                break;
                
            case OPT_BRAC2:
                if( Character.isWhitespace( (char)i ) ) break;
                if( i == '>' ) {
                    if( !ignore ) in.unread( content.toString().toCharArray() );
                    return;
                }
                throw new WrongDTDException( "Unexpected char '" + (char)i + "' in processing instruction." ); // NOI18N
        }
    }
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:64,代码来源:DTDParser.java


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