Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Really Challenging...HelpMe..java.Util - very Urgent  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can Anyone help me to get the Solution for the follwing program.I was trying a lot and fed up at getting(read) the byteArray record from hashtable to a vector for printing the output.
I had pasted the detail of the program, plz reply in URGENt ,it is very very URGENT
The Specification for the program:
Test Class
----------
Class name is called TestAttributeParser will be used to test the procesing class.
The main function of TestAttributeParser should recieve name of configuration file and test file
as arguments.
Load cinfiguration properties from the configuration file.
Construct an instance of the Processing class and pas the configuration properties to the constructor
Load testdata from the testfile.txt into a byte array.this byte array should be stored as
an element with key"fileContents" in a hashtable.
call the parse method of the processing class,passing the Hashtable as a parameter and recieve the
output records(see below)
Processing Class
----------------
Class name is AttributeParser
care should be taken to make the processing class threadsafe.
Constructor recieves properties object which define how to parse.
Contains a method called parse which recieve a hashtable as argument and
returns a vector of hashtables.
Each hashtable in the output vector should contain one record from the test file.
Each record in the test file contains one headerline and a number <key> =<value>
pairs.Each key/value pair should be entered into the hashtable(for exceptions to
this: see configuration). If quotes around the values are present, they should be stripped.
In addition, the single headerline should be stored in the hashtable under the key name
supplied by the Configuration properties.
All white spaces preceeding or following keys or values should be trimmed.
Format of InputText file:
-------------------------
This file contains one or records.Records are seperated by a single empty line
(this line may possibly contain white space(s)).This line in each records contain an
arbitary string.The rest of the record contains key/value pairs,one on each line.
<header for record 1>
<key1>=<value1>
<key2>=<value2>
....
<keyn>=<valuen>
<headerline for record 2>
<key1>=<value1>
<key2>=<value2>
....
<keyn>=<valuen>
etc.
format of testinput.txt file;
Thu Jan 11 00:05:14 2001
NAS-IP-Address = 192.168.100.93
NAS-PORT = 20027
Vendor-Specific-9-2 = "Serial1/0:27"
NAS-PORT-Type = ISDN
User-Name = "Dynjandi"
Called-Station-Id = "5300401"
Calling-Station-Id = "5681390"
Acct-Status-Type = Start
Acct-Authentic = RADIUS
Service-Type = Framed-user
Acct-Session-Id = "00006f3B"
Framed-Protocol = PPP
Acct-Delay-Time = 0;
Timestamp = 979171514

Thu Jan 12 00:05:14 2001
NAS-IP-Address = 192.168.100.93
NAS-PORT = 20027
User-Name = "Dynjandi"
Called-Station-Id = "5300401"
Calling-Station-Id = "5681390"
Acct-Status-Type = Start
Acct-Authentic = RADIUS
Framed-Protocol = PPP
Acct-Delay-Time = 0;
Timestamp = 979171514

One input file is provided:testinput.txt
Configuration Properties:
-------------------------
The following list of properties control the processing class:
header Name The key name used to store the headerline in the Hastable for each
record.Do not store the headerline if absent or empty.
outputFields contains a semicomma seperated list of keys that are allowed in the
output Hashtable.If this variable is absent or empty, all key/value pairs found in
input file should be stored.
Two samples configuration files are provided:config1.properties and
config2.properties.
format of config1.properties
-----------------------------

headername = "DateTime"
outputFields = "User-Name;Acct-Status-Type;Acct-Input-Octets;AcctOutput-Octets;Timestamp"

headername = "headerLine"
outputFields = ""
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kathir k,
Please read the Naming Policy It can benefit you, read [url=http://www.javaranch.com/bookpromo.jsp].
Looking forward to your posts
 
kathir k
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
_________________________________________________________________

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);

}
}
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathir,
I would heed the warning about the naming policy. I would hate to see your account get deactivated after all the work you put to show us your code.
One last thing I would ask you is please read the FAQ to learn how to format your code so it's more readable.
For example, this is more readable than your example:

Thanks,
-Peter
Ps. After you format your code, I promise to take a look at it.
[This message has been edited by Peter Tran (edited January 14, 2001).]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Peter Tran:
[B]Kathir,
I would heed the warning about the naming policy. I would hate to see your account get deactivated after all the work you put to show us your code.
One last thing I would ask you is please read the FAQ to learn how to format your code so it's more readable.
For example, this is more readable than your example:

Thanks,
-Peter
Ps. After you format your code, I promise to take a look at it.
[This message has been edited by Peter Tran (edited January 14, 2001).][/B]


Hello Peter,
I am really sorry for not going thro the policy.
Well Now i had given my code also i had changed my User name = kat Bhawan.
Expecting your early reply and solution
Thanks


 
kat Bhawan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
I was able to read the byte array pass in a hashtable and display as a string.
The Problem now is the output was displayed in a different manner, i.e, some key value pairs are displayed with spaces and some are displayed without spaces. which is difficult for us to use this to compare with the properties file;
Expect your solution
Regards
kat


Thanks,
-Peter
Ps. After you format your code, I promise to take a look at it.
[This message has been edited by Peter Tran (edited January 14, 2001).][/b]<HR></BLOCKQUOTE>
Hello Peter,
I am really sorry for not going thro the policy.
Well Now i had given my code also i had changed my User name = kat Bhawan.
Expecting your early reply and solution
Thanks

[/B]<HR></BLOCKQUOTE>
I quickly formatted the code for readablity. --Carl

[This message has been edited by Carl Trusiak (edited January 15, 2001).]
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kat,
First, thank you for the following the naming policy. Second, thanks for formatting your program so that it's more readable. I know this took some work. Finally, you should have received my email regarding your program. Please let me know if you still want to work on a solution. Again, I don't have time to code up a complete solution for you. I think you're getting overwhelmed with the requirement. It's not as bad as you think if you break it down into little pieces.
Regards,
-Peter
Ps. I'm a sucker for "Really Challenging" things.
-Peter
 
kat Bhawan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi peter,
Yes, i want u to work for the solution, that gives the vector output based on the property file standard , also it has to be thread safe.
Well, i am tryng a lot and i am able to get the string output of the test input file, which is not in a standard format.I am having problems.i am looking for ur sols.
Regards
kat
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!