    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.io.input;
    018
    019import static org.apache.commons.io.IOUtils.EOF;
    020
    021import java.io.InputStream;
    022
    023import org.apache.commons.io.IOUtils;
    024
    025/**
    026 * Always returns {@link IOUtils#EOF} to all attempts to read something from the stream.
    027 * <p>
    028 * Typically uses of this class include testing for corner cases in methods that accept input streams and acting as a
    029 * sentinel value instead of a {@code null} input stream.
    030 * </p>
    031 *
    032 * @since 1.4
    033 */
    034public class ClosedInputStream extends InputStream {
    035
    036    /**
    037     * The singleton instance.
    038     *
    039     * @since 2.12.0
    040     */
    041    public static final ClosedInputStream INSTANCE = new ClosedInputStream();
    042
    043    /**
    044     * The singleton instance.
    045     *
    046     * @deprecated Use {@link #INSTANCE}.
    047     */
    048    @Deprecated
    049    public static final ClosedInputStream CLOSED_INPUT_STREAM = INSTANCE;
    050
    051    /**
    052     * Returns -1 to indicate that the stream is closed.
    053     *
    054     * @return always -1
    055     */
    056    @Override
    057    public int read() {
    058        return EOF;
    059    }
    060
    061}