|
20 | 20 | import java.io.InputStream; |
21 | 21 |
|
22 | 22 | import org.apache.commons.codec.CodecPolicy; |
| 23 | +import org.apache.commons.codec.binary.BaseNCodecInputStream.AbstracBuilder; // NOPMD: Required by ECJ (Eclipse) |
23 | 24 |
|
24 | 25 | /** |
25 | 26 | * Provides Base16 decoding in a streaming fashion (unlimited size). |
26 | 27 | * <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. |
| 28 | + * The default behavior of the Base16InputStream is to DECODE, whereas the default behavior of the {@link Base16OutputStream} is to ENCODE, but this behavior |
| 29 | + * can be overridden by using a different constructor. |
29 | 30 | * </p> |
30 | 31 | * |
31 | 32 | * @see Base16 |
32 | 33 | * @since 1.15 |
33 | 34 | */ |
34 | | -public class Base16InputStream extends BaseNCodecInputStream<Base16> { |
| 35 | +public class Base16InputStream extends BaseNCodecInputStream<Base16, Base16InputStream, Base16InputStream.Builder> { |
| 36 | + |
| 37 | + /** |
| 38 | + * Builds instances of Base16InputStream. |
| 39 | + */ |
| 40 | + public static class Builder extends AbstracBuilder<Base16InputStream, Base16, Builder> { |
| 41 | + |
| 42 | + /** |
| 43 | + * Constructs a new instance. |
| 44 | + */ |
| 45 | + public Builder() { |
| 46 | + // empty |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public Base16InputStream get() { |
| 51 | + return new Base16InputStream(this); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected Base16 newBaseNCodec() { |
| 56 | + return new Base16(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Constructs a new Builder. |
| 62 | + * |
| 63 | + * @return a new Builder. |
| 64 | + */ |
| 65 | + public static Builder builder() { |
| 66 | + return new Builder(); |
| 67 | + } |
| 68 | + |
| 69 | + private Base16InputStream(final Builder builder) { |
| 70 | + super(builder); |
| 71 | + } |
35 | 72 |
|
36 | 73 | /** |
37 | 74 | * Constructs a Base16InputStream such that all data read is Base16-decoded from the original provided InputStream. |
38 | 75 | * |
39 | 76 | * @param inputStream InputStream to wrap. |
40 | 77 | */ |
41 | 78 | public Base16InputStream(final InputStream inputStream) { |
42 | | - this(inputStream, false); |
| 79 | + super(builder().setInputStream(inputStream)); |
43 | 80 | } |
44 | 81 |
|
45 | 82 | /** |
46 | | - * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original |
47 | | - * provided InputStream. |
| 83 | + * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original provided InputStream. |
48 | 84 | * |
49 | 85 | * @param inputStream InputStream to wrap. |
50 | | - * @param doEncode true if we should encode all data read from us, false if we should decode. |
| 86 | + * @param encode true if we should encode all data read from us, false if we should decode. |
51 | 87 | */ |
52 | | - public Base16InputStream(final InputStream inputStream, final boolean doEncode) { |
53 | | - this(inputStream, doEncode, false); |
| 88 | + @Deprecated |
| 89 | + public Base16InputStream(final InputStream inputStream, final boolean encode) { |
| 90 | + super(builder().setInputStream(inputStream).setEncode(encode)); |
54 | 91 | } |
55 | 92 |
|
56 | 93 | /** |
57 | | - * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original |
58 | | - * provided InputStream. |
| 94 | + * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original provided InputStream. |
59 | 95 | * |
60 | 96 | * @param inputStream InputStream to wrap. |
61 | | - * @param doEncode true if we should encode all data read from us, false if we should decode. |
62 | | - * @param lowerCase if {@code true} then use a lower-case Base16 alphabet. |
| 97 | + * @param encode true if we should encode all data read from us, false if we should decode. |
| 98 | + * @param lowerCase if {@code true} then use a lower-case Base16 alphabet. |
63 | 99 | */ |
64 | | - public Base16InputStream(final InputStream inputStream, final boolean doEncode, |
65 | | - final boolean lowerCase) { |
66 | | - this(inputStream, doEncode, lowerCase, CodecPolicy.LENIENT); |
| 100 | + @Deprecated |
| 101 | + public Base16InputStream(final InputStream inputStream, final boolean encode, final boolean lowerCase) { |
| 102 | + super(builder().setInputStream(inputStream).setEncode(encode).setBaseNCodec(new Base16(lowerCase))); |
67 | 103 | } |
68 | 104 |
|
69 | 105 | /** |
70 | | - * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original |
71 | | - * provided InputStream. |
| 106 | + * Constructs a Base16InputStream such that all data read is either Base16-encoded or Base16-decoded from the original provided InputStream. |
72 | 107 | * |
73 | | - * @param inputStream InputStream to wrap. |
74 | | - * @param doEncode true if we should encode all data read from us, false if we should decode. |
75 | | - * @param lowerCase if {@code true} then use a lower-case Base16 alphabet. |
| 108 | + * @param inputStream InputStream to wrap. |
| 109 | + * @param encode true if we should encode all data read from us, false if we should decode. |
| 110 | + * @param lowerCase if {@code true} then use a lower-case Base16 alphabet. |
76 | 111 | * @param decodingPolicy Decoding policy. |
77 | 112 | */ |
78 | | - public Base16InputStream(final InputStream inputStream, final boolean doEncode, |
79 | | - final boolean lowerCase, final CodecPolicy decodingPolicy) { |
80 | | - super(inputStream, new Base16(lowerCase, decodingPolicy), doEncode); |
| 113 | + @Deprecated |
| 114 | + public Base16InputStream(final InputStream inputStream, final boolean encode, final boolean lowerCase, final CodecPolicy decodingPolicy) { |
| 115 | + super(builder().setInputStream(inputStream).setEncode(encode).setBaseNCodec(new Base16(lowerCase, decodingPolicy))); |
81 | 116 | } |
82 | 117 | } |
0 commit comments