Hi All,
I wrote one program it works request and response purpose. The program name is BSDO
The BSDO holds request pattern and response pairs in BSDOData objects and provides a lookup method to find the appropriate response to a request.
package xxx.xxx.provider;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class BSDO
{
private String m_strFileName;
private long m_fileModTime;
private ArrayList m_bsdoList;
/**
* <p> Constructor.
*
* @param strFileName The name of the file containing the request pattern
* and response pairs
*/
public BSDO(String strFileName)
{
super();
m_strFileName = strFileName;
m_fileModTime = 0;
m_bsdoList = new ArrayList(8);
}
/**
* <p> Adds a request pattern and response pair.
*
* @param strPattern The request pattern
* @param strResult The response data
*/
public void addResult(String strPattern, String strResult)
{
BSDOData item = new BSDOData(strPattern, strResult);
m_bsdoList.add(item);
}
/**
* <p> Returns the response data corresponding to the first pattern which
* matches the request.
*
* @param strRequest The request data
* @return The response data
* @throws BSDOException if the BSDO cannot be initialized or a matching
* pattern cannot be found
*/
public String getResult(String strRequest) throws BSDOException
{
if ((m_fileModTime == 0) || (m_fileModTime != getFileModTime()))
initialize();
for(int i = 0; i < m_bsdoList.size(); i++)
{
BSDOData item = (BSDOData)m_bsdoList.get(i);
if (item.isMatch(strRequest))
return item.getResult();
}
BSDOException exception = new BSDOException("Request could not be matched to a pattern in the file");
throw exception;
}
/**
* <p> Initializes the bsdo data map from the file.
*
* @throws BSDOException if there is a problem with accessing the file
*/
public void initialize() throws BSDOException
{
try
{
String result;
File file = new File(m_strFileName);
FileInputStream fis = new FileInputStream(file);
if (m_fileModTime != 0)
{
m_bsdoList.clear();
}
// Read until the end of file is reached.
ArrayList lines = new ArrayList(8);
InputStreamReader isr = new InputStreamReader(fis);
//BufferedReader reader = new BufferedReader(isr, 8192);
BufferedReader reader = new BufferedReader(isr);
while (reader.ready())
{
String line = reader.readLine();
lines.add(line);
// If we have two lines available, process them.
if (lines.size() >= 2) {
String strPattern = (String)lines.get(0);
String strResult = (String)lines.get(1);
// Add a new result entry to the bsdo object.
addResult(strPattern, strResult);
// Empty the vector so that we start again.
lines.clear();
}
}
fis.close();
//isr.close();
//reader.close();
// Mark the initialisation as complete.
m_fileModTime = getFileModTime();
}
catch(IOException e)
{
BSDOException exception = new BSDOException("IOException in file " + m_strFileName + ": " + e.getMessage());
throw exception;
}
}
/**
* <p> Returns the time at which the bsdo file was last modified.
*
* @return The time at which the bsdo file was last modified
*/
private long getFileModTime()
{
File file = new File(m_strFileName);
return file.lastModified();
}
}
The performance was very slow...
Please guide me how to increase performance in IO.....
Thanks,
Anil


