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
022/**
023 * Provides Base32 encoding and decoding in a streaming fashion (unlimited size). When encoding the default lineLength
024 * is 76 characters and the default lineEnding is CRLF, but these can be overridden by using the appropriate
025 * constructor.
026 * <p>
027 * The default behaviour of the Base32InputStream is to DECODE, whereas the default behaviour of the Base32OutputStream
028 * is to ENCODE, but this behaviour can be overridden by using a different constructor.
029 * </p>
030 * <p>
031 * Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode
032 * character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).
033 * </p>
034 *
035 * @version $Id: Base32InputStream.html 928559 2014-11-10 02:53:54Z ggregory $
036 * @see <a href="http://www.ietf.org/rfc/rfc4648.txt">RFC 4648</a>
037 * @since 1.5
038 */
039public class Base32InputStream extends BaseNCodecInputStream {
040
041    /**
042     * Creates a Base32InputStream such that all data read is Base32-decoded from the original provided InputStream.
043     *
044     * @param in
045     *            InputStream to wrap.
046     */
047    public Base32InputStream(final InputStream in) {
048        this(in, false);
049    }
050
051    /**
052     * Creates a Base32InputStream such that all data read is either Base32-encoded or Base32-decoded from the original
053     * provided InputStream.
054     *
055     * @param in
056     *            InputStream to wrap.
057     * @param doEncode
058     *            true if we should encode all data read from us, false if we should decode.
059     */
060    public Base32InputStream(final InputStream in, final boolean doEncode) {
061        super(in, new Base32(false), doEncode);
062    }
063
064    /**
065     * Creates a Base32InputStream such that all data read is either Base32-encoded or Base32-decoded from the original
066     * provided InputStream.
067     *
068     * @param in
069     *            InputStream to wrap.
070     * @param doEncode
071     *            true if we should encode all data read from us, false if we should decode.
072     * @param lineLength
073     *            If doEncode is true, each line of encoded data will contain lineLength characters (rounded down to
074     *            nearest multiple of 4). If lineLength &lt;= 0, the encoded data is not divided into lines. If doEncode
075     *            is false, lineLength is ignored.
076     * @param lineSeparator
077     *            If doEncode is true, each line of encoded data will be terminated with this byte sequence (e.g. \r\n).
078     *            If lineLength &lt;= 0, the lineSeparator is not used. If doEncode is false lineSeparator is ignored.
079     */
080    public Base32InputStream(final InputStream in, final boolean doEncode,
081                             final int lineLength, final byte[] lineSeparator) {
082        super(in, new Base32(lineLength, lineSeparator), doEncode);
083    }
084
085}