• Post Reply Bookmark Topic Watch Topic
  • New Topic

Aleatory IOException with "Handle is invalid"  RSS feed

 
Enrico Gueli
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I have written a class that reads a file in a format I built from scratch. It's a sequence of chunks, each made of an integer and a GZIPped block of serialized objects. The integer specifies the size of the block, in order to allow fast seeking. While reading, it also constructs an index of the position of each chunk in the file.
The first implementation of this class reads an entire chunk, decompresses it, unserializes the objects and sends them to a callback method; this implementation works like a charm, but it doesn't allow to control the flow of incoming objects.

Now I'm trying to write a better implementation, where the user asks for an object at time. The reader contains a ByteArrayInputStream for the current (compressed) block and uncompresses/unserializes it only when needed.
The problem with this latter implementation is that I randomly get an IOException while calling the RandomAccessFile.getFilePointer(long) method, with a message "Handle is invalid".
There are no other threads running; there are no calls to close() anywhere in my code. If I print to stdout the result of RandomAccessFile.getFD().valid() before each call to getFilePointer(), it is always true except when the exception occurs. I think this means that the file gets closed by something I'm unaware of.
The position of the file when this happens is always variable, but it's usually around 500-600kB.
Please note that also the older implementation contains calls to RAF.getFilePointer(long), but they never throw such an exception.

I can post come code and part of the data file, but I'd ask your permission first because of its size (around 1MB).

Any clue?

Thanks & best regards
Enrico

 
Greg Charles
Sheriff
Posts: 3014
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Enrico,

Welcome to JavaRanch! I love your use of aleatory, though it probably only makes sense to people who have studied music. "Random" or "intermittent" would be a more common way of putting it.

As to your question, I'm not exactly clear what you're doing. You say RandomAccessFile.getFilePointer(long) is what fails, but there is no such method. There is getFilePointer(), which returns a long indicating the current position in the file, and seek(long), which goes to a new position in the file. Another point I'm confused on is exactly how you get from a RandomAccessFile to a ByteArrayInputStream. It's possible that closing that stream in some way affects your file, but I can't be sure.

Go ahead and post some code. (Remember to use code tags.) Don't post the megabyte data file though.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!