public final class Base64Variant extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
Base64Variant.PaddingReadBehaviour
Defines how the Base64Variant deals with Padding while reading
|
Modifier and Type | Field and Description |
---|---|
static int |
BASE64_VALUE_INVALID
Marker used to denote ascii characters that do not correspond
to a 6-bit value (in this variant), and is not used as a padding
character.
|
static int |
BASE64_VALUE_PADDING
Marker used to denote ascii character (in decoding table) that
is the padding character using this variant (if any).
|
protected static char |
PADDING_CHAR_NONE
Placeholder used by "no padding" variant, to be used when a character
value is needed.
|
Constructor and Description |
---|
Base64Variant(Base64Variant base,
String name,
boolean writePadding,
char paddingChar,
int maxLineLength)
"Copy constructor" that can be used when the base alphabet is identical
to one used by another variant, but other details (padding, maximum
line length) differ
|
Base64Variant(Base64Variant base,
String name,
int maxLineLength)
"Copy constructor" that can be used when the base alphabet is identical
to one used by another variant except for the maximum line length
(and obviously, name).
|
Base64Variant(String name,
String base64Alphabet,
boolean writePadding,
char paddingChar,
int maxLineLength) |
Modifier and Type | Method and Description |
---|---|
protected void |
_reportBase64EOF() |
protected void |
_reportBase64UnexpectedPadding() |
protected void |
_reportInvalidBase64(char ch,
int bindex,
String msg) |
boolean |
acceptsPaddingOnRead() |
byte[] |
decode(String input)
Convenience method for decoding contents of a Base64-encoded String,
using this variant's settings.
|
void |
decode(String str,
ByteArrayBuilder builder)
Convenience method for decoding contents of a Base64-encoded String,
using this variant's settings
and appending decoded binary data using provided
ByteArrayBuilder . |
int |
decodeBase64Byte(byte b) |
int |
decodeBase64Char(char c) |
int |
decodeBase64Char(int ch) |
String |
encode(byte[] input)
Convenience method for converting given byte array as base64 encoded
String using this variant's settings.
|
String |
encode(byte[] input,
boolean addQuotes)
Convenience method for converting given byte array as base64 encoded String
using this variant's settings, optionally enclosed in double-quotes.
|
String |
encode(byte[] input,
boolean addQuotes,
String linefeed)
Convenience method for converting given byte array as base64 encoded String
using this variant's settings, optionally enclosed in double-quotes.
|
byte |
encodeBase64BitsAsByte(int value) |
char |
encodeBase64BitsAsChar(int value) |
int |
encodeBase64Chunk(int b24,
byte[] buffer,
int outPtr)
Method that encodes given right-aligned (LSB) 24-bit value
into 4 base64 bytes (ascii), stored in given result buffer.
|
int |
encodeBase64Chunk(int b24,
char[] buffer,
int outPtr)
Method that encodes given right-aligned (LSB) 24-bit value
into 4 base64 characters, stored in given result buffer.
|
void |
encodeBase64Chunk(StringBuilder sb,
int b24) |
int |
encodeBase64Partial(int bits,
int outputBytes,
byte[] buffer,
int outPtr)
Method that outputs partial chunk (which only encodes one
or two bytes of data).
|
int |
encodeBase64Partial(int bits,
int outputBytes,
char[] buffer,
int outPtr)
Method that outputs partial chunk (which only encodes one
or two bytes of data).
|
void |
encodeBase64Partial(StringBuilder sb,
int bits,
int outputBytes) |
boolean |
equals(Object o) |
int |
getMaxLineLength() |
String |
getName() |
byte |
getPaddingByte() |
char |
getPaddingChar() |
int |
hashCode() |
String |
missingPaddingMessage()
Helper method that will construct a message to use in exceptions for cases where input ends
prematurely in place where padding would be expected.
|
Base64Variant.PaddingReadBehaviour |
paddingReadBehaviour() |
protected Object |
readResolve() |
boolean |
requiresPaddingOnRead() |
String |
toString() |
protected String |
unexpectedPaddingMessage()
Helper method that will construct a message to use in exceptions for cases where input ends
prematurely in place where padding is not expected.
|
boolean |
usesPadding() |
boolean |
usesPaddingChar(char c) |
boolean |
usesPaddingChar(int ch) |
Base64Variant |
withPaddingAllowed() |
Base64Variant |
withPaddingForbidden() |
Base64Variant |
withPaddingRequired() |
Base64Variant |
withReadPadding(Base64Variant.PaddingReadBehaviour readPadding) |
Base64Variant |
withWritePadding(boolean writePadding) |
protected static final char PADDING_CHAR_NONE
public static final int BASE64_VALUE_INVALID
public static final int BASE64_VALUE_PADDING
public Base64Variant(String name, String base64Alphabet, boolean writePadding, char paddingChar, int maxLineLength)
public Base64Variant(Base64Variant base, String name, int maxLineLength)
base
- Variant to use for settings not specific by other parametersname
- Name of this variantmaxLineLength
- Maximum length (in characters) of lines to output before
using linefeedpublic Base64Variant(Base64Variant base, String name, boolean writePadding, char paddingChar, int maxLineLength)
base
- Variant to use for settings not specific by other parametersname
- Name of this variantwritePadding
- Whether variant will use padding when encodingpaddingChar
- Padding character used for encoding, excepted on reading, if anymaxLineLength
- Maximum length (in characters) of lines to output before
using linefeedpublic Base64Variant withPaddingAllowed()
public Base64Variant withPaddingRequired()
public Base64Variant withPaddingForbidden()
public Base64Variant withReadPadding(Base64Variant.PaddingReadBehaviour readPadding)
readPadding
- Padding read behavior desiredpublic Base64Variant withWritePadding(boolean writePadding)
writePadding
- Determines if padding is output on write or notprotected Object readResolve()
public String getName()
public boolean usesPadding()
public boolean requiresPaddingOnRead()
True
if this variant requires padding on content decoded; false
if not.public boolean acceptsPaddingOnRead()
True
if this variant accepts padding on content decoded; false
if not.public boolean usesPaddingChar(char c)
public boolean usesPaddingChar(int ch)
public Base64Variant.PaddingReadBehaviour paddingReadBehaviour()
public char getPaddingChar()
public byte getPaddingByte()
public int getMaxLineLength()
public int decodeBase64Char(char c)
c
- Character to decodepublic int decodeBase64Char(int ch)
public int decodeBase64Byte(byte b)
public char encodeBase64BitsAsChar(int value)
public int encodeBase64Chunk(int b24, char[] buffer, int outPtr)
b24
- 3-byte value to encodebuffer
- Output buffer to append characters tooutPtr
- Starting position within buffer
to append encoded characterspublic void encodeBase64Chunk(StringBuilder sb, int b24)
public int encodeBase64Partial(int bits, int outputBytes, char[] buffer, int outPtr)
bits
- 24-bit chunk containing 1 or 2 bytes to encodeoutputBytes
- Number of input bytes to encode (either 1 or 2)buffer
- Output buffer to append characters tooutPtr
- Starting position within buffer
to append encoded characterspublic void encodeBase64Partial(StringBuilder sb, int bits, int outputBytes)
public byte encodeBase64BitsAsByte(int value)
public int encodeBase64Chunk(int b24, byte[] buffer, int outPtr)
b24
- 3-byte value to encodebuffer
- Output buffer to append characters (as bytes) tooutPtr
- Starting position within buffer
to append encoded characterspublic int encodeBase64Partial(int bits, int outputBytes, byte[] buffer, int outPtr)
bits
- 24-bit chunk containing 1 or 2 bytes to encodeoutputBytes
- Number of input bytes to encode (either 1 or 2)buffer
- Output buffer to append characters tooutPtr
- Starting position within buffer
to append encoded characterspublic String encode(byte[] input)
input
- Byte array to encodeinput
bytes, not surrounded by quotespublic String encode(byte[] input, boolean addQuotes)
input
- Byte array to encodeaddQuotes
- Whether to surround resulting value in double quotes or notinput
bytes, possibly
surrounded by quotes (if addQuotes
enabled)public String encode(byte[] input, boolean addQuotes, String linefeed)
input
- Byte array to encodeaddQuotes
- Whether to surround resulting value in double quotes or notlinefeed
- Linefeed to use for encoded contentinput
bytespublic byte[] decode(String input) throws IllegalArgumentException
input
- Base64-encoded input String to decodeIllegalArgumentException
- if input is not valid base64 encoded datapublic void decode(String str, ByteArrayBuilder builder) throws IllegalArgumentException
ByteArrayBuilder
.
NOTE: builder will NOT be reset before decoding (nor cleared afterwards); assumption is that caller will ensure it is given in proper state, and used as appropriate afterwards.
str
- Input to decodebuilder
- Builder used for assembling decoded contentIllegalArgumentException
- if input is not valid base64 encoded dataprotected void _reportInvalidBase64(char ch, int bindex, String msg) throws IllegalArgumentException
ch
- Character to report onbindex
- Relative index within base64 character unit; between 0
and 3 (as unit has exactly 4 characters)msg
- Base message to use for exceptionIllegalArgumentException
protected void _reportBase64EOF() throws IllegalArgumentException
IllegalArgumentException
protected void _reportBase64UnexpectedPadding() throws IllegalArgumentException
IllegalArgumentException
protected String unexpectedPaddingMessage()
public String missingPaddingMessage()
Copyright © 2021 JBoss by Red Hat. All rights reserved.