cdemployfile.java
来自「一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。」· Java 代码 · 共 242 行
JAVA
242 行
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>Card 偺嬈庬
*
* @author Ei KISHIDA <ei@sjts.co.jp>
* @author Hideyuki KITADE <kitade@sjts.co.jp>
*/
public class CDEmployFile extends GSTextFile{
/** 嬈庬奿擺儕僗僩 */
private List IdxList = null;
/** 僷僗 */
private String path = null;
/** 僼傽僀儖 */
private File file=null;
/** 嬈庬僨乕僞 */
private CDEmployData data=null;
/** 僼傽僀儖柤 */
public final static String FILENAME = "employ";
/**
* <p>弶婜壔媦傃僷儔儊乕僞僙僢僩
*
* @param HomeDir
*/
public CDEmployFile(String HomeDir) throws GSException{
init();
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 + FILENAME;
this.file = new File(filePath);
if(!file.exists())
{// 僼傽僀儖偑側偄応崌偼丄僨僼僅儖僩抣偱嶌惉
Save();
}else{
Load();
}
}
/**
* <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 eid 嬈庬ID
*/
public synchronized void Del(String eid){
synchronized(IdxList){
int cnt = 0 ;
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++){
data = (CDEmployData)it.next();
if( eid.equals( data.GetEmployid()) ){
cnt = i;
IdxList.remove(cnt);
break;
}
}
// IdxList.remove(cnt);
}
}
/**
* <p>嬈庬傪捛壛偟傑偡丅
*
* @param mod 嬈庬僨乕僞
*/
public synchronized void Addmod(CDEmployData mod){
synchronized(IdxList){
IdxList.add(mod);
}
}
/**
* <p>巜掕偟偨嬈庬ID偺僨乕僞傪庢摼偟傑偡丅
*
* @param eid 嬈庬ID
*/
public synchronized CDEmployData Getmod(int eid){
CDEmployData mod = null;
synchronized(IdxList){
int sizesize = IdxList.size();
if( (eid>=0)&&(eid<IdxList.size()))
mod = (CDEmployData)IdxList.get(eid);
return mod ;
}
}
/**
* <p>巜掕偟偨嬈庬ID偺僨乕僞傪庢摼偟傑偡丅
*
* @param eid 嬈庬ID
*/
public synchronized CDEmployData Getrec(String eid){
CDEmployData mod = null;
synchronized(IdxList){
int cnt = -1 ;
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++){
data = (CDEmployData)it.next();
if( eid.equals( data.GetEmployid()) )
{
cnt = i;
break;
}
}
if( (cnt>=0)&&(cnt<IdxList.size()))
mod = (CDEmployData)IdxList.get(cnt);
return mod ;
}
}
/**
* <p>偙偺僆僽僕僃僋僩偺CSV宍幃偵曄姺偟偨暥帤楍傪攝楍偱曉偟傑偡丅
*
* @return CSV宍幃偺僨乕僞
*/
public synchronized String[] toModsString(){
synchronized(IdxList){
Iterator it=IdxList.iterator();
String[] mods=new String[IdxList.size()];
for(int i=0;i<IdxList.size();i++){
CDEmployData mod = (CDEmployData)it.next();
mods[i] = mod.GetEmployid() + "," + mod.GetEmployname();
}
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]);
}
}
/**
* <p>僨乕僞傪撉傒崬傒傑偡丅
* <p>偙偺Read儊僜僢僪傪捈愙巊梡偡傞偙偲偼偁傝傑偣傫丅Load儊僜僢僪偐傜屇傃弌偝傟傑偡丅
* <BR>僥儞僾儗乕僩儊僜僢僪僷僞乕儞
*
* @param bf 僶僢僼傽乕儕乕僟乕
*/
public synchronized void Read(BufferedReader bf) throws GSException{
String buf;
init();
try{
for(buf=bf.readLine();buf!=null;buf=bf.readLine()){
StringTokenizer st = new StringTokenizer(buf,",");
String employid = st.nextToken();
String employname = st.nextToken();
Addmod(new CDEmployData(employid,employname));
}
}catch(IOException e){
throw new GSException();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?