I am trying to parse data from a file of type .FTR which is inside a zip file placed at an FTP location. It has almost > 34000 lines.
The parser which is written takes input in the form of InputStream and parses the file using ZipInputStream.
Part of parser code:
public void parse(InputStream inputStream){
ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry entry = null;
while((entry = zis.getNextEntry()) != null)
{
reader = new BufferedReader(new InputStreamReader(zis));
parseData(reader );
}
}
There are two ways to input the file to the parser. Either to download that file from FTP, pass it to the Parser manually from the UI or there is code to download that from FTP and pass an InputStream to Parser.
Code to download from FTP site:
FTPClient ftp = new FTPClient();
ftp.connect(host);
ftp.login(user, pass);
FTPFile[] files = ftp.listFiles(file);
ByteArrayOutputStream outputStream = null;
for(int i=0;i<files.length;i++)
{
try
{
outputStream = new ByteArrayOutputStream();
ftp.retrieveFile(files[i].getName(), outputStream);
bytes = outputStream.toByteArray();
if (null == bytes || 0 == bytes.length)
continue;
parse(new ByteArrayInputStream(bytes));// call the parser's parse function to parse the data
}
catch(Exception e){
e.printStackTrace();
}
}
When i manually download the file from FTP and pass it to the parser from UI then it works.
But when i
test it with the download code where i have used FTPClient to download the zip file then it gives invalid entry size (expected 7486146 but got 7486147 bytes).
FTPClient works for other types of file but it fails for zip
Please suggest.
I tried to google for this issue but still no progress.