I am downloading a few .gz file from an FTP server and un-compressing the file to read the data. I am getting the following error.
java.io.IOException: Corrupt GZIP trailer
at java.util.zip.GZIPInputStream.readTrailer(GZIPInputStream.java:200)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:92)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at com.omnesys.xdk.ClsXDKRTWeb.UnGunZip(ClsXDKRTWeb.java:961)
at com.omnesys.xdk.ClsXDKRTWeb.DeCompress(ClsXDKRTWeb.java:857)
at com.omnesys.xdk.ClsXDKRTWeb.FTPDownloadProcess(ClsXDKRTWeb.java:629)
at com.omnesys.xdk.ClsXDKRTWeb.ProcessRequestXML(ClsXDKRTWeb.java:460)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
The code for the fTP download and un compressing is as follows.
FTPClient ftp;
FTPClientConfig config;
ftp = new FTPClient();
config = new FTPClientConfig();
ftp.configure(config);
ftp.connect(strFTPServername);
ftp.user(strFTPUserName);
ftp.pass(strFTPUserPwd);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
OutputStream local = new BufferedOutputStream(new FileOutputStream(strCmnDwnldPath));
ftp.retrieveFile(strSrcFilePath, local);
local.close();
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
ftp.disconnect();
return false;
} else {
ftp.logout()
}
private boolean UnGunZip(String filename, String outputFolder) {
byte[] buffer = new byte[1024];
try {
String sfilename = new File(filename).getName();
sfilename = sfilename.substring(0, sfilename.indexOf(".gz"));
FileInputStream fileIn = new FileInputStream(filename);
GZIPInputStream gZIPInputStream = new GZIPInputStream(fileIn);
FileOutputStream fileOutputStream = new FileOutputStream(outputFolder + File.separator + sfilename);
int count;
while ((count = gZIPInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, count);
}
gZIPInputStream.close();
fileOutputStream.close();
} catch (IOException ex) {
ex.printStackTrace();
return false;
}
return true;
}
My application runs in Linux environment. When i try to extract the file in the windows environment i get the error saying the file is broken.
When I try to download the same file from windows environment I don't face this issue.
Can someone help me fix this.
[EDIT:] i found this question, according to this the file should be uploaded as ASCII and downloaded as ASCII. But how do i find out if the file was uploaded using ASCII transfer?