Here you can find the source of iconFromStream(final InputStream in)
public static ImageIcon iconFromStream(final InputStream in) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import javax.swing.ImageIcon; public class Main { public static ImageIcon iconFromStream(final InputStream in) throws IOException { if (in == null) { throw new IllegalArgumentException("Stream must not be null"); }/*from w w w . j a v a 2s. c o m*/ final ByteArrayOutputStream out = new ByteArrayOutputStream(); final byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) > 0) { out.write(buffer, 0, read); } in.close(); return new ImageIcon(out.toByteArray()); } }