From ac6b503adf42a2fbfe7d230092fd926ece6d3e68 Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 28 Oct 2010 23:12:33 +0000 Subject: [PATCH] untar files without gzip decompression even if the file has gz extension. this is done when the decompression fails. decompressed gzip files with gz extension may appear if the server sets a gzip compression header git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7282 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/tools/tarTools.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/de/anomic/tools/tarTools.java b/source/de/anomic/tools/tarTools.java index 7ef0121c7..dc41c63a6 100644 --- a/source/de/anomic/tools/tarTools.java +++ b/source/de/anomic/tools/tarTools.java @@ -29,6 +29,7 @@ package de.anomic.tools; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.util.zip.GZIPInputStream; @@ -41,8 +42,17 @@ import org.apache.tools.tar.TarInputStream; public class tarTools { public static InputStream getInputStream(final String tarFileName) throws Exception{ - if(tarFileName.endsWith(".gz")){ - return new GZIPInputStream(new FileInputStream(new File(tarFileName))); + if (tarFileName.endsWith(".gz")) { + try { + return new GZIPInputStream(new FileInputStream(new File(tarFileName))); + } catch (IOException e) { + // this might happen if the stream is not in gzip format. + // there may be a 'gz' extension, but it may stil be a raw tar file + // this can be caused by 'one too much gzip-content header' that was attached + // by a release file server + // so just try to open is as normal stream + return new FileInputStream(new File(tarFileName)); + } } return new FileInputStream(new File(tarFileName)); }