tcfile.java
来自「一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。」· Java 代码 · 共 241 行
JAVA
241 行
package jp.co.sjts.gsession.timecard;
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 java.util.NoSuchElementException;
import java.util.TreeSet;
import java.text.Collator;
import jp.co.sjts.gsession.tools.*;
/**
* <P>僞僀儉僇乕僪僼傽僀儖嶌惉(堦儠寧偺僞僀儉僇乕僪僼傽僀儖傪嶌惉偟傑偡丅) TCFile.java
* <P>Copyright (C) 1999-2000 Japan Total System Co,LTD
*
* @author Yuuichirou Ohba <ohba@sjts.co.jp>
*/
public class TCFile extends GSTextFile
{
private List IdxList = null;
private String path = null;
private File file = null;
private DayData[] dayDatas;
private String filePath;
private int hitcnt;
private DayData dayData = null;
/**
* <P>僐儞僗僩儔僋僞
*/
public TCFile(){}
/**
* <P> 堷偔悢晅偒僐儞僗僩儔僋僞
* @param HomeDir 儂乕儉僨傿儗僋僩儕偺僷僗
* @param sid 儐乕僓ID
* @param y 擭
* @param m 寧
* @param day 擔晅
*/
public TCFile(String HomeDir,String sid,int y,int m,String day) throws GSException
{
String fileName = EditTime.getHH(m);/* 僼傽僀儖柤(寧)傪嶌惉*/
filePath = HomeDir + sid + file.separator;
SetPath(filePath);
/* 僨傿儗僋僩儕偺桳岠惈傪僠僃僢僋*/
try{
File dir = new File(filePath);
if(!dir.exists()) { /* 儐乕僓枅偺id僨傿儗僋僩儕偼懚嵼偡傞偐丠*/
if(!dir.mkdirs()) /* 柍偗傟偽嶌惉偡傞*/
throw new GSException("僨傿儗僋僩儕嶌惉偵帋傒偨偑幐攕偟傑偟偨丅");
}
} catch (SecurityException e) {
throw new GSException("傾僋僙僗尃僄儔乕:"+filePath);
}
filePath = filePath + Integer.toString(y) + file.separator;
SetPath(filePath);
try{
File dir = new File(filePath);
if(!dir.exists()) { /* 奺擭僨傿儗僋僩儕偼懚嵼偡傞偐丠*/
if(!dir.mkdirs()) /* 柍偗傟偽嶌惉偡傞*/
throw new GSException("僨傿儗僋僩儕嶌惉偵帋傒偨偑幐攕偟傑偟偨丅");
}
} catch (SecurityException e) {
throw new GSException("傾僋僙僗尃僄儔乕:"+filePath);
}
filePath = filePath + fileName;/* 僼傽僀儖柤偼乮奺寧乯*/
SetPath(filePath);
/* 僼傽僀儖偺桳岠惈傪僠僃僢僋*/
this.file = new File(filePath);
init();
if(!file.exists()){
Save();
}else{
Load();
}
}
/**
* <P> 嬻偺僼僅乕儅僢僩傪嶌惉(弶婜壔)偟傑偡丅
*/
public synchronized void init()
{
IdxList = Collections.synchronizedList(new ArrayList());
for(int i=0;i<32;i++){
AdddayData(new DayData(i,"丂","丂","丂"));
}
}
/**
* <P>僨乕僞奿擺愭偺僷僗傪僙僢僩偟傑偡丅
* @param path 僨乕僞奿擺愭偺僷僗
*/
public synchronized void SetPath(String path) {this.path = path;}
/**
* <P>僼傽僀儖偺僀儞僨僢僋僗僒僀僘傪庢摼偟傑偡丅
* @return 僼傽僀儖偺僀儞僨僢僋僗僒僀僘
*/
public synchronized int size() {return IdxList.size();}
/**
* <P>巜掕擔晅傪庢摼偟傑偡丅柍偄応崌偼嬻偺僼僅乕儅僢僩偑曉傝傑偡丅
* @param day 擔晅
*/
public synchronized DayData DataChk(String day)
{
hitcnt = -1;
synchronized(IdxList){
Iterator it=IdxList.iterator();
for(int i=0;i<IdxList.size();i++)
{
dayData = (DayData)it.next();
if( dayData.getDay() == Integer.parseInt(day) )
{
hitcnt = i;
return dayData ;
}else{
dayData=null;
}
}
return dayData ;
}
}
/**
* <P>僀儞僨僢僋僗儕僗僩偺嵟屻偵侾擔暘偺僨乕僞傪捛壛偟傑偡丅
* @param dayData 侾擔暘偺僨乕僞
*/
public synchronized void AdddayData(DayData dayData)
{
synchronized(IdxList){
IdxList.add(dayData);
}
}
/**
* <P>巜掕擔晅偺僨乕僞傪庢摼偟傑偡丅乮day峴栚偺梫慺傪撉傒崬傓乯
* @param day 擔晅
* @return dayData 巜掕擔晅偺僨乕僞丅柍偄応崌偼嬻偺僨乕僞僼僅乕儅僢僩偑曉傝傑偡丅
*/
public synchronized DayData GetdayData(int day)
{
DayData dayData = null;
synchronized(IdxList){
if( (day>=0)&&(day<IdxList.size())){
dayData = (DayData)IdxList.get(day);
}
return dayData ;
}
}
/**
* <P>巜掕擔晅僨乕僞傪抲偒姺偊傑偡丅乮day峴栚偺梫慺傪dayData偲抲偒姺偊傞乯
* @param day 擔晅
* @param dayData 侾擔暘偺僨乕僞
*/
public synchronized void SetdayData(int day,DayData dayData){
synchronized(IdxList){
IdxList.set(day,dayData);
}
}
/**
* <P>僨乕僞偺寢崌丅侾擔偺僨乕僞梫慺傪侾峴偵寢崌(String偵曄姺)偟丄String[]傪嵞峔抸偟傑偡丅
* @return 侾擔偺僨乕僞偺廤崌懱(侾寧暘偺攝楍)
*/
public synchronized String[] gettoString()
{
synchronized(IdxList){
//Iterator it=IdxList.iterator();
String[] dayDatas=new String[IdxList.size()];
Iterator it = IdxList.iterator();
for(int i=0;i<IdxList.size();i++){
DayData dayData = (DayData)it.next();
dayDatas[i] = dayData.getDay() + "," + dayData.getFirst() + "," + dayData.getEnd() + "," + dayData.getNote();
}
return dayDatas;
}
}
/**
* <P>file傪GSTextFile傊曉偡
* @return file
*/
public synchronized File GetFile(){return file;}
/**
* <P>僥僉僗僩僼傽僀儖偵彂偒崬傒傑偡丅
* @param pw PrintWriter
*/
public synchronized void Write(PrintWriter pw) throws GSException
{
String[] buf = gettoString();
for(int i=0;i<buf.length;i++){
pw.println(buf[i]);
}
}
/**
* <P>僥僉僗僩僼傽僀儖傪撉傒崬傒傑偡丅
* @param bf BufferedReader
*/
public synchronized void Read(BufferedReader bf) throws GSException
{
try{
String buf;
/* 僨乕僞傪暘夝*/
for(buf=bf.readLine();buf!=null;buf=bf.readLine())
{
StringTokenizer st = new StringTokenizer(buf,",");
int day = Integer.parseInt(st.nextToken());
String first = st.nextToken();
String end = st.nextToken();
String note = st.nextToken();
SetdayData(day,new DayData(day,first,end,note));
}
}catch(IOException e){
throw new GSException("僼傽僀儖偺撉崬傒偵幐攕");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?