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 java.io.IOException;
020import java.io.InputStream;
021
022/**
023 * This is an alternative to {@link java.io.ByteArrayInputStream}
024 * which removes the synchronization overhead for non-concurrent
025 * access; as such this class is not thread-safe.
026 *
027 * Proxy stream that prevents the underlying input stream from being marked/reset.
028 * <p>
029 * This class is typically used in cases where an input stream that supports
030 * marking needs to be passed to a component that wants to explicitly mark
031 * the stream, but it is not desirable to allow marking of the stream.
032 * </p>
033 *
034 * @since 2.8.0
035 */
036public class MarkShieldInputStream extends ProxyInputStream {
037
038    /**
039     * Constructs a proxy that shields the given input stream from being
040     * marked or rest.
041     *
042     * @param in underlying input stream
043     */
044    public MarkShieldInputStream(final InputStream in) {
045        super(in);
046    }
047
048    @SuppressWarnings("sync-override")
049    @Override
050    public void mark(final int readLimit) {
051        // no-op
052    }
053
054    @Override
055    public boolean markSupported() {
056        return false;
057    }
058
059    @SuppressWarnings("sync-override")
060    @Override
061    public void reset() throws IOException {
062        throw UnsupportedOperationExceptions.reset();
063    }
064}