views:

166

answers:

1

I need to read/unpack a .gz file given a FileChannel.

I've played around with extracting GZIP archives using GZIPInputStream, but this won't take a FileChannel. I don't have access to the original FileInputStream that the FileChannel was taken from.

If someone could tell me a good way (or at least any way) of reading GZIP from a FileChannel, I would greatly appreciate it.

Adapted from a question on the Sun Oracle forums.

+2  A: 

You could obtain a wrapping InputStream around the FileChannel:

FileChannel fc = ...
GZIPInputStream gis = new GZIPInputStream(Channels.newInputStream(fc));

Channels is in Java SE.

Dan LaRocque