channelmanager.java
来自「支持并发访问的B+树」· Java 代码 · 共 71 行
JAVA
71 行
/* * Created on Nov 19, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */package com.nay0648.ds.bplustree;import java.io.*;import java.nio.channels.*;/** * * @author nay0648 * * this is used to manage file channle.all file operation to the B+ tree * get the file channel by this class */class ChannelManager{private static final String FILE_OPEN_MODE="rw";//open tree file in rw modeprivate String path; /** * @param path the tree file path */ public ChannelManager(String path) { this.path=path; } /** * get a new channel of the tree file * @return return null if field */ public FileChannel getChannel() { FileChannel ch=null; try { ch=(new RandomAccessFile(path,FILE_OPEN_MODE)).getChannel(); } catch(IOException exc) { exc.printStackTrace(); } return ch; } /** * recycle a channel * @param ch the channel of the tree file */ public void recycle(Channel ch) { try { if(ch.isOpen()) ch.close(); } catch(IOException exc) { exc.printStackTrace(); } } /* public static void main(String[] args) {} */}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?