本文整理了Java中org.apache.commons.net.util.Base64
类的一些代码示例,展示了Base64
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64
类的具体详情如下:
包路径:org.apache.commons.net.util.Base64
类名称:Base64
[英]Provides Base64 encoding and decoding as defined by RFC 2045.
This class implements section 6.8. Base64 Content-Transfer-Encoding from RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies by Freed and Borenstein.
The class can be parameterized in the following manner with various constructors:
Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).
[中]提供RFC 2045定义的Base64编码和解码。
此类实现了第6.8节。RFC 2045多用途Internet邮件扩展(MIME)的Base64内容传输编码第一部分:Freed和Borenstein的Internet邮件正文格式。
该类可以通过以下方式使用各种构造函数进行参数化:
*URL安全模式:默认关闭。
*行长度:默认为76。在编码数据中,不是4的倍数的行长度实际上仍然是4的倍数。
*行分隔符:默认为CRLF(“\r\n”)
由于该类直接对字节流而不是字符流进行操作,因此它被硬编码为仅对与较低的127 ASCII图表(ISO-8859-1、Windows-1252、UTF-8等)兼容的字符编码进行编码/解码。
代码示例来源:origin: deeplearning4j/nd4j
/**
* Create an ndarray from a base 64
* representation
* @param base64 the base 64 to convert
* @return the ndarray from base 64
* @throws IOException
*/
public static INDArray fromBase64(String base64) throws IOException {
byte[] arr = Base64.decodeBase64(base64);
ByteArrayInputStream bis = new ByteArrayInputStream(arr);
DataInputStream dis = new DataInputStream(bis);
INDArray predict = Nd4j.read(dis);
return predict;
}
代码示例来源:origin: commons-net/commons-net
/**
* Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The
* url-safe variation emits - and _ instead of + and / characters.
*
* @param binaryData
* binary data to encode
* @return byte[] containing Base64 characters in their UTF-8 representation.
* @since 1.4
*/
public static byte[] encodeBase64URLSafe(byte[] binaryData) {
return encodeBase64(binaryData, false, true);
}
代码示例来源:origin: deeplearning4j/nd4j
@Override
public void process(Exchange exchange) throws Exception {
final INDArray arr = (INDArray) exchange.getIn().getBody();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
Nd4j.write(arr, dos);
byte[] bytes = bos.toByteArray();
String base64 = Base64.encodeBase64String(bytes);
exchange.getIn().setBody(base64, String.class);
String id = UUID.randomUUID().toString();
exchange.getIn().setHeader(KafkaConstants.KEY, id);
exchange.getIn().setHeader(KafkaConstants.PARTITION_KEY, id);
}
}).to(kafkaUri);
代码示例来源:origin: commons-net/commons-net
/**
* Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The
* url-safe variation emits - and _ instead of + and / characters.
*
* @param binaryData
* binary data to encode
* @return String containing Base64 characters
* @since 1.4
*/
public static String encodeBase64URLSafeString(byte[] binaryData) {
return newStringUtf8(encodeBase64(binaryData, false, true));
}
代码示例来源:origin: commons-net/commons-net
/**
* Decodes Base64 data into octets
*
* @param base64Data
* Byte array containing Base64 data
* @return Array containing decoded data.
*/
public static byte[] decodeBase64(byte[] base64Data) {
return new Base64().decode(base64Data);
}
代码示例来源:origin: commons-net/commons-net
/**
* Decodes a String containing containing characters in the Base64 alphabet.
*
* @param pArray
* A String containing Base64 character data
* @return a byte array containing binary data
* @since 1.4
*/
public byte[] decode(String pArray) {
return decode(getBytesUtf8(pArray));
}
代码示例来源:origin: commons-net/commons-net
Base64.encodeBase64(("\000" + username + "\000" + password).getBytes(getCharset())),
getCharset())
) == POP3Reply.OK;
case CRAM_MD5:
byte[] serverChallenge = Base64.decodeBase64(getReplyString().substring(2).trim());
System.arraycopy(hmacResult, 0, toEncode, usernameBytes.length + 1, hmacResult.length);
return sendCommand(Base64.encodeBase64StringUnChunked(toEncode)) == POP3Reply.OK;
default:
return false;
代码示例来源:origin: commons-net/commons-net
Base64.encodeBase64StringUnChunked(("\000" + username + "\000" + password)
.getBytes(getCharset())));
if (result == IMAPReply.OK)
byte[] serverChallenge = Base64.decodeBase64(getReplyString().substring(2).trim());
System.arraycopy(hmacResult, 0, toEncode, usernameBytes.length + 1, hmacResult.length);
int result = sendData(Base64.encodeBase64StringUnChunked(toEncode));
if (result == IMAPReply.OK)
if (sendData(Base64.encodeBase64StringUnChunked(username.getBytes(getCharset()))) != IMAPReply.CONT)
int result = sendData(Base64.encodeBase64StringUnChunked(password.getBytes(getCharset())));
if (result == IMAPReply.OK)
代码示例来源:origin: commons-net/commons-net
/**
* Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
*
* @param bigInt
* a BigInteger
* @return A byte array containing base64 character data
* @throws NullPointerException
* if null is passed in
* @since 1.4
*/
public static byte[] encodeInteger(BigInteger bigInt) {
if (bigInt == null) {
throw new NullPointerException("encodeInteger called with null parameter");
}
return encodeBase64(toIntegerBytes(bigInt), false);
}
代码示例来源:origin: commons-net/commons-net
/**
* Decodes a byte[] containing containing characters in the Base64 alphabet.
*
* @param pArray
* A byte array containing Base64 character data
* @return a byte array containing binary data
*/
public byte[] decode(byte[] pArray) {
reset();
if (pArray == null || pArray.length == 0) {
return pArray;
}
long len = (pArray.length * 3) / 4;
byte[] buf = new byte[(int) len];
setInitialBuffer(buf, 0, buf.length);
decode(pArray, 0, pArray.length);
decode(pArray, 0, -1); // Notify decoder of EOF.
// Would be nice to just return buf (like we sometimes do in the encode
// logic), but we have no idea what the line-length was (could even be
// variable). So we cannot determine ahead of time exactly how big an
// array is necessary. Hence the need to construct a 2nd byte array to
// hold the final result:
byte[] result = new byte[pos];
readResults(result, 0, result.length);
return result;
}
代码示例来源:origin: commons-net/commons-net
/**
* Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
*
* @param binaryData
* Array containing binary data to encode.
* @param isChunked
* if <code>true</code> this encoder will chunk the base64 output into 76 character blocks
* @param urlSafe
* if <code>true</code> this encoder will emit - and _ instead of the usual + and / characters.
* @param maxResultSize
* The maximum result size to accept.
* @return Base64-encoded data.
* @throws IllegalArgumentException
* Thrown when the input array needs an output array bigger than maxResultSize
* @since 1.4
*/
public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize) {
if (binaryData == null || binaryData.length == 0) {
return binaryData;
}
long len = getEncodeLength(binaryData, isChunked ? CHUNK_SIZE : 0, isChunked ? CHUNK_SEPARATOR : EMPTY_BYTE_ARRAY);
if (len > maxResultSize) {
throw new IllegalArgumentException("Input array too big, the output array would be bigger (" +
len +
") than the specified maxium size of " +
maxResultSize);
}
Base64 b64 = isChunked ? new Base64(urlSafe) : new Base64(0, CHUNK_SEPARATOR, urlSafe);
return b64.encode(binaryData);
}
代码示例来源:origin: commons-net/commons-net
Base64.encodeBase64StringUnChunked(("\000" + username + "\000" + password).getBytes(getCharset()))
));
byte[] serverChallenge = Base64.decodeBase64(getReplyString().substring(4).trim());
Base64.encodeBase64StringUnChunked(toEncode)));
Base64.encodeBase64StringUnChunked(username.getBytes(getCharset()))))) {
return false;
Base64.encodeBase64StringUnChunked(password.getBytes(getCharset()))));
Base64.encodeBase64StringUnChunked(username.getBytes(getCharset()))
));
} else {
代码示例来源:origin: commons-net/commons-net
/**
* Encodes binary data using the base64 algorithm, without using chunking.
* <p>
* For a chunking version, see {@link #encodeBase64String(byte[])}.
*
* @param binaryData
* binary data to encode
* @return String containing Base64 characters.
* @since 3.2
*/
public static String encodeBase64StringUnChunked(byte[] binaryData) {
return newStringUtf8(encodeBase64(binaryData, false));
}
代码示例来源:origin: commons-net/commons-net
/**
* Decodes a Base64 String into octets
*
* @param base64String
* String containing Base64 data
* @return Array containing decoded data.
* @since 1.4
*/
public static byte[] decodeBase64(String base64String) {
return new Base64().decode(base64String);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Returns a set of arrays
* from base 64 that is tab delimited.
* @param base64 the base 64 that's tab delimited
* @return the set of arrays
*/
public static INDArray[] arraysFromBase64(String base64) throws IOException {
String[] base64Arr = base64.split("\t");
INDArray[] ret = new INDArray[base64Arr.length];
for (int i = 0; i < base64Arr.length; i++) {
byte[] decode = Base64.decodeBase64(base64Arr[i]);
ByteArrayInputStream bis = new ByteArrayInputStream(decode);
DataInputStream dis = new DataInputStream(bis);
INDArray predict = Nd4j.read(dis);
ret[i] = predict;
}
return ret;
}
代码示例来源:origin: commons-net/commons-net
/**
* Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
*
* @param binaryData
* binary data to encode
* @return Base64 characters chunked in 76 character blocks
*/
public static byte[] encodeBase64Chunked(byte[] binaryData) {
return encodeBase64(binaryData, true);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Returns an ndarray
* as base 64
* @param arr the array to write
* @return the base 64 representation of the binary
* ndarray
* @throws IOException
*/
public static String base64String(INDArray arr) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
Nd4j.write(arr, dos);
String base64 = Base64.encodeBase64String(bos.toByteArray());
return base64;
}
代码示例来源:origin: commons-net/commons-net
/**
* Encodes binary data using the base64 algorithm.
*
* @param binaryData
* binary data to encode
* @param useChunking whether to split the output into chunks
* @return String containing Base64 characters.
* @since 3.2
*/
public static String encodeBase64String(byte[] binaryData, boolean useChunking) {
return newStringUtf8(encodeBase64(binaryData, useChunking));
}
代码示例来源:origin: pl.edu.icm.synat/synat-oai-server
void deSerialize(String token) throws OAIInternalServerError, BadResumptionTokenException {
try {
Base64 dec = new Base64();
byte[] b = dec.decode(token);
ByteArrayInputStream bis = new ByteArrayInputStream(b);
ObjectInputStream ois = new ObjectInputStream(bis);
dOrigFrom = new Date(ois.readLong());
dUntil = new Date(ois.readLong());
lastElDate = new Date(ois.readLong());
lastElId = ois.readUTF();
metadataPref = ois.readUTF();
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new BadResumptionTokenException();
// throw new OAIInternalServerError("Iternal java error during serialisation");
}
}
代码示例来源:origin: commons-net/commons-net
/**
* Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
*
* @param pArray
* a byte array containing base64 character data
* @return A BigInteger
* @since 1.4
*/
public static BigInteger decodeInteger(byte[] pArray) {
return new BigInteger(1, decodeBase64(pArray));
}
内容来源于网络,如有侵权,请联系作者删除!