aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/main/java/com/yahoo/jdisc/handler/ContentInputStream.java
blob: 07c716b6ef0e51902d740b416332a2ee416691d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;

/**
 * This class extends {@link UnsafeContentInputStream} and adds a finalizer to it that calls {@link #close()}. This
 * has a performance impact, but ensures that an unclosed stream does not prevent shutdown.
 *
 * @author Simon Thoresen Hult
 */
public final class ContentInputStream extends UnsafeContentInputStream {

    /**
     * Constructs a new ContentInputStream that reads from the given {@link ReadableContentChannel}.
     *
     * @param content The content to read the stream from.
     */
    public ContentInputStream(ReadableContentChannel content) {
        super(content);
    }

    @Override
    @SuppressWarnings("deprecation")  // finalize() is deprecated from Java 9
    public void finalize() throws Throwable {
        try {
            close();
        } finally {
            super.finalize();
        }
    }

}