📄 blindexfile.java
字号:
package jp.co.sjts.gsession.bulletin;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import jp.co.sjts.gsession.tools.*;
/**
* <p>宖帵斅僨乕僞偺僀儞僨僢僋僗僼傽僀儖
*
* @author Masakatu O <ookubo@sjts.co.jp>
*/
public class BLIndexFile extends GSTextFile{
/** 僼傽僀儖柤 */
public final static String FILENAME = "index";
/** 棙梡儌僕儏乕儖 */
private List IdxList = null;
/** 僼傽僀儖僷僗 */
private String path = null;
/** */
private File wkfile;
/** */
private BLIndexData data=null;
/** 僼傽僀儖 */
private File file;
/**
* <p>
*
* @param BulletinDir
* @param GrpDir
*/
public BLIndexFile(String BulletinDir,String GrpDir) throws GSException{
init();
String filePath = BulletinDir + "group" + File.separator + GrpDir + File.separator ;
path = filePath;
File file1 = new File(filePath);
if(!file1.exists()) // 僼傽僀儖偑懚嵼偡傞偐
file1.mkdirs(); // 僼傽僀儖偑懚嵼偟側偄応崌偼丄嶌惉傪帋傒傞
filePath = filePath + FILENAME;
this.file = new File(filePath);
if(file.exists()) {
Load();
}
}
/**
* <p>
*
* @param BulletinDir
* @param GrpDir
*/
public synchronized void Path(String BulletinDir,String GrpDir) throws GSException{
init();
String filePath = BulletinDir + "group" + File.separator + GrpDir + File.separator ;
path = filePath;
File file1 = new File(filePath);
if(!file1.exists()){ // 僨傿儗僋僩儕偑懚嵼偡傞偐
file1.mkdirs(); // 僨傿儗僋僩儕偑懚嵼偟側偄応崌偼丄嶌惉傪帋傒傞
}
filePath = filePath + FILENAME;
this.file = new File(filePath);
if(file.exists()) {
Load();
}
}
/**
* <p>僼傽僀儖僆僽僕僃僋僩傪庢摼偟傑偡丅
*
* @return 僼傽僀儖僆僽僕僃僋僩
*/
protected File GetFile(){
return file;
}
/**
* <p>僼傽僀儖偵儔僀僩偟傑偡丅
* <p>偙偺Write儊僜僢僪傪捈愙巊梡偡傞偙偲偼偁傝傑偣傫丅Save儊僜僢僪偐傜屇傃弌偝傟傑偡丅
* <BR>僥儞僾儗乕僩儊僜僢僪僷僞乕儞
*
* @param pw PrintWriter僆僽僕僃僋僩
*/
synchronized protected void Write(PrintWriter pw) throws GSException{
String[] buf = toModsString();
for(int i=0;i<buf.length;i++) {
pw.println(buf[i]);
}
}
/**
* <p>僨乕僞傪撉傒崬傒傑偡丅
* <p>偙偺Read儊僜僢僪傪捈愙巊梡偡傞偙偲偼偁傝傑偣傫丅Load儊僜僢僪偐傜屇傃弌偝傟傑偡丅
* <BR>僥儞僾儗乕僩儊僜僢僪僷僞乕儞
*
* @param bf 僶僢僼傽乕儕乕僟乕
*/
synchronized protected void Read(BufferedReader bf) throws GSException{
init();
try{
String buf;
for(buf=bf.readLine();buf!=null;buf=bf.readLine()) {
StringTokenizer st = new StringTokenizer(buf,",");
String bullid = st.nextToken();
String level = st.nextToken();
String pbullid = st.nextToken();
String limit = st.nextToken();
Addmod(new BLIndexData(bullid,level,pbullid,limit));
}
}catch(IOException e){
throw new GSException("俬俶俢俤倃僼傽僀儖偺撉崬傒偵幐攕");
}
}
/**
* <p>弶婜壔
*/
public synchronized void init(){
IdxList = Collections.synchronizedList(new ArrayList());
}
/**
* <p>僒僀僘庢摼
*/
public synchronized int size(){
return IdxList.size();
}
/**
* <p>嶍彍
*/
public synchronized void Delbullid(String bid){
synchronized(IdxList){
int cnt = 0 ;
int[] tbl = new int[IdxList.size()];
String level = null;
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++) {
data = (BLIndexData)it.next();
if( cnt == 0 ) {
if( bid.equals( data.GetBullid()) ) {
tbl[cnt++] = i ;
level = data.GetLevel() ;
}
}else{
if( Integer.parseInt(level) < Integer.parseInt(data.GetLevel()) ) {
tbl[cnt++] = i ;
}else{
break;
}
}
}
if(cnt != 0) {
String fpath = null ;
for(int i=cnt;i>0;i--) {
data = Getmod(tbl[i-1]);
fpath = path + data.GetBullid();
this.wkfile = new File( fpath );
if(wkfile.exists()) {
wkfile.delete();
}
fpath = fpath + "b";
this.wkfile = new File( fpath );
if(wkfile.exists()) {
wkfile.delete();
}
//偙偺僞僀儈儞僌偱柧嵶僨乕僞傕嶍彍偡傞
IdxList.remove(tbl[i-1]);
}
}
}
}
/**
* <p>擔晅僠僃僢僋
*/
public synchronized void DateChk(String bid){
GSDate cal = new GSDate();
long chkdate = Long.parseLong( cal.getstrYear() + cal.getstrMonth() + cal.getstrDate() + cal.getstrHour() + cal.getstrMinute() + cal.getstrSecond() );
synchronized(IdxList){
int cnt = 0 ;
int[] tbl = new int[IdxList.size()];
String level = null;
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++) {
data = (BLIndexData)it.next();
if( Long.parseLong(data.GetLimit()) != -1 )
if( Long.parseLong(data.GetLimit()) < chkdate )
tbl[cnt++] = i ;
}
if(cnt != 0) {
String fpath = null ;
for(int i=cnt;i>0;i--) {
data = Getmod(tbl[i-1]);
fpath = path + data.GetBullid();
this.wkfile = new File( fpath );
if(wkfile.exists())
wkfile.delete();
IdxList.remove(tbl[i-1]);
}
}
}
}
/**
* <p>捛壛
*/
public synchronized void Addmod(BLIndexData mod){
synchronized(IdxList){
IdxList.add(mod);
}
}
/**
* <p>捛壛
*/
public synchronized void Addmod(int bullid,BLIndexData mod){
synchronized(IdxList){
IdxList.add(bullid,mod);
}
}
/**
* <p>捛壛
*/
public synchronized void Addmod(String bid,BLIndexData mod){
synchronized(IdxList){
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++) {
BLIndexData mod1 = (BLIndexData)it.next();
if( bid.equals( mod1.GetBullid()) ) {
IdxList.add(i+1,mod);
break;
}
}
}
}
/**
* <p>峏怴
*/
public synchronized BLIndexData Getmod(int bullid){
BLIndexData mod = null;
synchronized(IdxList){
if( (bullid>=0)&&(bullid<IdxList.size()))
mod = (BLIndexData)IdxList.get(bullid);
return mod ;
}
}
/**
* <p>偙偺僆僽僕僃僋僩傪String攝楍宆偱曉偟傑偡丅
*/
public synchronized String[] toModsString(){
synchronized(IdxList){
Iterator it=IdxList.iterator();
String[] mods=new String[IdxList.size()];
for(int i=0;i<IdxList.size();i++) {
BLIndexData mod = (BLIndexData)it.next();
mods[i] = mod.GetBullid() + "," + mod.GetLevel() + "," + mod.GetPbullid() + "," + mod.GetLimit();
}
return mods;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -