• Post Reply Bookmark Topic Watch Topic
  • New Topic

why code gets blocked with GZipInputStream ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I m sending images from server to client so
when code hits this line it gets blocked .....I means code further to this line is not executing.

after poking my nose here and there i found that GZipInputStream's read method blocks the code untill enough data is available for decompression
but i m sending a String as then why it gets blocked ...?
what else i can do to fix it ?
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reading code is designed to read the whole stream. Apparently your writing code hasn't finished writing the whole stream. (Hint: Writing an end-of-line character doesn't signal the end of the stream.)
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also confused because you first said you were sending an image, and then the code you provided clearly sent a string and not an image. Perhaps that confusion is replicated in your code.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:The reading code is designed to read the whole stream. Apparently your writing code hasn't finished writing the whole stream. (Hint: Writing an end-of-line character doesn't signal the end of the stream.)

SO how do i signal end of the stream ?

and about your confusion , yes i m sending images but before i start sending images i am sending "key" for authentication purpose
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naved momin wrote:SO how do i signal end of the stream ?


You close it.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
naved momin wrote:SO how do i signal end of the stream ?


You close it.

But i can't do that i have to send images in every 100ms ...is there some other methods ?
and i m successfully able to stream images from client to server in my case both are single machine through ImageIcon object, but do you think this is a efficient way of sending images ?
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about "efficient" -- you would have to explain what that means to you.

But first of all I wouldn't use Java serialization, I would just send the raw bytes of the image. And if my images were JPEG files, I wouldn't use GZIP because JPEG is already a compressed format. That would at least keep things simple. (Which is one of my preferred attributes of "efficient".)
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I don't know about "efficient" -- you would have to explain what that means to you.

But first of all I wouldn't use Java serialization, I would just send the raw bytes of the image. And if my images were JPEG files, I wouldn't use GZIP because JPEG is already a compressed format. That would at least keep things simple. (Which is one of my preferred attributes of "efficient".)

my defination to efficient
1. my code should be clean
2. image size or what ever i using to transport images should be as small as possible so that it gets delivered faster

so do you mean i should use ? will this be an efficient way of sending images ?
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certainly the raw bytes of the image by themselves will be smaller than any other way of packaging those bytes.

You may have to take them and reconstruct a Java object at the receiving end, but that will probably be a fast operation compared to the cost of sending extra bytes over the network. Of course there's a large amount of guesswork in that "probably" -- if you added 500 bytes of overhead to a 3,000-byte image it would be more significant than if you added 500 bytes of overhead to a 300,000-byte image.

So I would start out with the simplest code, and then add complexities if you found it didn't run fast enough.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Certainly the raw bytes of the image by themselves will be smaller than any other way of packaging those bytes.

Well, other than possibly using some compression on those raw bytes - that could make them smaller. Not necessarily a lot smaller, and it's quite possibly not worth the added complexity. Many algorithms for text file compression don't do much good when used on image data. But it may be worthwhile to explore how much benefit can be achieved from compression. After getting things working smoothly without any compression.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!