1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * https://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.codec.binary; 19 20 import java.io.InputStream; 21 22 import org.apache.commons.codec.CodecPolicy; 23 24 /** 25 * Provides Base16 decoding in a streaming fashion (unlimited size). 26 * <p> 27 * The default behavior of the Base16InputStream is to DECODE, whereas the default behavior of the 28 * {@link Base16OutputStream} is to ENCODE, but this behavior can be overridden by using a different constructor. 29 * </p> 30 * 31 * @since 1.15 32 */ 33 public class Base16InputStream extends BaseNCodecInputStream { 34 35 /** 36 * Constructs a Base16InputStream such that all data read is Base16-decoded from the original provided InputStream. 37 * 38 * @param inputStream InputStream to wrap. 39 */ 40 public Base16InputStream(final InputStream inputStream) { 41 this(inputStream, false); 42 } 43 44 /** 45 * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original 46 * provided InputStream. 47 * 48 * @param inputStream InputStream to wrap. 49 * @param doEncode true if we should encode all data read from us, false if we should decode. 50 */ 51 public Base16InputStream(final InputStream inputStream, final boolean doEncode) { 52 this(inputStream, doEncode, false); 53 } 54 55 /** 56 * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original 57 * provided InputStream. 58 * 59 * @param inputStream InputStream to wrap. 60 * @param doEncode true if we should encode all data read from us, false if we should decode. 61 * @param lowerCase if {@code true} then use a lower-case Base16 alphabet. 62 */ 63 public Base16InputStream(final InputStream inputStream, final boolean doEncode, 64 final boolean lowerCase) { 65 this(inputStream, doEncode, lowerCase, CodecPolicy.LENIENT); 66 } 67 68 /** 69 * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original 70 * provided InputStream. 71 * 72 * @param inputStream InputStream to wrap. 73 * @param doEncode true if we should encode all data read from us, false if we should decode. 74 * @param lowerCase if {@code true} then use a lower-case Base16 alphabet. 75 * @param decodingPolicy Decoding policy. 76 */ 77 public Base16InputStream(final InputStream inputStream, final boolean doEncode, 78 final boolean lowerCase, final CodecPolicy decodingPolicy) { 79 super(inputStream, new Base16(lowerCase, decodingPolicy), doEncode); 80 } 81 }