📄 defaultsavorandloader.java
字号:
package invertedList;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
import java.util.Set;
/**
* @author Administrator
* an default implementation of AbstractSavorAndLoader
*/
public class DefaultSavorAndLoader extends AbstractSavorAndLoader {
public DefaultSavorAndLoader(Map<String,Set<String>> allInvertedList,Set<File> fileList){
this.allInvertedList = allInvertedList;
this.fileList = fileList;
}
/* (non-Javadoc)
* @see invertedList.AbstractSavorAndLoader#loadInvertedList(java.lang.String)
*/
/**
* @see invertedList.AbstractSavorAndLoader#saveInvertedList(java.lang.String)
* extend from AbstractSavorAndLoader
*/
@SuppressWarnings("unchecked")
@Override
protected void loadInvertedList(String dir) {
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File(dir + "/AllIndex.xbq")));
allInvertedList = (Map<String,Set<String>>)ois.readObject();
ois.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Loading Failed. File can not be found.");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Loading Failed. File can not be read.");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see invertedList.AbstractSavorAndLoader#saveInvertedList(java.lang.String)
*/
/**
* @see invertedList.AbstractSavorAndLoader#saveInvertedList(java.lang.String)
* extend from AbstractSavorAndLoader
*/
@Override
protected void saveInvertedList(String dir) {
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(dir + "/AllIndex.xbq")));
oos.writeObject(allInvertedList);
oos.flush();
oos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Saving Failed, the all index file can not be created.");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Saving Failed, the all index file can not be written.");
}
}
/*
private void saveFileList(String dir){
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(dir + "/fileIndex.xbq")));
oos.writeObject(fileList);
oos.flush();
oos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("Saving Failed, file can not be created.");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Saving Failed, file can not be written.");
}
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -