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

voidcloseCloseableIfNotNull(Closeable fileWriter)
close Closeable If Not Null
if (fileWriter != null) {
    try {
        fileWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
voidcloseConnection(Closeable... closes)
close Connection
for (Closeable close : closes) {
    try {
        if (close != null) {
            close.close();
    } catch (IOException e) {
        e.printStackTrace();
voidcloseDataLine(final SourceDataLine line, final AudioInputStream ais)
close Data Line
line.drain();
line.stop();
line.close();
ais.close();
voidcloseDebugFile()
close Debug File
debugFileName = null;
if (debugStream == null) {
    return;
debugStream.close();
debugStream = null;
voidcloseEL(InputStream is)
close inputstream without a Exception
try {
    if (is != null)
        is.close();
} catch (Throwable e) {
voidcloseEntry(ZipOutputStream... outputStreams)
Equivalent to ZipOutputStream#closeEntry() but without checked exception.
for (final ZipOutputStream outputStream : outputStreams) {
    try {
        outputStream.closeEntry();
    } catch (final IOException e) {
        throw new RuntimeException(e);
voidcloseFile()
close File
writer.close();
voidcloseFile()
close File
try {
    writer.close();
} catch (IOException e) {
    e.printStackTrace();
voidcloseFile(File file, boolean toBeDeleted)
Closes the file handle for temporary file.
if (file != null) {
    updateFileHandle(file, null, true);
    if (toBeDeleted) {
        boolean deleted = file.delete();
        if (!deleted) {
            throw new IOException("Failed to delete temporary file " + file.getName());
voidcloseFile(File file, RandomAccessFile raf)
Close the file and automatically releases the FileLock (if any) and removes the advisory lock for that file (if any).
if (file == null)
    throw new IllegalArgumentException();
if (raf == null)
    throw new IllegalArgumentException();
try {
    if (raf.getChannel().isOpen()) {
        raf.close();
} finally {
    removeAdvisoryLock(file);