Example usage for java.io InputStream close

List of usage examples for java.io InputStream close

Introduction

In this page you can find the example usage for java.io InputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    ZipFile zf = new ZipFile("a.zip");
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        FileOutputStream fout = new FileOutputStream(ze.getName());
        InputStream in = zf.getInputStream(ze);
        for (int c = in.read(); c != -1; c = in.read()) {
            fout.write(c);/*from w w  w. j av a 2s.co  m*/
        }
        in.close();
        fout.close();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    ZipFile zf = new ZipFile(args[0]);
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        System.out.println("Unzipping " + ze.getName());
        FileOutputStream fout = new FileOutputStream(ze.getName());
        InputStream in = zf.getInputStream(ze);
        for (int c = in.read(); c != -1; c = in.read()) {
            fout.write(c);//from  ww w  .ja  v a  2  s  .  c o m
        }
        in.close();
        fout.close();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    String hostname = "time.nist.gov";
    int port = 37;

    InputStream raw = null;
    Socket theSocket = new Socket(hostname, port);
    raw = theSocket.getInputStream();//  w w w.  j  av  a2s .co m

    System.out.println(raw.read());

    raw.close();
}

From source file:InputStreamEnumerator.java

public static void main(String args[]) throws IOException {

    int c;//from ww w. ja  va 2  s . c  o m
    Vector<String> files = new Vector<String>();

    files.addElement("c:\\autoexec.bat");
    files.addElement("c:\\config.sys");
    InputStreamEnumerator e = new InputStreamEnumerator(files);
    InputStream input = new SequenceInputStream(e);

    while ((c = input.read()) != -1) {
        System.out.print((char) c);
    }

    input.close();
}

From source file:net.nicoll.boot.metadata.Sample.java

public static void main(String[] args) throws IOException {
    ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
    for (InputStream resource : getResources()) {
        try {//from w ww .  jav  a2s  .  c o  m
            builder.withJsonResource(resource);
        } finally {
            resource.close();
        }
    }
    ConfigurationMetadataRepository repo = builder.build();
    System.out.println(getMetadataFormatter().formatMetadata(repo));
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    URL url = new URL("http://www.google.com");
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();

    InputStream inStrm = httpCon.getInputStream();
    System.out.println("\nContent at " + url);
    int ch;//ww w.  j  a va 2s. co m
    while (((ch = inStrm.read()) != -1))
        System.out.print((char) ch);
    inStrm.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    InputStream stream = Main.class.getResourceAsStream("test.png");
    BufferedImage image = ImageIO.read(stream);
    int iw = image.getWidth();
    int ih = image.getHeight();
    stream.close();

    for (int y = 0; y < ih; y++) {
        for (int x = 0; x < iw; x++) {
            int pixel = image.getRGB(x, y);
            int alpha = (pixel >> 24) & 0xFF;
            int red = (pixel >> 16) & 0xFF;
            int green = (pixel >> 8) & 0xFF;
            int blue = pixel & 0xFF;
        }// w  ww .  j  a va 2  s  .c o  m
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    int c;/*from   www .  ja va2  s  .  c o m*/
    URL hp = new URL("http", "www.java2s.com", 80, "/");
    URLConnection hpCon = hp.openConnection();
    if (hpCon.getContentLength() > 0) {
        InputStream input = hpCon.getInputStream();
        int i = hpCon.getContentLength();
        while (((c = input.read()) != -1) && (--i > 0)) {
            System.out.print((char) c);
        }
        input.close();
    } else {
        System.out.println("No Content Available");
    }
}

From source file:Main.java

public static void main(String[] args) {
    byte[] b = { 'h', 'e', 'l', 'l', 'o' };
    try {/*from  w w  w  .j  av  a  2  s .  c  om*/

        OutputStream os = new FileOutputStream("test.txt");

        InputStream is = new FileInputStream("test.txt");

        os.write(b, 0, 3);

        for (int i = 0; i < 3; i++) {
            System.out.print((char) is.read());
        }
        os.close();
        is.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:FileInputOutputExample.java

public static void main(String[] args) throws Exception {

    InputStream is = new FileInputStream("in.txt");
    OutputStream os = new FileOutputStream("out.txt");
    int c;//  w  w  w  .  j av  a 2 s.  co m
    while ((c = is.read()) != -1) {
        System.out.print((char) c);
        os.write(c);
    }
    is.close();
    os.close();

}