Java Utililty Methods Stream Close

List of utility methods to do Stream Close

Description

The list of methods to do Stream Close are organized into topic(s).

Method

voidcloseProcess(Process process)
close Process
try {
    process.getInputStream().close();
    process.getOutputStream().close();
    process.getErrorStream().close();
} catch (IOException e) {
process.destroy();
try {
...
voidcloseProcessStreams(Process p)
close Process Streams
if (p != null) {
    closeQuietly(p.getOutputStream()); 
    closeQuietly(p.getInputStream()); 
    closeQuietly(p.getErrorStream()); 
WritercloseProofWriter(Writer out)
close Proof Writer
return new Writer(out) {
    @Override
    public void close() throws IOException {
    @Override
    public void write(char[] cbuf, int off, int len) throws IOException {
        out.write(cbuf, off, len);
    @Override
    public void flush() throws IOException {
        out.flush();
};
OutputStreamcloseProtectedStream(final OutputStream outputStream)
close Protected Stream
return new OutputStream() {
    @Override
    public void write(int b) throws IOException {
        outputStream.write(b);
    @Override
    public void close() throws IOException {
};
voidcloseQietly(ZipFile zipFile)
close Qietly
try {
    zipFile.close();
} catch (final IOException e) {
    throw new RuntimeException(e);
voidcloseQuietly(@Nullable ObjectInput in)
Method that will close an ObjectInput ignoring it if it is null and ignoring exceptions.
if (in != null) {
    try {
        in.close();
    } catch (IOException e) {
voidcloseQuietly(BufferedReader br)
close Quietly
if (br != null) {
    try {
        br.close();
    } catch (IOException e) {
voidcloseQuietly(Closeable input, Logger log)
Close I/O object quietly without exception but using external logger for logging errors if any
try {
    if (input != null) {
        input.close();
} catch (IOException ioe) {
    log.warn("'close' invocation exception for resource: " + input.getClass().getName(), ioe);
voidcloseQuietly(Closeable stream)
Close a stream, ignores checked Exceptions and nulls, but rethrows RuntimeExceptions.
if (stream != null) {
    try {
        stream.close();
    } catch (RuntimeException rethrow) {
        throw rethrow;
    } catch (Exception e) {
        logger.warn(e.getMessage());
voidcloseQuietly(Closeable stream)
Unconditionally close an InputStream.
try {
    if (stream != null) {
        stream.close();
} catch (IOException ioe) {