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 */
017
018package org.apache.commons.codec.binary;
019
020import java.io.InputStream;
021
022import org.apache.commons.codec.CodecPolicy;
023
024/**
025 * Provides Base16 encoding and decoding in a streaming fashion (unlimited size).
026 * <p>
027 * The default behavior of the Base16InputStream is to DECODE, whereas the default behavior of the
028 * {@link Base16OutputStream} is to ENCODE, but this behavior can be overridden by using a different constructor.
029 * </p>
030 *
031 * @since 1.15
032 */
033public class Base16InputStream extends BaseNCodecInputStream {
034
035    /**
036     * Constructs a Base16InputStream such that all data read is Base16-decoded from the original provided InputStream.
037     *
038     * @param inputStream InputStream to wrap.
039     */
040    public Base16InputStream(final InputStream inputStream) {
041        this(inputStream, false);
042    }
043
044    /**
045     * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original
046     * provided InputStream.
047     *
048     * @param inputStream InputStream to wrap.
049     * @param doEncode true if we should encode all data read from us, false if we should decode.
050     */
051    public Base16InputStream(final InputStream inputStream, final boolean doEncode) {
052        this(inputStream, doEncode, false);
053    }
054
055    /**
056     * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original
057     * provided InputStream.
058     *
059     * @param inputStream InputStream to wrap.
060     * @param doEncode true if we should encode all data read from us, false if we should decode.
061     * @param lowerCase if {@code true} then use a lower-case Base16 alphabet.
062     */
063    public Base16InputStream(final InputStream inputStream, final boolean doEncode,
064            final boolean lowerCase) {
065        this(inputStream, doEncode, lowerCase, CodecPolicy.LENIENT);
066    }
067
068    /**
069     * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original
070     * provided InputStream.
071     *
072     * @param inputStream InputStream to wrap.
073     * @param doEncode true if we should encode all data read from us, false if we should decode.
074     * @param lowerCase if {@code true} then use a lower-case Base16 alphabet.
075     * @param decodingPolicy Decoding policy.
076     */
077    public Base16InputStream(final InputStream inputStream, final boolean doEncode,
078            final boolean lowerCase, final CodecPolicy decodingPolicy) {
079        super(inputStream, new Base16(lowerCase, decodingPolicy), doEncode);
080    }
081}