Bd Howard

Greenhorn
+ Follow
since Mar 30, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bd Howard

I'm confused. The relevant code is posted above. The only difference between my code that works locally is that instead of the URL/URLConnection/InputStreamReader I use a FileReader to grab the local log file.

Anyway, you posted a response quicker than I could get back here. I used the skip() method on the reader and it works great!!

Thanks so much for the help, I do appreciate it. You pointed me in directions I needed to be pointed.

BD
6 years ago
Using a FileReader, compiled with 1.7 I only needed to set up the reader once and it grabbed each file update just like the Unix tail command does. Notice in the code above the Reader is created outside the loop (but also remember that I use a FileReader locally, and the URL stuff in the above code). Using URLConnection and InputStreamReader compiled with 1.5 the Reader grabs the file then gives up after printing the contents once. As you mentioned, each new Reader prints out the whole file again.

How would you forward to the "new" content in the file? I am thinking about storing the "old" file size and using that to mark() with so I can skip the "old" content. That said, I have no clue if this is a good way to do it since I've never done this sort of thing. I am going to read up on the various ways to move the file pointer around but I'd appreciate any input you have regarding skipping the "old" content.

BD
6 years ago
Okay, I guess I wasn't following your response correctly.

I wonder if FileReader watches for changes while InputStreamReader doesn't.

Do you think my thread should sleep longer than 1 second between polls?

I'll try a reset and/or a new stream per loop.

Again, I appreciate the response and help.
6 years ago
Thanks for the response. :-)

Yes, the initial contents of the log file are displayed fine.

If I open the log file and make a change and save it as the infinite loop is running in the code above, the change is not displayed. On my local machine, using FileReader instead of the InputStreamReader stuff, the changes do show.

I'd appreciate any insight you can offer.

BD
6 years ago
Hello,

I am trying to display in near real time the changes to a log file. I have 'proof of concept' running locally but moving my code to access a file (via a symlink) on the server has proven problematic. The symlink resides in the /var/www/html/log_links directory and points to the log file which is not under /var/www/

I have an inner class, shown below, that will grab the 'test.log' file from the server and display its contents on the console. Any changes I make to the log file as my runs are not printed out though. The only difference between this version and the version that works on my local machine is I am using a FileReader for the local file whereas I am using URL/URLConnection/InputStreamReader for the version below.

My question is how can I send the new updates to the log file down the Stream? Oh, and I only have access to Java 1.5



Appreciate the help

BD
6 years ago
Ulf & Paul,

These two breadcrumbs you've given me are exactly what I was looking for. Now I have a trail to follow and implement.

Many thanks

BD
6 years ago
I appreciate the response Paul.

Today I explored grabbing the file via PHP and that worked well. I now have the contents displaying in the browser after parsing it with PHP.

I can get the file onto the client easily from outside the Applet, but I need it passed (or the parsed contents of the file passed) into the Applet. Also, the specific file is chosen via JComboBox in the Applet so that variable must be sent to the server.

Anyway, the PHP seems to be working but I'll take your advice and look into having IT configure the server so the log directory is served to the outside world. I don't expect that to be a problem since this is an intranet and the "world" is kinda small.

Thanks again Paul,

BD

6 years ago
Hello,

Is it possible to grab a file stored on the server without using Tomcat?

I have been tasked with parsing and displaying a log file inside a legacy Applet. Both the Applet and the log file are stored on the same server. As I am reading up on this, I have discovered that JSch may be the way to go. That said, Tomcat is not installed on the server and the powers that be don't want to "mess" with that server.

Could someone point me in the right direction as to how I might grab a file (with this Tomcat restriction) so I can display it in the Applet? I can do everything involved with this task except get the file.

I can ssh into the server from the client.

Appreciate the help

BD
6 years ago
Stevens,

Thanks for the post, I appreciate every viewpoint I can get. I was referring more to design than formatting. I am trying to learn to break things up in a manner so others can follow what I am trying to code. I've made good progress, but there is always room for improvement. Oh, and I am glad old dogs can learn new tricks, since that means there is hope for me. :-)



Jayesh,

I have four programs in my portfolio, and I do a round-robin update to them. As I learn more, I just revisit each and change its code to show my new knowledge. Several times, I have come back to one of them and looked at the code and frowned. How could I write such ugly code?? haha

As far as the best solution, I believe I am far from that. Each of my four programs have always worked, but the code was difficult to follow at best, and just plain old spaghetti at worst. That is changing though.

I appreciate your input. :-)

BD
7 years ago
Yes, the methods are private. It appears to me that they are used merely to clean up the code and make it easier to add/remove stuff from the GUI.

The move from procedural to OO has been a challenge, but I am getting there. I learned to code using Fortran & Pascal back in the early 90s then decided to take a different career path. So my personal coding odyssey to OO is only influenced by procedural instead of dominated by it since I had forgotten much by the time I returned to school.

No coding for me today, since I have to repair my car. :-(

Cheers

BD
7 years ago
I don't think I should call this a suggestion on their part, merely an example I gleaned from code they posted.

In a nutshell, each individual JPanel is handled in its own method, and that method returns the JPanel (filled with all of its stuff) which is then added to the outermost JPanel/JFrame. This way appears to force the careful selection of which variables become fields and which stay local which is something I've struggled with. Makes me question the wisdom of using a procedural language to introduce new students to programming. ;-)

Thanks for the help.

BD
7 years ago
I appreciate the link you posted Campbell, I will take a look.

Your point about "varying quality" is what drove me to make this post. I can Google all day but I don't have the experience to separate the crap from the...uh.....non-crap.

I did some digging on JavaPractices last night and it seems like a good source to me, and your assessment is most helpful.

I did not find anything about code layout there, but they have good examples in terms of the initial GUI setup, which is what I was really focused on in terms of my code. My GUI init method was so long, and I know that is not a good thing. I saw some "tricks" they used to break it up into a more readable format, so I am in the process of changing my code now.

Thanks

BD

Ps. >30k posts? Wow. :-D
7 years ago
Update:

Is the website JavaPractices considered a good source?
7 years ago
Hello,

I have been building a small portfolio of Java programs that I am using in my search for a job/internship. The code works to my satisfaction, but I am unsure if my source code itself follows best practice.

For instance, the code required to make a GUI work seems quite large to me, and I don't know if I've organized it in a wise and maintainable fashion.

So my question is this: could someone point me to a resource that would give me an example of how a professional organizes GUI code? Often in web based examples, the code is the bare minimum to get the point across, so I am hoping to find a "complete" GUI example with more than one type of listener, JPanels, buttons, checkboxes, etc.

Thank you for the help.

BD
7 years ago
Hello,

I am not sure where to start debugging to deal with a freezing program. This is strange since the program runs fine from within the Eclipse IDE. When I export it to a runnable JAR, the freeze happens after a few interactions with that instance of the program.

I'm on OSX 10.7.4 and my JAR freezes in both 1.6_37 and 1.7_09. One unknown from my POV is how Eclipse runs with multiple versions of Java installed on my Mac. When I set Eclipse to compile with either 1.6 or 1.7, the program runs fine in the IDE. Using the Java Preferences utility program, I have moved both 1.7 and 1.6 64bit into the top spot during my quest to find the cause of this problem. Whenever I run Terminal and type java -version, it always returns 1.7_09 so I don't know if Eclipse follows that or not when I set it to compile in 1.6.

The program stores text in an ObjectOutputStream that is stored locally in a file. I use ObjectInputStream to access the file. The file is less than 100k.

I am at a loss as to explain why it runs in the IDE, but fails as a JAR. When running with either the JAR version or inside the IDE, both access the same file with the Streams.

Perhaps someone can point me in the direction of a possible cause? Or maybe a guess? I know the scope of this question is awfully general, but until I can narrow down where to look, I don't know how to be more specific. I don't remember having this problem before the recent updates to Java, but I've only made this program a runnable JAR a few times in the past, so the problem may have existed before the updates.

Thanks for the help,

BD
7 years ago