Java Stream Close closeProcessStreams(Process p)

Here you can find the source of closeProcessStreams(Process p)

Description

close Process Streams

License

GNU General Public License

Declaration

public static void closeProcessStreams(Process p) 

Method Source Code

//package com.java2s;
/*//from   w w  w. j a  va 2 s . co  m
 * Copyright (C) 2015  University of Oregon
 *
 * You may distribute under the terms of either the GNU General Public
 * License or the Apache License, as specified in the README file.
 *
 * For more information, see the README file.
 */

import java.io.*;

public class Main {
    public static void closeProcessStreams(Process p) {
        if (p != null) {
            closeQuietly(p.getOutputStream()); // process's STDIN [sic]
            closeQuietly(p.getInputStream()); // process's STDOUT [sic]
            closeQuietly(p.getErrorStream()); // process's STDERR
        }
    }

    public static void closeQuietly(Object obj) {
        if (obj != null) {
            if (obj instanceof Closeable) {
                try {
                    ((Closeable) obj).close();
                } catch (Exception e) {
                }
            } else {
                throw new ClassCastException("Not a closable Object");
            }
        }
    }
}

Related

  1. closeOutputStream(OutputStream outputStream)
  2. closePermanentOutputWriter()
  3. closePort()
  4. closePrintWriter(PrintWriter fileOutputStream)
  5. closeProcess(Process process)
  6. closeProofWriter(Writer out)
  7. closeProtectedStream(final OutputStream outputStream)
  8. closeQietly(ZipFile zipFile)
  9. closeQuietly(@Nullable ObjectInput in)