This code loads an image in a BufferedImage object. ImageIO.read()
may take an InputStream as an argument.
I first tried getting an InputStream from a socket and loading. Then I tried loading the image in an array of bytes and giving this array as argument (I thought that the problem was in the connection).
Both ways work fine when I run my program through Eclipse and both of them don't work when I save my project as a runnable jar file. The code stuck at the last line.
byte[] buffer = new byte[imageBufferSize];
int count = 0;
while ((count = in.read(buffer)) != -1) {
//nothing here. Just reading in buffer in while cycle.
}
String bytesStr = new String(buffer);
int skipPos = bytesStr.indexOf("‰PNG");
byte[] newBytes = Arrays.copyOfRange(buffer, skipPos, buffer.length);
bufImg = ImageIO.read(new ByteArrayInputStream(newBytes));