public class Base64 extends Object
Base64 encoding and decoding utility methods, both for binary and textual informations.
| 构造器和说明 |
|---|
Base64() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
decode(byte[] bytes)
Decodes a binary sequence.
|
static void |
decode(File source,
File target)
Decodes data from the given source file contents and writes them in the
given target file.
|
static void |
decode(InputStream inputStream,
OutputStream outputStream)
Decodes data from the given input stream and writes them in the given
output stream.
|
static String |
decode(String str)
Decodes the supplied string.
|
static String |
decode(String str,
String charset)
Decodes the supplied string.
|
static byte[] |
encode(byte[] bytes)
Encodes a binary sequence.
|
static byte[] |
encode(byte[] bytes,
int wrapAt)
Encodes a binary sequence, wrapping every encoded line every
wrapAt characters.
|
static void |
encode(File source,
File target)
Encodes data from the given source file contents and writes them in the
given target file.
|
static void |
encode(File source,
File target,
int wrapAt)
Encodes data from the given source file contents and writes them in the
given target file, wrapping every encoded line every wrapAt
characters.
|
static void |
encode(InputStream inputStream,
OutputStream outputStream)
Encodes data from the given input stream and writes them in the given
output stream.
|
static void |
encode(InputStream inputStream,
OutputStream outputStream,
int wrapAt)
Encodes data from the given input stream and writes them in the given
output stream, wrapping every encoded line every wrapAt
characters.
|
static String |
encode(String str)
Encodes a string.
|
static String |
encode(String str,
String charset)
Encodes a string.
|
public static String encode(String str) throws RuntimeException
Encodes a string.
Before the string is encoded in Base64, it is converted in a binary sequence using the system default charset.
str - The source string.RuntimeException - If an unexpected error occurs.public static String encode(String str, String charset) throws RuntimeException
Encodes a string.
Before the string is encoded in Base64, it is converted in a binary sequence using the supplied charset.
str - The source stringcharset - The charset name.RuntimeException - If an unexpected error occurs.public static String decode(String str) throws RuntimeException
Decodes the supplied string.
The supplied string is decoded into a binary sequence, and then the sequence is encoded with the system default charset and returned.
str - The encoded string.RuntimeException - If an unexpected error occurs.public static String decode(String str, String charset) throws RuntimeException
Decodes the supplied string.
The supplied string is decoded into a binary sequence, and then the sequence is encoded with the supplied charset and returned.
str - The encoded string.charset - The charset name.RuntimeException - If an unexpected error occurs.public static byte[] encode(byte[] bytes)
throws RuntimeException
Encodes a binary sequence.
If data are large, i.e. if you are working with large binary files,
consider to use a Base64OutputStream instead of loading too much
data in memory.
bytes - The source sequence.RuntimeException - If an unexpected error occurs.public static byte[] encode(byte[] bytes,
int wrapAt)
throws RuntimeException
Encodes a binary sequence, wrapping every encoded line every wrapAt characters. A wrapAt value less than 1 disables wrapping.
If data are large, i.e. if you are working with large binary files,
consider to use a Base64OutputStream instead of loading too much
data in memory.
bytes - The source sequence.wrapAt - The max line length for encoded data. If less than 1 no
wrap is applied.RuntimeException - If an unexpected error occurs.public static byte[] decode(byte[] bytes)
throws RuntimeException
Decodes a binary sequence.
If data are large, i.e. if you are working with large binary files,
consider to use a Base64InputStream instead of loading too much
data in memory.
bytes - The encoded sequence.RuntimeException - If an unexpected error occurs.public static void encode(InputStream inputStream, OutputStream outputStream) throws IOException
Encodes data from the given input stream and writes them in the given output stream.
The supplied input stream is read until its end is reached, but it's not closed by this method.
The supplied output stream is nor flushed neither closed by this method.
inputStream - The input stream.outputStream - The output stream.IOException - If an I/O error occurs.public static void encode(InputStream inputStream, OutputStream outputStream, int wrapAt) throws IOException
Encodes data from the given input stream and writes them in the given output stream, wrapping every encoded line every wrapAt characters. A wrapAt value less than 1 disables wrapping.
The supplied input stream is read until its end is reached, but it's not closed by this method.
The supplied output stream is nor flushed neither closed by this method.
inputStream - The input stream from which clear data are read.outputStream - The output stream in which encoded data are written.wrapAt - The max line length for encoded data. If less than 1 no
wrap is applied.IOException - If an I/O error occurs.public static void decode(InputStream inputStream, OutputStream outputStream) throws IOException
Decodes data from the given input stream and writes them in the given output stream.
The supplied input stream is read until its end is reached, but it's not closed by this method.
The supplied output stream is nor flushed neither closed by this method.
inputStream - The input stream from which encoded data are read.outputStream - The output stream in which decoded data are written.IOException - If an I/O error occurs.public static void encode(File source, File target, int wrapAt) throws IOException
Encodes data from the given source file contents and writes them in the given target file, wrapping every encoded line every wrapAt characters. A wrapAt value less than 1 disables wrapping.
source - The source file, from which decoded data are read.target - The target file, in which encoded data are written.wrapAt - The max line length for encoded data. If less than 1 no
wrap is applied.IOException - If an I/O error occurs.public static void encode(File source, File target) throws IOException
Encodes data from the given source file contents and writes them in the given target file.
source - The source file, from which decoded data are read.target - The target file, in which encoded data are written.IOException - If an I/O error occurs.public static void decode(File source, File target) throws IOException
Decodes data from the given source file contents and writes them in the given target file.
source - The source file, from which encoded data are read.target - The target file, in which decoded data are written.IOException - If an I/O error occurs.Copyright © 2013 The Skfiy Open Association. All Rights Reserved.