From: Jochen H. <Hoe...@In...> - 2004-02-26 10:23:32
|
On Thursday 26 February 2004 10:45, John Leuner wrote: > -----Forwarded Message----- >=20 > From: Brett Trotter <btr...@us...> > To: je...@us... > Subject: GZipInputStream > Date: 25 Feb 2004 22:48:11 -0800 >=20 > How would one go about being able to seek through a GZip'd file? > Seeking ahead could be done by reading bytes normally and discarding > the bytes.=20 Yes, or use skip(), which does more or less the same. > But seeking backwards? Would I have to seek to the beginning and > seek forward to the right position for every backward seek? This isn't possible. You would have to create a new GZipInputStream to start from the beginning and then skip to the position. This also requires to create a new underlying stream. If you read from stdin this wouldn't work at all. If you need to seek very much and you don't have so much data it might be better to read everything into a ByteArray first and then use a ByteArrayInputStream. If you have a big file and only want to seek on the header (e.g. for detecting file type), you can also write a new =46ilterInputStream that caches the header and allows seeking there. Regards, Jochen =2D-=20 Jochen Hoenicke, University of Oldenburg, 26111 Oldenburg, Germany Email: hoe...@in... Tel: +49 441 798 3124 |