Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FileInputStream problems?
#2
KajitiSouls Wrote:Mmm yes Java...

I have a problem with my code, named Browser. It's basically a sophisticated object that can hold another instance of itself. In that sense, it's kinda like a linked list object. One of its nonstatic properties is a FileInputStream, and the way it is built right now, they're all suppose to go to the same file the original Browser was instantiated for. However, each FileInputStream is suppose to be able to work independently of each other, or that's the theory anyways.

Now here's the problem: these FileInputStreams are behaving in a rather unexpected way. At some point shortly after the next Browser object in the chain is created, something fks up and its FileInputStream somehow ends up 10 bytes behind the expected position. Is there something about these input streams that I should know about?

The code that seems to bring up the most of this strange error:
Code:
Browser browse = new Browser(stuuufffff);
browse.lookIn("cash"); //sometimes screws up, depending on edits.
browse.back();
browse.lookIn("cash"); //WILL screw up!

Code here (site seems to be plagued with popups lately). Certain parts are edited due to confidentiality reasons. Of particular interest are methods navigateTo, the various read methods at the bottom, and lookIn. The read methods were copy pasta from previous projects that have proven themselves to work, so I highly doubt those are the problem, but then again one never knows. The two places where the problems start occurring are at lines 66 and 119.

Haven't looked at your code, but if you want the FileInputStreams to operate independently of each other, you have to "copy" the FileInputStream by opening the file again and seeking the new FileInputStream to the position of the old FileInputStream. A FileInputStream has an internal seek position and simply assigning FileInputStream stream2 = stream1; does not make a copy of the object. Sometimes stream classes have an internal buffer with its own seek pointer separate from the file seek pointer. Check the documentation and google to see if seeking is supposed to behave normally with that class.

A debugger may also help.
Reply


Messages In This Thread
FileInputStream problems? - by KajitiSouls - 2010-02-03, 02:16 AM
FileInputStream problems? - by Spaz - 2010-02-03, 03:48 PM
FileInputStream problems? - by XTOTHEL - 2010-02-04, 02:37 PM
FileInputStream problems? - by KajitiSouls - 2010-02-04, 10:49 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)