Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Byte Array convert to Image

793912Dec 23 2008 — edited Dec 25 2008
Hi all
I need to covert a byte array from a server to a image at client.

Folowing is the code
Server.java
public static byte[] getImageasByteArray()
    {
      // implementation goes here
    }

public static void main(String args[])
    {
        ServerSocket sock = null;                       
        Socket clientSocket = null;                   
        PrintWriter pw = null;                            
        
        try
        {
            sock = new ServerSocket(serverPort);            
            clientSocket = sock.accept();                               
            pw = new PrintWriter(clientSocket.getOutputStream(), true);

            // other codes goes here

            pw.println(getImageasByteArray()); 

        } 
       catch (Throwable e)
        {
            ....
        }
    }
Does any one know a suitable code for the client side? I'm implement the client on j2me platform. Since I have at the client
InputStream is = sc.openInputStream();
DataInputStream dataInputStream = new DataInputStream(is);
Some how I need to get the byte array and convert it into image. Following is the normal string buffer case at client . How can I convert this back to image
StringBuffer results = new StringBuffer();
            
            int inputChar;
            while ((inputChar = dataInputStream.read()) != -1)
            {
            results.append((byte) inputChar);
            }
            
            is.close();
            dataInputStream.close();
            sc.close();
Please help me
Thabnk You
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 22 2009
Added on Dec 23 2008
5 comments
1,417 views