import java.util.zip.Deflater;

int myInteger = 137; //starting value

Integer mi = new Integer(myInteger);
String classOfMyInteger = mi.getClass().toString();
System.out.println("my starting int is " + myInteger + " I placed it in a wrapper class of type " + classOfMyInteger);

char[] myIntChars = Integer.toBinaryString(mi).toCharArray();

System.out.print(" myInt converted to a char array is: ");

CharArrayReader reader = new CharArrayReader(myIntChars);
int k = 0;
while ((k = reader.read()) != -1) {  
    char ch = (char) k;  
    System.out.print(ch);  
}  
System.out.println("");  //make sure output will be on a new line

System.out.println("now I will use a class called a deflator to compress the char array into a byte array");
System.out.println("... honestly I chose this because I was looking at built-in java classes and found the deflator and inflator classes");
byte[] dataToCompress = (new String(myIntChars)).getBytes("UTF-8");
// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(dataToCompress);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
compresser.end();

System.out.println("the compressed data is: " + Base64.getEncoder().encodeToString(output) + " with a length of " + compressedDataLength + "bytes");
my starting int is 137 I placed it in a wrapper class of type class java.lang.Integer
 myInt converted to a char array is: 10001001
now I will use a class called a deflator to compress the char array into a byte array
... honestly I chose this because I was looking at built-in java classes and found the deflator and inflator classes
the compressed data is: eJwzNDAwMAQiAAbVAYQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== with a length of 14bytes
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

public class DisplayImage {

    public static void main(String avg[]) throws IOException
    {
        DisplayImage abc=new DisplayImage();
    }

    public DisplayImage() throws IOException
    {
        BufferedImage img=ImageIO.read(new File("/home/kasm-user/vscode/CSA1/images/logo.png"));
        ImageIcon icon=new ImageIcon(img);
        JFrame frame=new JFrame();
        frame.setLayout(new FlowLayout());
        frame.setSize(200,300);
        JLabel lbl=new JLabel();
        lbl.setIcon(icon);
        frame.add(lbl);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        System.out.println(icon); //this is purely for the output in jupyter notebooks
        System.out.println("it will display an error below when the window closed");
    }
}

DisplayImage myImage = new DisplayImage();
javax.swing.ImageIcon@31c0cba3
it will display an error below when the window closed



The Kernel crashed while executing code in the current cell or a previous cell. 


Please review the code in the cell(s) to identify a possible cause of the failure. 


Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. 


View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.