This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Text file location seems to affect number of Jtable records delivered via BufferedReader

 
george stylian
Greenhorn
Posts: 10
MS IE Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm close to completing an online archive index project that's intended to mimic the sorting and filtering behavior of a read-only Microsoft access database table in Jtable format. I'll admit that my strategy is not as technical as hosting the database and dynamically linking it to the user interface:

1) create an access query with the fields I want to display, in the order I want them displayed in
2) export the query to a tab-delineated text file
3) host the Jtable jar / jnlp and text file
4) publish a link to the jnlp
5) update by re-exporting / copy-replacing the text file

The Jtable displays a street name, plan type, plan number, plan year, and a hyperlink to each hosted plan's location on a web server. Street names and / or plan types can be filtered, and most of the fields can be sorted.

This has worked well except for two coding challenges I have not yet figured out, one of which is how to display all of the records from the database table / text file export. There are about 22,000 records. For some time I thought I had a map vs. multimap problem, because I first tried to use the values in the "street name" field as the map key and many records have the same street name. But then I switched the key to a field of unique ID's that was available and the behavior didn't change. I can demonstrate what's happening by swapping the following lines of code in either of two separate java projects:



With the above code, the text file export is stored on my PC in the same directory as the java project, and all of the records get displayed in the Jtable. I know they're all there because I can sort them, manually count how many appear for each street, and reconcile the count with the access database table.



If I paste/replace the above code for a URL stream source instead, with the same text file hosted on my godaddy space, the Jtable populates and operates the same way but with many fewer records. Entire groups of records for specific street names are missing, and only some of the records for other streets appear.



 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show the code you are using to read and parse the file contents.
 
george stylian
Greenhorn
Posts: 10
MS IE Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony. This variation returns all of the records:




This variation returns many less records:



 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ready method cannot be used to test if you have read all of the file. It returning false just means the next call to read may block waiting for input. The reason it appears to work on the local file system is there are no delays in reading the whole file in so ready returns true up until there is nothing more to read, however when reading across a network there may be intermittent delays which can cause ready to return false (ie the reader currently has no data buffered) before the end of file is reached.

In your situation the only way to guarantee reading to the end of the file is to keep reading until readLine() returns null.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:...however when reading across a network there may be intermittent delays which can cause ready to return false (ie the reader currently has no data buffered) before the end of file is reached...


And when I downloaded the actual file to my browser (hopefully that wasn't supposed to be private or confidential data!) there was indeed a noticeable pause about halfway through.
 
george stylian
Greenhorn
Posts: 10
MS IE Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony + Paul for the valuable information. The records seem to be left out very consistently but some type of stream interruption is a logical cause; I hadn't considered problems outside of the code. I'll read more about reader methods next.

I had looked for an 'edit post' option briefly but ran out of time. It's public information though and a large number of the files are already available in an online map index.
 
george stylian
Greenhorn
Posts: 10
MS IE Netbeans IDE Notepad
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This buffered reader code keeps the stream open until the end of the remote text file is reached:



Users don't need to see the key values, which keeps the jtable a little cleaner. This strategy makes the program pickier about null values in the text file though, and my less-than-professional workaround was to populate those fields with " ". Not the best solution but it does allow for filtering to records with no street or type value.

Thanks also for the link to the testing article... very humbling stuff.
 
george stylian
Greenhorn
Posts: 10
MS IE Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once again I ask for some help with this project. Today I made the following minor changes and via console the program performed exactly according to my original plan. But when I hosted the new Jar file and tried to run it remotely, the application looked like it had been set to a viewport size of (0,0). IE it looked like a little toolbar floating on my desktop, and when I expanded it it was completely empty and did not show any data rows or text fields.

I'm pretty confident my problem is not "location of the Jar file." The only changes were to lines 9, 23, and 25 of the same portion of code that was posted on 4/29/15:




 
Tony Docherty
Saloon Keeper
Posts: 3144
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to say without seeing the rest of the code but if that is all you have changed then my guess is the URL constructor is throwing a MalformedURLException which you aren't catching until after the code that builds the GUI (or you are not catching it at all) and so no components are being added to the frame and hence it is sized at 0,0.
 
george stylian
Greenhorn
Posts: 10
MS IE Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Tony, that is quite likely correct: I did not add any code for catching exceptions. But strangely, the application worked properly on an older Toshiba / vista laptop last night. My work console is Dell / windows 7 with a current java version.

I'll add the exception-catch code.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!