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