Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

BufferedReader.readLine() works in debug, but not run...  RSS feed

 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I step through my code line-by-line in debug-mode, BufferedReader.readLine() returns the expected values. However, when I run the code, BufferedReader.readLine() returns null.

In my earlier development phases, I used a normal File object and never experienced this issue. It started when I switched to the createTempFile approach...

Summary:
I'm decrypting a file and putting the contents into a temp file using


I'm then reading the temp file line by line - splitting each row into an array. Then passing that array to my stored proc call...




So, should I be using a different object to work with the tempfile, or do I need to work with a real file and manage it on my own?

Also, the decrypted file sizes range for 700kb to 9MBs - if that changes what type of reader to use...

Thanks!
[ August 28, 2008: Message edited by: Chris Montgomery ]
 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you showed there creates a file (empty, of course) and then starts reading from it. So it isn't surprising that you don't get any data.

By the way, the File you created is a "normal" File object. You shouldn't have to treat it differently than any other file.
[ August 28, 2008: Message edited by: Paul Clapham ]
 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, short hand code...
The file is filling up using this code:


I'll move back to the 'regular file' (even though both commands are creating a file, but one you choose the location and the other it chooses the location for you)

Still can't understand whey the tempFile is empty, missing or unreadable...

Thanks!
 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so a 'regular' (created using new File("filepath")) file is behaving the same way...

I did stop the code in the middle and was able to browse to the file that is returning null for .readLine. There is content in the file as well.

So now I'm wondering if the BufferedReader is the incorrect object or if my approach to all of this is not considerate of File reading rules...

OS is Windows XP
 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If things work differently when you are debugging versus when you aren't, that very often indicates that there are threading errors going on. When you go into debug mode, you stop one thread and allow another thread to do some work which it normally wouldn't do.

So that suggests to me that gnu.decrypt is starting a thread to do its work and returning immediately. Or something along that line. Does the documentation for that method say anything about threading or asynchronous processing?
 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no... I wrote that.
the decryption was a bit of a headache, since java and GnuPG on windows don't play well together.. Process waitFor() hangs even if you read the output and error streams.

So I've written an external .bat that decrypts the file for me. I just make sure java is pointing to the same file that was created during the decryption routine in the .bat file.


here's the code:


Hmmmmm....
So perhaps the work done by the .bat program hasn't completed by the time java is looking for the results file.

I think I'm starting to understand!


Thanks for helping me through this. Also, if you think I'm on the wrong track let me know.

Chris
 
Chris Montgomery
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would it be 'silly' to write a check routine that checks to see if the file was created by the .bat program and that it's finished filling up?

pseudo code:


Fun infinite loop possibility...
Could also hit a false positive where the lengths are the same, but the file is still growing...

Ick

[ August 28, 2008: Message edited by: Chris Montgomery ]
[ August 28, 2008: Message edited by: Chris Montgomery ]
 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Montgomery:
Would it be 'silly' to write a check routine that checks to see if the file was created by the .bat program and that it's finished filling up?
Well, yes, it would be silly. In this case at least. Your "ick" comment indicates quite correctly what can go wrong with that idea. But fortunately you don't need to do that. If you need to wait for a Process to finish, you just call its method which does that. Check out the API documentation if you can't guess its name.

 
relli Toto
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello chris, my problem with your code is that the decrypt method doesn't produce any output in the frist place when you execute it from java. It works fine from the command line though, but not from java!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!