• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

invalid entry size (expected 7486146 but got 7486147 bytes) error

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... not sure where this topic belongs, but the ranch office is definitely not the correct forum for this.


Since there is mention of zip and ftp, let's try the other api forum first. Or maybe the streams forum is better ... not sure. Regardless, moved.

Henry
 
Deepak Amar
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys if anyone knows the solution for it then please suggest..
I have struggled a lot for this...
 
Ranch Hand
Posts: 121
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like a common problem with FTP.

Most likely you transfer your files as Ascii files (this is default mode for FTP). And zip files are definitely not ascii so they get corrupted at some stage. You should explicitly set file type to binary by calling FTPClient.setFileType(FTP.BINARY_FILE_TYPE) before any transfer (but after connecting and logging in).
 
Deepak Amar
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maxim Karvonen wrote:Looks like a common problem with FTP.

Most likely you transfer your files as Ascii files (this is default mode for FTP). And zip files are definitely not ascii so they get corrupted at some stage. You should explicitly set file type to binary by calling FTPClient.setFileType(FTP.BINARY_FILE_TYPE) before any transfer (but after connecting and logging in).



I had tried with Binary but it was giving error, so i removed it..
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Amar wrote:
I had tried with Binary but it was giving error, so i removed it..



For ZIP files, which is a binary file format, you definitely need to use the binary option. Basically, you tried the binary option, got an error, and created another error to mask the first error. Now, you have more errors -- albeit, not all of them will show up as compile errors.

Recommendation is to fix the binary issue, then tackle the error caused by that.

Henry
 
Deepak Amar
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Deepak Amar wrote:
I had tried with Binary but it was giving error, so i removed it..



For ZIP files, which is a binary file format, you definitely need to use the binary option. Basically, you tried the binary option, got an error, and created another error to mask the first error. Now, you have more errors -- albeit, not all of them will show up as compile errors.

Recommendation is to fix the binary issue, then tackle the error caused by that.

Henry



Thank you so much Maxim and Henry for your help and I really appreciate your prompt replies.
Actually i was setting binary file type after connecting and before logging into the FTP.
Thanks again Maxim for pointing out that..(setting of binary file type before connecting and logging in)
I was struggling to fix this since so long. It is finally resolved..

Thanks and Regards,
Deepak Amar
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Amar wrote:
Thanks again Maxim for pointing out that..(setting of binary file type before connecting and logging in)
I was struggling to fix this since so long. It is finally resolved..




And thanks for returning to inform us that is has been resolved. Have a cow. One for Maxim too.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic