So I have an image cache set up for what could very likely be pretty big images that I’d rather not re-render if I don’t have to. The problem is that this quickly eats up all of my memory (we’re talking on the order of 100 MB or more). And seeing as how I don’t need to have ALL of the images displayed at once (in fact, I really only need a few of them), I want to take the image data for the rest of them and compress them, and then uncompress them into full-out images when I need to draw them (and forget about the previous uncompressed image data, as I won’t be displaying it anymore).
I know that Java comes with some Zip utilities, but most of this looks like it wants to work with FILES rather than just data in memory. I would prefer to leave the filesystem out of this completely, as there’s no point in saving these images to disk. (It just takes a while to render each one, and I don’t want the user to have to wait forever each time they look at one they’ve already seen – I’m talking specifically about pages in a PDF document, if that helps clarify at all.)
I have also found an ObjectOutputStream, and an equivalent input stream, but these require Serializable objects, and I can’t find any image classes that are. And even if it there were, I can’t find a way to take an OutputStream and use its data (perhaps right away) as an InputStream without writing to disk and reading the file back.
In a nutshell, I need to:
- Compress image data in memory (zip would be fine)
- Access compressed image data in memory
- Decompress data in memory to an Image
Does anyone have any ideas on even where to get started with this?