import java.net.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import javax.imageio.ImageIO;

public class CameraClient {
    private String hostIP;
    private int serverPort;
    private Socket client;
    private OutputStream out;
    private InputStream in;
    
    public CameraClient(String hostIP, int serverPort) {
        this.hostIP = hostIP;
        this.serverPort = serverPort;
    }
    public CameraClient() {}
    public void sethostIP(String hostIP) {
        this.hostIP = hostIP;
    }
    public void setServerPort(int port) {
        this.serverPort = port;
    }
    public String getHostIP() {
        return hostIP;
    }
    public int getServerPort() {
        return serverPort;
    }
    public void initSocket() {
        try {
            this.client = new Socket(hostIP, serverPort);
            this.out = this.client.getOutputStream();
            this.in = this.client.getInputStream();
            System.out.println("Client socket successfully initialized.");
        } catch (IOException e) {
            System.out.println("Error Initializing Socket or Input/Output Streams");
        }
        
    }
    public void writeString(String s) {
        try {
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
            bw.write(s);
            bw.close();
        } catch (IOException e) {
            System.out.println("Error writing string to socket.");
        }
    }
    public String readSocketString() {
        String s = null;
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            s = br.readLine();
            br.close();
        } catch (IOException e) {
            System.out.println("Error reading string from socket.");
        }
        return s;
    }
    private byte[] readSocketBytes() {
        ByteArrayOutputStream bs = null;
        try {   
            bs = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            for (int s = 0; (s = in.read(buffer)) != -1; ) {
                bs.write(buffer, 0, s);
            }
        } catch (IOException e) {
            System.out.println("Error reading bytes from socket.");
        }
        return bs.toByteArray();
    }
    public BufferedImage readImage() {
        BufferedImage img = null;
        try {
            byte[] inBytes = readSocketBytes();
            InputStream imageIn = new ByteArrayInputStream(inBytes);
            img = ImageIO.read(imageIn);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return img;
    }
    public static void main(String[] args) {
        CameraClient driveStation = new CameraClient("172.17.125.210", 5439);
        driveStation.initSocket();
        byte[] bytes = driveStation.readSocketBytes();
        
        System.out.println(Arrays.toString(bytes));
        
        try {  
            BufferedImage img = driveStation.readImage();
            ImageIO.write(img, "jpg", new File("socketTest.jpg"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

@@ -50,27 +50,34 @@
 awt.
-image.BufferedI
+*;%0Aimport java.awt.i
 mage
+.*
 ;%0Aim
@@ -128,16 +128,38 @@
 ImageIO;
+%0Aimport javax.swing.*;
 %0A%0Apublic
@@ -2337,16 +2337,37 @@
 adImage(
+int width, int height
 ) %7B%0A    
@@ -2474,103 +2474,418 @@
     
-InputStream imageIn = new ByteArrayInputStream(inBytes);%0A            img = ImageIO.read(imageIn
+DataBuffer buffer = new DataBufferByte(inBytes, inBytes.length);%0A            WritableRaster raster = Raster.createInterleavedRaster(buffer, width, height, 3*width, 3, new int%5B%5D%7B0,1,2%7D, (Point)null);%0A            ColorModel cm = new ComponentColorModel(ColorModel.getRGBdefault().getColorSpace(), false, true, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);%0A            img = new BufferedImage(cm, raster, true, null
 );%0A 
@@ -3338,16 +3338,21 @@
 adImage(
+10,10
 );%0A     
@@ -3362,60 +3362,51 @@
     
-ImageIO.write(img, %22jpg%22, new File(%22socketTest.jpg%22)
+DisplayImage testImg = new DisplayImage(img
 );%0A 
@@ -3485,10 +3485,507 @@
 %7D%0A    %7D%0A
+    private static class DisplayImage %7B%0A        public DisplayImage(BufferedImage img) throws IOException %7B%0A            ImageIcon icon = new ImageIcon(img);%0A            JFrame frame = new JFrame();%0A            frame.setLayout(new FlowLayout());%0A            frame.setSize(200,300);%0A            JLabel lbl = new JLabel();%0A            lbl.setIcon(icon);%0A            frame.add(lbl);%0A            frame.setVisible(true);%0A            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);%0A        %7D%0A    %7D%0A
 %7D%0A

Test Image Displayer