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

📄 tapiconfig.java

📁 tapi的java封装
💻 JAVA
字号:
/*
*	JTAPI library copyright 1998 by Web4Groups consortium (http://Web4Groups.at)
*/

import java.io.*;
import java.util.*;


public class TAPIConfig {

	protected String fileName = "tapi.conf";

	//The data structure which stores the configuration information has the following format:
	//A Hashtable with the line id (converted to an Integer) as key and a Vector as value.
	//The first element of this Vector consists the name of the address,
	//all the following elements are the terminal names assocciated to this address.


	//the main routine, reads in the configuration file and returns a Hashtable:
	public Hashtable read() {

		Hashtable hash = new Hashtable();
		FileInputStream fin = null;
		int num = 0;
		try {
			fin = new FileInputStream(fileName);
			String line;
			do {
				num++;
				line = readLine(fin);
				if(line != null) {
					if(!handleLine(hash, line)) {
						System.err.println("Syntax Error in the file "+fileName+" at line "+num);
						return null; 
					}
				}
			} while(line != null);
			fin.close();
		} 
		catch(Exception e){ 
			e.printStackTrace(); 
		}
		return hash;
	}


/**
* Read a line from an input steram
* @param stream The input stream
* @return The line or null if no more data available. 
*/
	public static String readLine(InputStream stream) {

		StringBuffer buffer = new StringBuffer();
		int temp;
		do {
			try {
				temp = stream.read();
			} catch(Exception e) {
				return(null);
			}
			if(temp == -1){
				if(buffer.length() > 0)
					return(buffer.toString());
				else
					return null;
			}
			if(temp != '\n')
					buffer.append((char)temp);
				
		} while(temp != '\n');
		
		
		return(buffer.toString());
	}


	//process the line of the configuration file (read in by readLine()):
	protected boolean handleLine(Hashtable hash, String line){

		if(line.startsWith("#"))	// comment
			return true;
		if(line.equals(""))		// empty line
			return true;
		StringTokenizer t = new StringTokenizer(line);
		int count = t.countTokens();
		if(count < 3)
			return false;
		int index = 0;
		String lineId = t.nextToken();
		String address = t.nextToken();
		Vector addrTerm = new Vector();
		addrTerm.addElement(address);
		String terminal = " ";
		while (t.hasMoreTokens()) {
			terminal = t.nextToken();
			addrTerm.addElement(terminal);
		}
		hash.put(new Integer(lineId), addrTerm);
			
		return true;
	}
}

⌨️ 快捷键说明

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