Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Objects and scope

Thread view: 
paulers85213@gmail.com - 16 Sep 2006 05:54 GMT
Hello,

I am learning java and currently am working on a project that parses a
logfile line by line.  I have a couple if statements that pull out
information important information and assigns the values to variables.
I would like to store these values in objects but when I create a new
instance of my object class in one of my if statements, I can only call
the methods from my class from inside that one if statemen and not from
others. I need to be able to update my object from all of the if
statements in the loop that is extracting the values.

here is my code.

try {
           BufferedReader br = new BufferedReader(new
FileReader("c:\\paul.txt"));
           Matcher
matcher1,matcher2,matcher3,matcher4,matcher5,matcher6;
           int toggle = 0;
           while ( (line = br.readLine()) != null ) {
               matcher1 =
Pattern.compile("^(\\d+:\\d+:\\d+)\\s(.*)\\sTrace:\\s\\[\\s+(\\d+)\\](.*):\\s.*\\(=\\sMessage\\sType\\s47\\);").matcher(line);
               matcher2 = Pattern.compile("^\\s+$").matcher(line);
               matcher3 =
Pattern.compile("^\\s(.*)\\s\\(\\=\\sSubtype\\s(\\d+)\\)\\;\\sDialogueID\\:\\s\\((.*)\\)\\s.*$").matcher(line);
               matcher4 =
Pattern.compile("^\\s{3}.*:.*").matcher(line);
               if (matcher1.find()) {
                   toggle = 1;
                   timeStamp = matcher1.group(1);
                   pim = matcher1.group(2);
                   traceID = matcher1.group(3);
                   ConvDir = matcher1.group(4);
               }
               if (matcher2.find()) {
                   toggle = 0;
               }
               if (toggle ==1) {
                   //extract mesage name, subtype, and dialog ID
                   if (matcher3.find()) {
                       messageName = matcher3.group(1);
                       subType = matcher3.group(2);
                       dialogueID = matcher3.group(3);
                       //System.out.println("Subtype:" + subType + "
DialogueID:" + dialogueID + " Name:" + messageName + " Time:" +
timeStamp + " PIM:" + pim + " TraceID:" + traceID + " Conv Dir:" +
ConvDir);
                   }

                   if (matcher4.find()) {
                       Matcher ani_matcher =
Pattern.compile("^\\s{3}ANI:(.*)").matcher(line);
                       if (ani_matcher.find()) {
                           //System.out.println("Found ANI: " +
ani_matcher.group(0));
                       }
                   }
               }
           }

       } catch (FileNotFoundException ex) {
           ex.printStackTrace();
       } catch (IOException ex) {
           ex.printStackTrace();
       }
   }

Thanks for taking the time to read this. I appreciate your help.
Jim Cheng - 16 Sep 2006 15:57 GMT
Not sure about what your question is.
why couldn't you create the instance outside of the IF statements?

Regards,
Jim

> Hello,
>
[quoted text clipped - 64 lines]
>
> Thanks for taking the time to read this. I appreciate your help.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.