_________________________________________________________________
Originally posted by Peter Tran:
Kathir,
Why is it so urgent? Your specifications doesn't look to difficult to implement. Exactly what part are you having difficulty with? Have you tried writing the application yourself? You should post the part of your program that is giving you difficulty rather than asking for help on the entire application. Just a word of advice from what I've observed. If you're a little more specific on your problem, e.g. "I'm having trouble reading in a text file using this class...Is my approach correct?", you'll get a much faster response.
As is, I don't know where to begin helping you out. Unless I write your application and paste the whole solution here. If I did that, you wouldn't learn anything.
That said, post part of your application that is giving you trouble, and I think you'll find that JavaRanch people are more than willing to help you out.
-Peter
[This message has been edited by Peter Tran (edited January 14, 2001).]
_______________________________________________________________-
Peter,
Thanks for your efforts,
My Query and difficulty is >
The problem to me is that, iwas able construct the class TestAttributeParser and load the config1.properties and testinput.txt file, but in the AttributeParser class file, i am having difficulty in reading the stored testinput.txt file(which is in a Bytearra in the hashtable) andcompre it with config property and display the result in the vector.
so plz help me to solve the problem.
Also i am pasting and attaching the code i had developed ,and plz give me the correct coding for the solution.
kathir
i am pasting my code :
TestAttributeParser:
import java.io.*;
import java.util.*;
public class TestAttributeParser3 {
Hashtable ht = new Hashtable();
Vector resultVector = new Vector();
Properties getProp;
TestAttributeParser3(
String propFile, String testFile) {
this.propFile = propFile;
this.testFile = testFile;
}
public void loadConfigProp() {
String key;
String value;
String data;
int i = 0;
boolean status =true;
Properties prop = new Properties();
try {
File getPropFile = new File(propFile);
FileReader fileRead = new FileReader(getPropFile);
BufferedReader buffer = new BufferedReader(fileRead);
while(status) {
data = buffer.readLine();
if(data != null) {
i++;
prop.put("Record" + i,data);
System.out.println(data);
} else {
status = false;
}
}
buffer.close();
} catch(IOException e) {
System.out.println("IOError" + e);
}
}
public void loadTestFile() {
Hashtable hashTest = new Hashtable();
byte input[];
int i =0;
String data;
String getdata;
boolean condn =true;
try{
File gettestFile = new File(testFile);
FileReader fileRead = new FileReader(gettestFile);
BufferedReader buffer = new BufferedReader (fileRead);
while(condn) {
getdata = buffer.readLine();
if(getdata != null) {
data += getdata;
} else {
condn =false;
}
}
buffer.close();
input = input.getBytes();
System.out.println("Input Length" + input.length);
} catch(IOException e) {
System.out.println("IOError" + e);
}
hashTest.put("fileContents" , input);
}
public void printResult() {
AttributeParser ap = new AttributeParser(getProp);
Vector v = ap.parse(ht);
Iterator ir = v.iterator();
while (ir.hasNext()){
System.out.println(ir.next());
}
}
public static void main (String args[]) {
TestAttributeParser3 runTest = new TestAttributeParser3("config1.properties","inputtest.txt");
runTest.loadConfigProp();
runTest.loadTestFile();
runTest.printResult();
}
}
AttributeParser:
import java.io.*;
import java.util.*;
class AttributeParser2{
Properties prop;
Vector vectorProperties = new Vector();
Vector vectorTest = new Vector();
public AttributeParser2(Properties prop){
this.prop = prop;
}
public Vector parse(Hashtable hashtable){
Set key;
String value = null;
String str = null;
key = prop.keySet();
Iterator itr = key.iterator();
while(itr.hasNext()){
str = (String)itr.next();
value = prop.getProperty(str);
findMainSeperator(value);
}
convertString(hashtable);
return vectorProperties;
}
public void findMainSeperator(String valuein){
int sepPostion =0;
valuein = valuein.trim();
String result = null;
if (valuein == null){
vectorProperties.addElement("NA");
}else{
sepPostion = valuein.indexOf("=");
if(sepPostion > 0){
result = valuein.substring(sepPostion + 1);
System.out.println("Main" + result);
findSubSeperator(result);
}
}
//removeQuotes(result);
}
public void findSubSeperator(String res){
System.out.println("inside sub");
int postion =0;
int start =0;
boolean status =true;
String string = null;
String storeValue = null;
res = res.trim();
int lastoccurance = 0;
lastoccurance = res.lastIndexOf(";");
if (lastoccurance == -1){
storeValue = removeQuotes(res);
vectorProperties.addElement(storeValue);
}
else{
storeValue = removeQuotes(res);
while(status){
postion = storeValue.indexOf(";",start);
if(postion > 0){
System.out.println(res + "sub");
string = storeValue.substring(start,postion);
System.out.println(string);
vectorProperties.addElement(string);
start = postion + 1;
}
else{
string = storeValue.substring(lastoccurance);
vectorProperties.addElement(string);
status = false;
}
}
}
}
public String removeQuotes(String quoteString){
System.out.println("RemoveQuotes");
int quotePostion = 0;
String finalString = null;
boolean status = true;
int start =0;
while(status){
quotePostion = quoteString.indexOf("\"",start);
if(quotePostion != -1){
quoteString = quoteString.substring(quotePostion +1,quoteString.length() -1);
System.out.println("Final " + quoteString);
start = quotePostion + 1;
}else{
status = false;
finalString = quoteString;
}
}
System.out.println("Final String... " +finalString);
return finalString;
}
public void convertString(Hashtable hastable){
String key;
Enumeration enum;
enum = hastable.keys();
key = (String)enum.nextElement();
Byte value = hastable.get(key);
//for(int i=0; i< value.length; i++){
//System.out.println(value);
}
}