cdtanidxfile.java
来自「一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。」· Java 代码 · 共 250 行
JAVA
250 行
package jp.co.sjts.gsession.card;
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 java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;
import jp.co.sjts.gsession.tools.*;
/**
* <p>柤帉偺扴摉僀儞僨僢僋僗僼傽僀儖
*
* @author Ei Kishida <ei@sjts.co.jp>
* @author Hideyuki Kitade <kitade@sjts.co.jp>
*/
public class CDtanidxFile extends GSTextFile{
/** 僼傽僀儖柤 */
private String Fname;
/** 扴摉僨乕僞儕僗僩 */
private List IdxList = null;
/** 僼傽僀儖僷僗 */
private String path = null;
/** 僼傽僀儖 */
private File file=null;
/** 扴摉僨乕僞 */
private CDtanidxData data=null;
/**
* <p>弶婜壔媦傃僷儔儊乕僞僙僢僩
*
* @param HomeDir 僨乕僞僨傿儗僋僩儕
* @param Fname 僼傽僀儖柤
*/
public CDtanidxFile(String HomeDir,String Fname) throws GSException{
init();
this.Fname = Fname;
String filePath = HomeDir + file.separator ;
SetPath(filePath);
// 僨傿儗僋僩儕偺桳岠惈傪僠僃僢僋
try{
File file1 = new File(filePath);
if(!file1.exists()) // 僼傽僀儖偑懚嵼偡傞偐
{
if(!file1.mkdirs()) // 僼傽僀儖偑懚嵼偟側偄応崌偼丄嶌惉傪帋傒傞
throw new GSException("僨傿儗僋僩儕嶌惉偵帋傒偨偑幐攕偟傑偟偨丅");
}
} catch (SecurityException e) {
throw new GSException("傾僋僙僗尃僄儔乕:"+filePath);
}
filePath = filePath + Fname;
this.file = new File(filePath);
if(!file.exists())
{// 僼傽僀儖偑側偄応崌偼丄僨僼僅儖僩抣偱嶌惉
}else{
Load();
}
}
/**
* <p>巜掕偟偨柤帉ID偺僨乕僞傪庢摼偟傑偡丅
*
* @param cid 柤帉ID
* @return 扴摉僨乕僞
*/
public synchronized CDtanidxData Getmod(int cid){
CDtanidxData mod = null;
synchronized(IdxList){
int sizesize = IdxList.size();
if( (cid>=0)&&(cid<IdxList.size()))
mod = (CDtanidxData)IdxList.get(cid);
return mod ;
}
}
/**
* <p>巜掕偟偨柤帉ID偺僨乕僞傪庢摼偟傑偡丅
*
* @param cid 柤帉ID
* @param 僨乕僞
*/
public synchronized CDtanidxData Getrec(String cid){
CDtanidxData mod = null;
synchronized(IdxList){
int cnt = 0 ;
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++){
data = (CDtanidxData)it.next();
if(cid==data.GetCardid()){
cnt = i;
break;
}
}
if( (cnt>=0)&&(cnt<IdxList.size()))
mod = (CDtanidxData)IdxList.get(cnt);
return mod ;
}
}
/**
* <P>弶婜壔傪峴偄傑偡丅
*/
public synchronized void init(){
IdxList = Collections.synchronizedList(new ArrayList());
}
/**
* <p>僷僗傪僙僢僩偟傑偡丅
*
* @param path 僷僗
*/
public synchronized void SetPath(String path){
this.path = path;
}
/**
* <p>僒僀僘庢摼
*
* @return 僒僀僘
*/
public synchronized int size(){
return IdxList.size();
}
/**
* <p>巜掕偟偨柤帉ID偺僨乕僞傪嶍彍偟傑偡丅
*
* @param 柤帉ID
*/
public synchronized void Del(String cid){
synchronized(IdxList){
int cnt = 0 ;
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++){
data = (CDtanidxData)it.next();
if( cid.equals( data.GetCardid())){
cnt = i;
IdxList.remove(cnt);
break;
}
}
}
}
/**
* <p>柤帉扴摉僨乕僞傪捛壛偟傑偡丅
*
* @param mod 柤帉扴摉僨乕僞
*/
public synchronized void Addmod(CDtanidxData mod){
synchronized(IdxList){
IdxList.add(mod);
}
}
/**
* <p>偙偺僆僽僕僃僋僩偺暥帤楍昞尰傪曉偟傑偡丅
*
* @param 暥帤楍攝楍
*/
public synchronized String[] toModsString(){
synchronized(IdxList){
Iterator it=IdxList.iterator();
String[] mods=new String[IdxList.size()];
for(int i=0;i<IdxList.size();i++){
CDtanidxData mod = (CDtanidxData)it.next();
mods[i] = mod.GetCardid();
}
return mods;
}
}
/**
* <p>扴摉儕僗僩傪曉偟傑偡丅
*
* @return 扴摉儕僗僩
*/
public synchronized List GetIdxList(){
synchronized(IdxList){
return IdxList;
}
}
/**
* <p>僼傽僀儖僆僽僕僃僋僩傪曉偟傑偡丅
*
* @return 僼傽僀儖僆僽僕僃僋僩
*/
public synchronized File GetFile(){
return file;
}
/**
* <p>僼傽僀儖偵儔僀僩偟傑偡丅
* <p>偙偺Write儊僜僢僪傪捈愙巊梡偡傞偙偲偼偁傝傑偣傫丅Save儊僜僢僪偐傜屇傃弌偝傟傑偡丅
* <BR>僥儞僾儗乕僩儊僜僢僪僷僞乕儞
*
* @param pw PrintWriter僆僽僕僃僋僩
*/
public synchronized void Write(PrintWriter pw) throws GSException{
String[] buf = toModsString();
for(int i=0;i<buf.length;i++){
pw.println(buf[i]);
}
pw.flush();
pw.close();
}
/**
* <p>僨乕僞傪撉傒崬傒傑偡丅
* <p>偙偺Read儊僜僢僪傪捈愙巊梡偡傞偙偲偼偁傝傑偣傫丅Load儊僜僢僪偐傜屇傃弌偝傟傑偡丅
* <BR>僥儞僾儗乕僩儊僜僢僪僷僞乕儞
*
* @param bf 僶僢僼傽乕儕乕僟乕
*/
public synchronized 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 cardid = st.nextToken();
Addmod(new CDtanidxData(cardid));
}
bf.close();
}catch(IOException e){
throw new GSException("index僼傽僀儖偺撉崬傒偵幐攕");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?