Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Problem transfering JPG using RMI

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I'm programming a client-server application, where the client ask the server for a jpg file. The server then transfers the file (if found) to the client. I'm having a strange issue where all of the jpg bytes are transfered but when I go to the folder where the client keeps the file, and I try to open the file, my Image Viewer (I'm using GNOME) says "Could not load image 'nameOfFile.jpg'. Error interpreting JPEG image file (Not a JPEG file: starts with 0x00| 0x00".

This also happened to me doing the same application but using sockets instead of RMI, and happens also when using Windows instead of Ubuntu. I'm not sure what I am doing wrong. I'll be thankful if anyone can help me.
Posts: 8
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the io streams you are using. You may not be writing the file properly.
Posts: 21950
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you transferring the JPG through RMI?

Communication in RMI is as follows:
- the client sends method call request with all arguments in serialized form to the server
- the server executes the method with the given deserialized arguments
- the server sends the return value in serialized form to the client
- the client gets the deserialized return value

As you see, any changes to the arguments will not be seen by the client. For instance, the following method will not do what you expect when used in RMI:
The server modifies the StringBuilder, but this is not the client's StringBuilder - it's a copy. This copy is not synchronized with the client's copy.

So if your transfer method passes a byte[] to the RMI server's method like in and you expect it to be modified - well, it won't.
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you verifying that:

all of the jpg bytes are transfered


Are you sure that you are always treating the contents as byte[]? As Nisha said, check your use of streams - watch out for treating the bytes as characters, for example by creating a String or using a Writer or Reader.

Due to unicode character conversions, an image will not survive being treated as char[] or String.


Ever since I found this suit I've felt strange new needs. And a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic