All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.thksystems.util.io.IOUtils Maven / Gradle / Ivy

Go to download

Commons for lang, crypto, xml, dom, text, csv, reflection, annotations, parsing, ...

There is a newer version: 4.3.3
Show newest version
/*
 * tksCommons
 *
 * Author : Thomas Kuhlmann (ThK-Systems, http://www.thk-systems.de) License : LGPL (https://www.gnu.org/licenses/lgpl.html)
 */
package de.thksystems.util.io;

import java.io.Closeable;
import java.io.IOException;
import java.io.StringWriter;

public final class IOUtils {

    private IOUtils() {
    }

    /**
     * Copies the given {@link StringWriter}, by creating a new {@link StringWriter} and copying the string content.
     */
    public static StringWriter copyStringWriter(StringWriter sourceWriter) {
        sourceWriter.flush();
        StringWriter targetWriter = new StringWriter();
        targetWriter.write(sourceWriter.toString());
        targetWriter.flush();
        return targetWriter;
    }

    /**
     * Closes the {@link Closeable} (e.g. a {@link java.io.InputStream or a {@link java.io.OutputStream}}) without throwing (or logging any exception)!
     * 

* Use with care! */ public static void closeQuietly(Closeable closeable) { if (closeable == null) return; try { closeable.close(); } catch (IOException e) { } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy