1

Possible Duplicate:
In Java: How to zip file from byte[] array?

Here's the deal, I work at a university web office and we provide a few website templates for university departments and clubs. I have been tasked with building a web form that will allow them to select the template they want and provide a title which will be programmatically inserted into the template they select before downloading.

My question is, can I pull the template into memory, insert the title and output it to a zip archive without writing a temporary file to disk?

It seems that Java's ZipEntry requires a filename and cannot simply use data already in memory.

Community
  • 1
  • 1
jcksncllwy
  • 11
  • 3

2 Answers2

4

No, the name "file name" is probably a little bit confusing here but it means the file name of entry in ZIP archive you are creating. Take a look on ZipOutputStream. It is created as a wrapper over every other output stream, either FileOutputStream or ByteArrayOutputStream. Using ByteArrayOutputStream you can create zip archive completely in memory.

AlexR
  • 114,158
  • 16
  • 130
  • 208
1

It's because unlike GZIP, ZIP can compress multiple files.

So while you have to provide a file name (which will be recorded in the zip file), that doesn't mean the file has to physically exist in the filesystem. It's just the name that will be given to the file in the archive.

biziclop
  • 48,926
  • 12
  • 77
  • 104