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

📄 jeindexoutput.java

📁 lucene2.2.0版本
💻 JAVA
字号:
package org.apache.lucene.store.je;/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import java.io.IOException;import org.apache.lucene.store.IndexOutput;/** * Port of Andi Vajda's DbDirectory to Java Edition of Berkeley Database *  * @author Aaron Donovan */public class JEIndexOutput extends IndexOutput {    /**     * The size of data blocks, currently 16k (2^14), is determined by this     * constant.     */    static public final int BLOCK_SHIFT = 14;    static public final int BLOCK_LEN = 1 << BLOCK_SHIFT;    static public final int BLOCK_MASK = BLOCK_LEN - 1;    protected long position = 0L, length = 0L;    protected JEDirectory directory;    protected Block block;    protected File file;    protected JEIndexOutput(JEDirectory directory, String name, boolean create)            throws IOException {        super();        this.directory = directory;        file = new File(directory, name, create);        block = new Block(file);        length = file.getLength();        seek(length);        block.get(directory);        directory.openFiles.add(this);    }    public void close() throws IOException {        flush();        file.modify(directory, length, System.currentTimeMillis());        directory.openFiles.remove(this);    }    public void flush() throws IOException {        if (length > 0)            block.put(directory);    }    public void writeByte(byte b) throws IOException {        int blockPos = (int) (position++ & BLOCK_MASK);        block.getData()[blockPos] = b;        if (blockPos + 1 == BLOCK_LEN) {            block.put(directory);            block.seek(position);            block.get(directory);        }        if (position > length)            length = position;    }    public void writeBytes(byte[] b, int offset, int len) throws IOException {        int blockPos = (int) (position & BLOCK_MASK);        while (blockPos + len >= BLOCK_LEN) {            int blockLen = BLOCK_LEN - blockPos;            System.arraycopy(b, offset, block.getData(), blockPos, blockLen);            block.put(directory);            len -= blockLen;            offset += blockLen;            position += blockLen;            block.seek(position);            block.get(directory);            blockPos = 0;        }        if (len > 0) {            System.arraycopy(b, offset, block.getData(), blockPos, len);            position += len;        }        if (position > length)            length = position;    }    public long length() throws IOException {        return length;    }    public void seek(long pos) throws IOException {        if (pos > length)            throw new IOException("seeking past end of file");        if ((pos >>> BLOCK_SHIFT) == (position >>> BLOCK_SHIFT))            position = pos;        else {            block.put(directory);            block.seek(pos);            block.get(directory);            position = pos;        }    }    public long getFilePointer() {        return position;    }}

⌨️ 快捷键说明

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