FileDocCategorySizeDatePackage
ACLFileReader.javaAPI DocphoneME MR2 API (J2ME)5858Wed May 02 18:00:38 BST 2007com.sun.satsa.acl

ACLFileReader

public class ACLFileReader extends Object
This class represents file reader for file that describes access control information.

Fields Summary
Reader
in
Input data reader.
char[]
lineBuffer
Temporary data array.
protected static final int
HT
Horizontal Tab - Unicode character 0x09.
protected static final int
LF
Line Feed - Unicode character 0x0A.
protected static final int
CR
Carrage Return - Unicode character 0x0D.
protected static final int
EOF
End Of File - Unicode character 0x1A.
protected static final int
SP
SPace - Unicode character 0x20.
protected int
lineNumber
Current line number.
protected char
savedChar
Temporary variable used in parsing.
Constructors Summary
public ACLFileReader(Reader r)
Constructor.

param
r input data reader.


        lineBuffer = new char[128];
        in = r;
    
Methods Summary
public voidcheckWord(java.lang.String s)
Check that the next word is equal to specified one.

param
s the word value.
throws
IOException if I/O error occurs.


        if (! readWord().equals(s)) {
            throw new IOException();
        }
    
public intgetLineNumber()
Returns the current line number.

return
the current line number.

        return lineNumber;
    
public intreadByte()
Reads one word, converts it into unsigned byte value.

return
unsigned byte value.
throws
IOException if I/O error occurs.

        return Integer.parseInt(readWord(), 16) & 0xff;
    
public java.lang.StringreadLine()
Read current line without any modification.

return
the current line value.
throws
IOException if I/O error occurs.


        int room;
        int offset = 0;
        int c;
        char[] temp;

        room = lineBuffer.length;

        for (;;) {
            c = in.read();

            if (c == LF) {
                lineNumber++;
            }

            if (c == -1 || c == LF) {
                // LF or CR LF ends a line
                break;
            }

            /*
            * throw away carrage returns and the end of file character.
            */
            if (c == CR || c == EOF) {
                continue;
            }

            if (--room < 0) {
                temp = new char[offset + 128];
                room = temp.length - offset - 1;
                System.arraycopy(lineBuffer, 0, temp, 0, offset);
                lineBuffer = temp;
            }

            lineBuffer[offset++] = (char) c;
        }

        if ((c == -1) && (offset <= 0)) {
            return null;
        }

        return new String(lineBuffer, 0, offset).trim();
    
public java.lang.StringreadWord()
Read one word.

return
the word.
throws
IOException if I/O error occurs.


                     
         


        if (savedChar == '{") {
            savedChar = 0;
            return "{";
        }

        if (savedChar == '}") {
            savedChar = 0;
            return "}";
        }

        int room = lineBuffer.length;
        int offset = 0;
        boolean comment = false;
        int c;

        for (;;) {
            c = in.read();
            if (c == -1) {
                // LF or CR LF ends a line
                break;
            }

            if (c == '#") {
                comment = true;
            }

            if (c == LF) {
                lineNumber++;
                comment = false;
            }

            if (comment) {
                continue;
            }

            if (c == LF || c == CR || c == EOF || c == HT || c == SP) {
                if (offset == 0) {
                    continue;
                }
                break;
            }

            if (c == '{" || c == '}") {
                if (offset == 0) {
                    lineBuffer[offset++] = (char) c;
                } else {
                    savedChar = (char) c;
                }
                break;
            }

            if (--room < 0) {
                char[] temp = new char[offset + 128];
                room = temp.length - offset - 1;
                System.arraycopy(lineBuffer, 0, temp, 0, offset);
                lineBuffer = temp;
            }

            lineBuffer[offset++] = (char) c;
        }

        if ((c == -1) && (offset <= 0)) {
            return null;
        }

        return new String(lineBuffer, 0, offset).trim();