cinotefile_convert.java

来自「一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。」· Java 代码 · 共 207 行

JAVA
207
字号
/*-
 * 夞棗斅僨乕僞僐儞僶乕僩  CINoteFile.java
 */

import java.io.FileOutputStream;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.util.Properties;
import java.util.StringTokenizer;

/**
 * <p>夞棗斅僨乕僞僐儞僶乕僩
 * <p>Copyright (C) 1999-2000 Japan Total System Co,LTD
 *
 * @author   Masakatu O	  &lt;ookubo@sjts.co.jp&gt;
 * @author   Satoru K   &lt;koni@sjts.co.jp&gt;
 */
public class CINoteFile_convert extends GSTextFile_convert
{
	private String  entuserid="";	// 儐乕僓ID
	private String  name="";		// 儐乕僓柤
	private String  taitol="";		// 僞僀僩儖
	private String  messege="";		// 杮暥
	private String  limit="";		// 寈崘奐巒擔
	private String  timestamp="";	// 嶌惉擔
	private String  tmpfile="";		// 揧晅僼傽僀儖
	private String  tmptype="";     // 揧晅僼傽僀儖僞僀僾

	public void CINote(String entuserid,String name,String taitol,String messege,String limit,String timestamp, String tmpfile, String tmptype)
	{
		this.entuserid = entuserid;
		this.name = name;
		this.taitol = taitol;
		this.messege = messege;
		this.limit = limit;
		this.timestamp = timestamp;
		this.tmpfile = tmpfile;
		this.tmptype = tmptype;
	}

	public void setEntuserid(String entuserid) { this.entuserid = entuserid; }
	public void setName(String name) { this.name = name; }
	public void setTaitol(String taitol) { this.taitol = taitol; }
	public void setMessege(String messege) { this.messege = messege; }
	public void setLimit(String limit) { this.limit = limit; }
	public void setTimestamp(String timestamp) { this.timestamp = timestamp; }
	public void setTmpfile(String tmpfile) { this.tmpfile = tmpfile; }
	public void setTmptype(String tmptype) { this.tmptype = tmptype; }

	public String getEntuserid() { return entuserid; }
	public String getName() { return name; }
	public String getTaitol() { return taitol; }
	public String getMessege() { return messege; }
	public String getLimit() { return limit; }
	public String getTimestamp() { return timestamp; }
	public String getTmpfile() { return tmpfile; }
	public String getTmptype() { return tmptype; }

	public static final String V1 = "entuserid";	//儐乕僓ID
	public static final String V2 = "name";			//儐乕僓柤
	public static final String V3 = "taitol";		//僞僀僩儖
	public static final String V4 = "messege";		//杮暥
	public static final String V5 = "limit";		//桳岠婜尷
	public static final String V6 = "timestamp";	//僞僀儉僗僞儞僾
	public static final String V7 = "tmpfile";		//揧晅僼傽僀儖
	public static final String V8 = "tmptype";      //揧晅僼傽僀儖僞僀僾

	public final static String SPATH = File.separator ;
	public final static String DIR0 = "data" + File.separator ;
	public final static String DIR1 = "user" + File.separator ;
	public final static String NAME = "note";

	private Properties properties=null;

	private File file;
	private String filePath = null;
	private String GrpDir = null;

	public CINoteFile_convert(String HomeDir,String Id,int mode,PrintWriter bf) throws Exception
	{
		properties = System.getProperties();
		if(mode == 1)
			GrpDir = HomeDir + DIR1 + Id ;//ID偼夞棗斅ID
		else
			GrpDir = HomeDir + DIR0 + Id ;//ID偼儐乕僓乕ID
		GrpDir = GrpDir.replace('/',this.properties.getProperty("file.separator").charAt(0));

		File file1 = new File(GrpDir);
		if( file1.exists() ) {
			filePath = GrpDir + SPATH + NAME;
			this.file = new File(filePath);

			if( file.exists() ) {
				bf.println(file.getParent() + File.separator + file.getName());
				if(mode != 1) {
					Load();
					Save();
				}
				else
					Delete();
			}
		}
	}

	public synchronized boolean Get(String HomeDir,String Id) throws Exception
	{
		properties = System.getProperties();
		GrpDir = HomeDir + DIR0 + Id + SPATH + NAME;
		filePath = GrpDir.replace('/',this.properties.getProperty("file.separator").charAt(0));

		this.file = new File(filePath);

		if(file.exists()) {
			Load();
			return	true;
		}else{
			return	false;
		}
	}

//昁偢偄傞
	synchronized protected File GetFile()
	{
		return file;
	}

//昁偢偄傞
	synchronized protected void Read(BufferedReader bf) throws Exception
	{
		try {
			String buf = null;

			tmptype = "application/octet-stream";
			for(buf=bf.readLine();buf!=null;buf=bf.readLine()) {
				if(buf.length() > 0) {
					StringTokenizer st = new StringTokenizer(buf,"=");
					String label = st.nextToken();
					String value = st.nextToken();
					if(label.equals(V1))
						entuserid = value;
					else if(label.equals(V2))
						name = GSTool_convert.delimitDecorde("=",value);
					else if(label.equals(V3))
						taitol = GSTool_convert.delimitDecorde("=",value);
					else if(label.equals(V4))
						messege = GSTool_convert.delimitDecorde("=",value);
					else if(label.equals(V5))
						limit = value;
					
					else if(label.equals(V6)) {
						timestamp = value;
						if(timestamp.length() == 8)
							timestamp = timestamp + "000000";
					}
					else if(label.equals(V7))
						tmpfile = value;
					else if(label.equals(V8))
						tmptype = value;
				}
			}
		} catch(IOException e) {
			throw new Exception("\"Data file\"撉崬傒僄儔乕");
		}
	}

//昁偢偄傞
	synchronized protected void Write(PrintWriter pw) throws Exception
	{
		pw.println(V1 + "=" + getEntuserid());
		pw.println(V2 + "=" + GSTool_convert.delimitEncorde("=",getName()));
		pw.println(V3 + "=" + GSTool_convert.delimitEncorde("=",getTaitol()));
		pw.println(V4 + "=" + GSTool_convert.delimitEncorde("=",getMessege()));
		pw.println(V5 + "=" + getLimit());
		pw.println(V6 + "=" + getTimestamp());
		pw.println(V7 + "=" + getTmpfile());
		pw.println(V8 + "=" + getTmptype());
	}


	public void setContent(byte[] content) throws Exception
	{
		try{
			FileOutputStream fos = new FileOutputStream(filePath+"b");
			BufferedOutputStream bos = new BufferedOutputStream(fos,content.length+1);
			bos.write(content,0,content.length);
			bos.flush();
			bos.close();
		}catch(FileNotFoundException e){
			throw new Exception("僼傽僀儖偑尒偮偐傝傑偣傫丅");
		}catch(IOException e){
			throw new Exception("IO僄儔乕偱偡丅");
		}
	}

	public synchronized void Delete() throws Exception
	{
		if(file.exists())
			file.delete();
	}


}

⌨️ 快捷键说明

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