⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cidirfile_convert.java

📁 一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。
💻 JAVA
字号:
/*
 * Circular 偺僐儞僶乕僞  CIDirFile_convert.java
 * Copyright (C) 1999-2000 Japan Total System Co,LTD
 *	  Masakatu O	<ookubo@sjts.co.jp>
 */

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;

public class CIDirFile_convert extends GSTextFile_convert
{
	private List IdxList = null;	// 棙梡儌僕儏乕儖
	private CIDirData_convert data=null;

	public static String FILENAME = "direct";

	private File file;

	public CIDirFile_convert(String HomeDir,String UserDir,PrintWriter bf) throws Exception
	{
		String[] fnames = {"directnew","directtmp","directwk"};

		init();
		String filePath = HomeDir + UserDir + File.separator ;

		File file1 = new File(filePath);

		if(file1.exists()) {	// 僼傽僀儖偑懚嵼偡傞偐

			for(int i=0;i < fnames.length;i++) {
				filePath = filePath + fnames[i];
				this.file = new File(filePath);
				
				if(file.exists()) {
					bf.println(file.getParent() + File.separator + file.getName());
					file.delete();
				}
			}
		}
	}


//愨懳偄傞
	protected File GetFile()
	{
		return file;
	}


//愨懳偄傞
	synchronized protected void Write(PrintWriter pw) throws Exception
	{
		String[] buf = toModsString();
		for(int i=0;i<buf.length;i++) {
			pw.println(buf[i]);
		}
	}


//愨懳偄傞
	synchronized protected void Read(BufferedReader bf) throws Exception
	{
		init();

		try{
			String buf;

			for(buf=bf.readLine();buf!=null;buf=bf.readLine()) {
				String buf2;
				String id="";
				String name="";
				String uid="";
				String memo="";

				StringTokenizer st = new StringTokenizer(buf,",",true);
				if((buf2 = st.nextToken()).equals(","))
					throw new Exception("僼傽僀儖僨乕僞偑晄惓偱偡丅");
				id = buf2;

				if(!(buf2 = st.nextToken()).equals(","))
					throw new Exception("僼傽僀儖僨乕僞偑晄惓偱偡丅");

				if((buf2 = st.nextToken()).equals(","))
					throw new Exception("僼傽僀儖僨乕僞偑晄惓偱偡丅");
			       	name = buf2;

				if(!(buf2 = st.nextToken()).equals(","))
					throw new Exception("僼傽僀儖僨乕僞偑晄惓偱偡丅");

				if((buf2 = st.nextToken()).equals(",")) {
					uid = "";
				}else{
					uid = buf2;
				}
				if(buf2.equals(",")){
					if((buf2 = st.nextToken()).equals(","))
						throw new Exception("僼傽僀儖僨乕僞偑晄惓偱偡丅");
					else
						memo = buf2;
				}else{
					if(!(buf2 = st.nextToken()).equals(",")){
						throw new Exception("僼傽僀儖僨乕僞偑晄惓偱偡丅");
					}else{
						if((buf2 = st.nextToken()).equals(","))
							throw new Exception("僼傽僀儖僨乕僞偑晄惓偱偡丅");
						else
							memo = buf2;
					}
				}

				Addmod(new CIDirData_convert(id,name,uid,memo));
			}
		}catch(IOException e){
			throw new Exception("夞棗僌儖乕僾僨乕僞僼傽僀儖偺撉崬傒偵幐攕");
		}
	}

	//弶婜壔
	public synchronized void init()
	{
		IdxList = Collections.synchronizedList(new ArrayList());
	}

	//僒僀僘庢摼
	public synchronized int size()
	{
		return IdxList.size();
	}

	//嶍彍
	public synchronized void Del(String id)
	{
		synchronized(IdxList){
			int     cnt = -1 ;
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (CIDirData_convert)it.next();
				if( id.equals( data.GetId()) ) {
					cnt = i ;
					break;
				}
			}
			if(cnt != -1) {
				IdxList.remove(cnt);
			}
		}
	}

	public synchronized CIDirData_convert GetMOD(String bid)
	{
		synchronized(IdxList){
			int     cnt = -1 ;
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (CIDirData_convert)it.next();
				if( Integer.parseInt(data.GetId()) == Integer.parseInt(bid) ) {
					cnt = i ;
					break;
				}
			}
				return  Getmod(cnt);
		}
	}

	//捛壛
	public synchronized void Addmod(CIDirData_convert mod)
	{
		synchronized(IdxList){
			IdxList.add(mod);
		}
	}

	//峏怴
	public synchronized CIDirData_convert Getmod(int idx)
	{
		CIDirData_convert mod = null;
		synchronized(IdxList){
			if( (idx>=0)&&(idx<IdxList.size()))
				mod = (CIDirData_convert)IdxList.get(idx);
			return mod ;
		}
	}

	//
	public synchronized String[] toModsString()
	{
		synchronized(IdxList){
			Iterator it=IdxList.iterator();
			String[] mods=new String[IdxList.size()];
			for(int i=0;i<IdxList.size();i++) {
				CIDirData_convert mod = (CIDirData_convert)it.next();
				mods[i] = mod.toString() ;
			}
			return mods;
		}
	}

	//峏怴
	public synchronized void update(CIDirData_convert idata)
	{
		synchronized(IdxList){
			int     cnt = -1 ;
			Iterator it=IdxList.iterator();
			for(int i=0;i<IdxList.size();i++) {
				data = (CIDirData_convert)it.next();
				if( Integer.parseInt(data.GetId()) == Integer.parseInt(idata.GetId()) ) {
					IdxList.set(i,idata);
					break;
				}
			}
		}
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -