if ( isNonWSCharOccurred == false ) {
                                    continue;
                                }
                                bufferPosition --;
                                inputStream.reset ();
                                inputStream.skip ( bufferPosition );

                                Double res = new Double ( ( ( Double ) Double.valueOf ( sb.toString () ) ).doubleValue () );
                                if ( res!= null ) {
                                    return res.doubleValue ();
                                }
                                else {
                                    throw new Exception ( "readNumber: String is not number" );
                                }
                            }
                            case -1: {
                                Double res = new Double ( ( ( Double ) Double.valueOf ( sb.toString () ) ).doubleValue () );
                                if ( res!= null ) {
                                    return res.doubleValue ();
                                }
                                else {
                                    throw new Exception ( "readNumber: String is not number" );
                                }

                            }
                            default:
                                sb.append ( ( char ) k );
                                isNonWSCharOccurred = true;
                                break;
                        }
                    }
                }
                case ACCESS_MODE_READ_PLUS:
                case ACCESS_MODE_WRITE_PLUS:
                case ACCESS_MODE_APPEND_PLUS: {
                    lastOp = OP_READ;
                    StringBuffer buf = new StringBuffer ();
                    int k = 0;
                    boolean isNonWSCharOccurred = false;
                    for (;;) {
                        k = buffer.charAt ( bufferPosition ++ );
                        switch ( k ) {
                            case'':
                            case '\n':
                            case '\t': {
                                if ( isNonWSCharOccurred == false ) {
                                    continue;
                                }
                                bufferPosition --;

                                Double res = new Double ( ( ( Double ) Double.valueOf ( buf.toString () ) ).doubleValue () );
                                if ( res!= null ) {
                                    return res.doubleValue ();
                                }
                                else {
                                    throw new Exception ( "readNumber: String is not number" );
                                }
                            }
                            case -1: {
                                Double res = new Double ( ( ( Double ) Double.valueOf ( buf.toString () ) ).doubleValue () );
                                if ( res!= null ) {
                                    return res.doubleValue ();
                                }
                                else {
                                    throw new Exception ( "readNumber: String is not number" );
                                }

                            }
                            default:
                                buf.append ( ( char ) k );
                                isNonWSCharOccurred = true;
                                break;
                        }
                    }
                }
            }
            return -1;
        }

        public StringBuffer fgets ( StringBuffer str, int num ) {
            if ( bothRWMode && lastOp == OP_WRITE ) {
                return null;
            }
            try {
                switch ( accessMode ) {
                    case ACCESS_MODE_WRITE:
                    case ACCESS_MODE_APPEND: {
                        return null;
                    }
                    case ACCESS_MODE_READ: {
                        lastOp = OP_READ;
                        if ( inputStream == null )
                            inputStream = connection.openInputStream ();
                        if ( inputStream == null )
                            return null;

                        int k = 0;
                        for ( int i = 0; i < num; i ++ ) {
                            k = inputStream.read ();
                            if ( k == -1 ) {
                                return null;
                            }
                            str.append ( ( char ) k );
                            bufferPosition ++;
                            if ( ( ( char ) k ) == '\n' )
                                return str;
                        }
                        return str;
                    }
                    case ACCESS_MODE_READ_PLUS:
                    case ACCESS_MODE_WRITE_PLUS:
                    case ACCESS_MODE_APPEND_PLUS: {
                        lastOp = OP_READ;
                        for ( int i = 0; i < num; i ++ ) {
                            if ( bufferPosition >= buffer.length () ) {
                                if ( i == 0 )
                                    return null;
                                else
                                    return str;
                            }
                            else {
                                str.append ( buffer.charAt ( bufferPosition ) );
                                if ( buffer.charAt ( bufferPosition ++ ) == '\n' )
                                    return str;

                            }
                        }
                        return str;
                    }
                }
                return null;
            }
            catch ( Exception ex ) {
                return null;
            }
        }

        public int ftell () {
            return bufferPosition;
        }

        public int fseek ( long offset, int origin ) throws Exception {
            fflush ();
            switch ( origin ) {
                case SEEK_SET:
                     {
                        if ( offset < 0 )
                            return 1;
                        switch ( accessMode ) {
                            case ACCESS_MODE_READ: {
                                if ( connection == null )
                                    return 1;
                                if ( inputStream == null )
                                    inputStream = connection.openInputStream ();
                                if ( inputStream == null )
                                    return 1;
                                inputStream.reset ();
                                inputStream.skip ( offset );
                                bufferPosition = ( int ) ( offset );
                                return 0;
                            }
                            case ACCESS_MODE_WRITE:
                            case ACCESS_MODE_APPEND:
                            case ACCESS_MODE_READ_PLUS:
                            case ACCESS_MODE_WRITE_PLUS:
                            case ACCESS_MODE_APPEND_PLUS: {
                                bufferPosition = ( int ) ( offset );
                                return 0;
                            }
                        }
                    }
                    break;
                case SEEK_CUR:
                     {
                        switch ( accessMode ) {
                            case ACCESS_MODE_READ: {
                                if ( connection == null )
                                    return 1;
                                if ( inputStream == null )
                                    inputStream = connection.openInputStream ();
                                if ( inputStream == null )
                                    return 1;

                                bufferPosition += ( int ) ( offset );
                                if ( bufferPosition < 0 )
                                    bufferPosition = 0;
                                if ( offset > 0 ) {
                                    inputStream.skip ( offset );
                                    return 0;
                                }
                                else {
                                    inputStream.reset ();
                                    inputStream.skip ( bufferPosition );
                                    return 0;
                                }
                            }
                            case ACCESS_MODE_WRITE:
                            case ACCESS_MODE_APPEND:
                            case ACCESS_MODE_READ_PLUS:
                            case ACCESS_MODE_WRITE_PLUS:
                            case ACCESS_MODE_APPEND_PLUS: {
                                bufferPosition += ( int ) ( offset );
                                if ( bufferPosition < 0 )
                                    bufferPosition = 0;
                                return 0;
                            }
                        }
                    }
                    break;
                case SEEK_END:
                     {
                        if ( offset < 0 )
                            return 1;

                        switch ( accessMode ) {
                            case ACCESS_MODE_READ: {
                                if ( connection == null )
                                    return 1;
                                if ( inputStream == null )
                                    inputStream = connection.openInputStream ();
                                if ( inputStream == null )
                                    return 1;

                                int fileSize = 0;
                                byte c;
                                int j = 0;
                                inputStream.reset ();
                                while ( ( j = inputStream.read () )!= -1 ) {
                                    fileSize ++;
                                }
                                inputStream.reset ();

                                bufferPosition = fileSize - ( int ) offset;
                                if ( bufferPosition < 0 )
                                    bufferPosition = 0;
                                inputStream.skip ( bufferPosition );
                                return 0;
                            }
                            case ACCESS_MODE_WRITE:
                            case ACCESS_MODE_APPEND:
                            case ACCESS_MODE_READ_PLUS:
                            case ACCESS_MODE_WRITE_PLUS:
                            case ACCESS_MODE_APPEND_PLUS: {
                                int fileSize = buffer.length ();
                                bufferPosition = fileSize - ( int ) offset;
                                if ( bufferPosition < 0 )
                                    bufferPosition = 0;
                                return 0;
                            }
                        }
                    }
                    break;
            }
            return 1;
        }

        public int fflush () throws Exception {
            lastOp = OP_NONE;
            switch ( accessMode