一、Directory的分类
Directory分为两种类型:一种是内存目录,一种是文件目录。
1、内存目录即RAMDirectory
2、文件目录即FSDirectory
FSDirectory又分为3类:
1)windows下的SimpleFSDirectory
2)linux支持NIO的NIOFSDirectory
3)还有一个是内存Map目录MMapDirectory
SimpleFSDirectory是一个FSDirectory的简单实现,对并发处理能力有限,使用MMapDirectory会更好些。
NIOFSDirectory是用与在Linux下的目录,可以提供很好的性能,
二、继承Directory的工具
除此之外Directory还有两个工具类。
1、一个是用于可以同时在两个不同的目录中读取文件的FileSwitchDirectory,这是个代理类。
2、另一是用户读取复合文件的CompoundFileReader,只能读取扩展名为cfs的文件。(写扩展名为cfs的文件用CompoundFileWriter)CompoundFileReader仅在SegmentReader中被引用。
三、Directory与读写对象的对应关系
Directory是个抽象类,定义了获取读写对象的方法createOutput()和openInput()。
FSDirectory是个抽象类,每个继承了FSDirectory的类都实现了自己的createOutput()和openInput()方法,返回符合每个不同类型Directory的IndexInput和IndexOutput。
openInput()返回的对象:
Directory -->RAMDirectory ===> IndexInput --> RAMInputStream
Directory -->FSDirectory -->SimpleFSDirectory ===>IndexInput -->BufferedIndexInput-->SimpleFSIndexInput
Directory -->FSDirectory -->NIOFSDirectory ===>IndexInput -->BufferedIndexInput-->NIOFSIndexInput
Directory -->FSDirectory -->MMapDirectory ===>IndexInput -->BufferedIndexInput-->MMapIndexInput/MultiMMapIndexInput
Directory -->FileSwitchDirectory =====> IndexInput --> 用于交叉读取的上述类型的对应的IndexInput
Directory -->CompoundFileReader =====> IndexInput --> BufferedIndexInput --> CSIndexInput
createOutput()返回的对象:
Directory -->RAMDirectory ===> IndexInput --> RAMOutputStream
Directory -->FSDirectory -->SimpleFSDirectory ===>IndexOutput -->BufferedIndexOutput-->SimpleFSIndexOutput
Directory -->FSDirectory -->NIOFSDirectory ===>IndexOutput -->BufferedIndexOutput-->SimpleFSDirectory.SimpleFSIndexOutput
Directory -->FSDirectory -->MMapDirectory ===>IndexOutput -->BufferedIndexOutput-->SimpleFSDirectory.SimpleFSIndexOutput
Directory -->FileSwitchDirectory =====> IndexInput --> 用于交叉读取的上述类型的对应的IndexInput
Directory -->CompoundFileWriter =====> CompoundFileWriter没有继承IndexOutput是因为CompoundFileWriter使用add(String File)进行增加,而不是writeBytes()