1

I'm trying to use a BufferedInputStream to load an external DICOM file, but it eventually runs out of memory. When I used an InputStream, this never came up (I did this when I was loading the file through the assets folder).

I created my own producer-consumer threads to buffer the file, so I don't actually need the BufferedInputStream, but I DO need to use mark() and reset() which is not available in FileInputStream.

How should I go around this? Is there another kind of InputStream that I can use with a File which has the mark()/reset() functions? Can I empty the buffer somehow before the BufferedInputStream throws the error? Or should I find a way around using mark() instead?

Thanks for your input.

5
  • how big of a buffer are you using? Commented Nov 18, 2011 at 16:35
  • I'm using the default value (I believe that's 8024 or so). I can't create a buffer that's the size of the file because it's too big, so I have to read it in chunks. Commented Nov 18, 2011 at 16:43
  • is it possible that the chunks are too big? Have you tried smaller buffer sizes? Commented Nov 18, 2011 at 16:51
  • Hmm, not yet. I'll try and get back to you on that. Thanks! Commented Nov 18, 2011 at 16:52
  • Ok, I tried using 4096 and 1024 buffer sizes, but both still throw oom errors. From what I can tell, it's crashing after the same number of reads. Commented Nov 18, 2011 at 16:57

1 Answer 1

3

For mark and reset to work with buffered input the file points between the mark and reset need to remain in memory.

Workarounds depend on what you're actually trying to do; if you just need to start reading from a known location, perhaps a RandomAccessFile.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.