Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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");
        }
        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());
    }
}