⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textcache.java

📁 一个用java写的开源的数据库系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            } while ((next = sep.indexOf('\\', start)) != -1);            realSep.append(sepArray, start, len - start);            sep = realSep.toString();        }        return (sep);    }    /**     *  open method declaration <P>     *     *  The open method creates or opens a database file.     *     * @param  readonly       Description of the Parameter     * @param  ignore1st      Description of the Parameter     * @throws  SQLException     */    void open(boolean readonly) throws SQLException {        try {            rFile    = new DatabaseFile(sName, (readonly) ? "r"                                                          : "rw", 4096);            iFreePos = (int) rFile.length();            if ((iFreePos == 0) && ignoreFirst) {                rFile.write(ignoredFirst.getBytes());                iFreePos = ignoredFirst.length();            }        } catch (Exception e) {            throw Trace.error(Trace.FILE_IO_ERROR,                              "error " + e + " opening " + sName);        }        readOnly = readonly;    }    void reopen() throws SQLException {        open(readOnly);        in.reset();    }    /**     *  flush method declaration <P>     *     *  The flush method saves all cached data to the file, saves the free     *  position and closes the file.     *     * @throws  SQLException     */    void flush() throws SQLException {        if (rFile == null) {            return;        }        try {            rFile.seek(0);            saveAll();            boolean empty = (rFile.length() <= NL.length());            rFile.close();            rFile = null;            if (empty &&!readOnly) {                new File(sName).delete();            }        } catch (Exception e) {            throw Trace.error(Trace.FILE_IO_ERROR,                              "error " + e + " closing " + sName);        }    }    void purge() throws SQLException {        if (rFile == null) {            return;        }        try {            if (readOnly) {                flush();            } else {                rFile.close();                rFile = null;                new File(sName).delete();            }        } catch (Exception e) {            throw Trace.error(Trace.FILE_IO_ERROR,                              "error " + e + " purging " + sName);        }    }    void free(CachedRow r) throws SQLException {        int pos    = r.iPos;        int length = r.storageSize;        //-- Change to blank line:        StringBuffer blank = new StringBuffer(length);        length -= NL.length();        for (int i = 0; i < length; i++) {            blank.append(' ');        }        blank.append(NL);        try {            rFile.seek(pos);            rFile.writeBytes(blank.toString());        } catch (IOException e) {            throw (Trace.error(Trace.FILE_IO_ERROR, e + ""));        }        remove(r);    }    protected void setStorageSize(CachedRow r) throws SQLException {        int size;        try {            out.writeData(r.getData(), r.getTable());            size = out.toByteArray().length;        } catch (IOException e) {            throw (Trace.error(Trace.FILE_IO_ERROR, e + ""));        }        r.storageSize = size;    }    protected CachedRow makeRow(int pos, Table t) throws SQLException {        CachedRow r = null;        try {            StringBuffer buffer   = new StringBuffer(80);            boolean      blank    = true;            boolean      complete = false;            try {                char c;                int  next;                rFile.readSeek(pos);                //-- The following should work for DOS, MAC, and Unix line                //-- separators regardless of host OS.                while (true) {                    next = rFile.read();                    if (next == -1) {                        break;                    }                    c = (char) (next & 0xff);                    //-- Ensure line is complete.                    if (c == '\n') {                        buffer.append('\n');                        //-- Store first line.                        if (ignoreFirst && pos == 0) {                            ignoredFirst = buffer.toString();                            blank        = true;                        }                        //-- Ignore blanks                        if (!blank) {                            complete = true;                            break;                        } else {                            pos += buffer.length();                            buffer.setLength(0);                            blank = true;                            in.skippedLine();                            continue;                        }                    }                    if (c == '\r') {                        //-- Check for newline                        try {                            next = rFile.read();                            if (next == -1) {                                break;                            }                            c = (char) (next & 0xff);                            if (c == '\n') {                                buffer.append('\n');                            }                        } catch (Exception e2) {                            ;                        }                        buffer.append('\n');                        //-- Store first line.                        if (ignoreFirst && pos == 0) {                            ignoredFirst = buffer.toString();                            blank        = true;                        }                        //-- Ignore blanks.                        if (!blank) {                            complete = true;                            break;                        } else {                            pos += buffer.length();                            buffer.setLength(0);                            blank = true;                            in.skippedLine();                            continue;                        }                    }                    if (c != ' ') {                        blank = false;                    }                    buffer.append(c);                }            } catch (Exception e) {                complete = false;            }            if (complete) {                in.setSource(buffer.toString(), pos);                r = new CachedRow(t, in);            }        } catch (Exception e) {            e.printStackTrace();            throw Trace.error(Trace.FILE_IO_ERROR, "reading: " + e);        }        return (r);    }    protected void saveRow(CachedRow r) throws IOException, SQLException {        rFile.seek(r.iPos);        r.write(out);        rFile.write(out.toByteArray());    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -