简体   繁体   中英

Delphi to Java code conversion

how can i convert the specific code written in Delphi to JAVA

  try

    LLine := TMemoryStream.Create;
    IdTCPClient1.IOHandler.WriteLn('atext');

    IdTCPClient1.IOHandler.ReadStream(LLine, -1);

    LLine.Position := 0;  
    LLine.Read(intval, 4); //the server is sending memstream as integer + ajpeg image

    Image1.Picture.Graphic.LoadFromStream(LLine);


  finally
   //free
  end;

the above code works perfectly with Delphi , but now i want to create a java client too , but my own conversion is giving me error(java)

 Image image = null ;
 Socket socket = new Socket(someIP, myport);

My conversion is

      InputStream in = socket.getInputStream();
      OutputStream out = socket.getOutputStream();

         String string = "atext\n";

         byte buffer[] = string.getBytes();
         out.write(buffer);

    in.skip(4); // i don't want the integer

   image = ImageIO.read(in);

the server is getting the text atext perfectly , but my java client is having a problem always image is showing a null value (i assigned a breakpoint and checked it );

The ImageIO.read(InputStream input) documentation says:

If no registered ImageReader claims to be able to read the resulting stream, null is returned.

So the null value seems to be normal in this case. Have you checked that a matching ImageReader is registered ? (For example by loading an existing, valid reference image file)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM