473,516 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue in decompressing bytes

22 New Member
I'm sending 56kb of GZipped data from sending side over a socket on localhost. The receiving side (at localhost) receives it and needs to unzip it. I receive: EOFException: Unexpected end of ZLib input stream

Sender:
Expand|Select|Wrap|Line Numbers
  1. ByteArrayOutputStream b = new ByteArrayOutputStream();
  2. GZIPOutputStream g = new GZIPOutputStream(b);
  3. b.write(bData); /* bData is a byte array of 500k bytes size*/
  4. byte[] bData2 = b.toByteArray();
  5. g.close();
  6. b.close();

Expand|Select|Wrap|Line Numbers
  1. BufferedOutputStream bos = new BufferedOutputStream(socketObj.getOutputStream());
  2. bos.write(bData2); 
  3. bos.flush();       
  4. bos.close();
Receiver:
Expand|Select|Wrap|Line Numbers
  1. DataInputStream d = new DataInputStream(socketObj.getInputStream());
  2. ByteArrayOutputStream b = new ByteArrayOutputStream();
  3.  
  4. int iRead = -1;
  5. while((iRead = d.read()) != -1)
  6.     b.write(iRead);
  7.  
  8. return b.toByteArray();

Data is received properly with same no. of bytes but when i try to decompress it, I receive the above mentioned exception. Here is the code for decompressing.

Expand|Select|Wrap|Line Numbers
  1. ByteArrayInputStream b = new ByteArrayInputStream(bData);
  2. GZIPInputStream g = new GZIPInputStream(b);
Here bData contains the compressed bytes. At this point the exception is raised.


Please give some suggestion why the decompression is not working. I'm using JDK1.5
Jul 24 '09 #1
1 2844
JosAH
11,448 Recognized Expert MVP
@jeet232
You never zip anything, i.e. you're using the wrapped OutputStream directly without using the write() method of the GZIPOutputStream. The bytes are written as is and no decompression is possible on them (in the receiver).

kind regards,

Jos
Jul 25 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6785
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
0
2002
by: Stephane D. | last post by:
I have currently an issue with the following piece of code. The assembly is to run under com+ (as Library) and the class derives from ServicedComponent. Code: C# - .NET framework V1.1.4322 // Prepare fully qualified class name fullyQualifiedNetClassTypeName = Namespace + "." + ClassName + ", " + AssemblyName + ", " + "Version=" +...
13
1651
by: ma740988 | last post by:
I'm faced with endian issues during communication across different platforms. So I've recommendations/tips (from one of these newsgroups - cant recall which) on an approach (or two or three) that seems reasonable and is based on issues that were encountered and how to handle them in this situation. One of which - the one I'm currently...
0
8922
by: jimmyfingers | last post by:
I've just tried the following code for decompressing a .zip file, but get the following error message: "The magic number in GZip header is not correct. Make sure you are passing in a GZip stream." The error is on line 27: "int bytesRead = compressedZipStream.Read(smallBuffer, 0, 100);" My code is as follows: using System; using...
2
1513
by: Yoo | last post by:
Is there a good website that decompresses javascript code input? Is there also a bookmarklet that decompresses bookmarklet code? This kind of bookmarklet can be useful when studying bookmarklets from Jesse's Bookmarklets Site. By decompressing I mean changing: do{if(r=prompt((s?'>'+s+'\ncommand:':'query:'),'')){u=f...
5
1432
by: Amit | last post by:
Hi I am developing an application in C#. The application creates a TCPListener object and listens to (incoming) data on a particular port. A simulator hardware writes data to this port. My application reads the data and process it and generates some results for display. The TCPListener object waits for incoming data in a background...
3
4200
by: towers | last post by:
Hi I'm probably doing something stupid but I've run into a problem whereby I'm trying to add a csv file to a zip archive - see example code below. The csv just has several rows with carriage return line feeds (CRLF). However after adding it to an archive and then decompressing the line endings have been converted to just line feeds...
14
2384
by: n3o | last post by:
Hello Comp.Lang.C Members, I have an issue with user input that I have been trying to figure out for the longest. For instance, let's say you have something like this: void foo() { int num; printf("Please enter a number: "); scanf("%d", &num); // yes I know this function may throw a
3
1766
by: Joseph Geretz | last post by:
I'm using the Request Filter documentation which can be found here: http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx In this example, two filters are installed, one filter uppercases every alphabetic character and then the second filter replaces every 'E' with "#'. OK, very nice. What's trivial about these...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.