September 09, 2010, 02:03:28 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: java.util.zip.DataFormatException: incorrect data check  (Read 1533 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« on: March 18, 2009, 06:21:19 PM »

I want to unzip a file over a socket connection, while it works with small chunks of data, i get a "java.util.zip.DataFormatException: incorrect data check" when retrieving larger files.
 
client code:
 
Code
GeSHi (java):
  1. byte[] bytesOut = baos.toByteArray();
  2.  
  3. Deflater compressor = new Deflater();
  4. compressor.setLevel(Deflater.BEST_SPEED);
  5.  
  6. compressor.setInput(bytesOut);
  7. compressor.finish();
  8.  
  9. ByteArrayOutputStream bos = new ByteArrayOutputStream(bytesOut.length);
  10.  
  11. byte[] buf = new byte[100];
  12. while (!compressor.finished()) {
  13. int count = compressor.deflate(buf);
  14. bos.write(buf, 0, count);
  15. }
  16. try {
  17. bos.close();
  18. } catch (IOException e) {
  19. e.printStackTrace();
  20. }
  21.  
  22. byte[] compressedData = bos.toByteArray();
  23. System.out.println("COMPRESSED " + compressedData.length);
  24. OutputStream out=skt.getOutputStream();
  25. out.write(compressedData);
  26. out.close();
  27. skt.close();
Created by GeSHI 1.0.7.20

server code

Code
GeSHi (java):
  1. InputStream in =  skt.getInputStream();
  2. byte[] buffer = new byte[100];
  3. int bytesRead = -1;
  4. while((bytesRead = in.read(buffer)) > -1) {
  5. out.write(buffer, 0, bytesRead);
  6. }
  7. in.close();
  8. byte[] imageBytes = out.toByteArray();
  9.  
  10. Inflater decompressor = new Inflater();
  11. decompressor.setInput(imageBytes);
  12.  
  13. ByteArrayOutputStream bos = new ByteArrayOutputStream(imageBytes.length);
  14.  
  15.  
  16. while (!decompressor.finished()) {
  17. try {
  18. int count = decompressor.inflate(imageBytes);
  19. bos.write(imageBytes, 0, count);
  20.  
  21. } catch (DataFormatException e) {
  22. e.printStackTrace();
  23. }
  24. }
  25. try {
  26. decompressor.end();
  27. bos.close();
  28. } catch (IOException e) {
  29. e.printStackTrace();
  30. }
Created by GeSHI 1.0.7.20

Is there some limitation when reading compressed data trough the net or is my code not efficient enough to do so? I haven't done similiar things before so i might have missed something important.

Thanks
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
« on: March 18, 2009, 06:21:19 PM »

 Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« Reply #1 on: March 21, 2009, 08:35:09 AM »

Nevermind, fixed.
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
gluk
Member
*

Reputation: 0
Offline Offline
Posts: 22
Referrals: 0

Awards
« Reply #2 on: April 21, 2009, 05:52:17 PM »

The solution for most of the Java related errors can be found at this site: Java errors and solutions.
« Last Edit: April 22, 2009, 12:44:15 PM by HappyFace » Logged
Javaforums.net :: a community about Java software development.
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.265 seconds with 34 queries.

Google visited last this page Yesterday at 07:20:36 PM