本文整理了Java中org.apache.jackrabbit.util.Base64.encode()
方法的一些代码示例,展示了Base64.encode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Base64.encode()
方法的具体详情如下:
包路径:org.apache.jackrabbit.util.Base64
类名称:Base64
方法名:encode
[英]Outputs base64 representation of the specified stream data to an OutputStream
.
[中]将指定流数据的base64表示形式输出到OutputStream
。
代码示例来源:origin: org.apache.jackrabbit/com.springsource.org.apache.jackrabbit.commons
/**
* Outputs base64 representation of the specified stream data to an
* <code>OutputStream</code>.
*
* @param in stream data to be encoded
* @param out stream where the encoded data should be written to
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, OutputStream out)
throws IOException {
Writer writer = new OutputStreamWriter(out, CHARSET);
encode(in, writer);
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector
/**
* From a byte[] returns a base 64 representation
* @param data byte[]
* @return String
* @throws IOException
* @throws IOException
*/
public static String byteToBase64(byte[] data) throws IOException {
StringWriter writer = new StringWriter();
Base64.encode(data, 0, data.length, writer);
return writer.toString();
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons
/**
* Outputs base64 representation of the specified stream data to a
* <code>Writer</code>.
*
* @param in stream data to be encoded
* @param writer writer to output the encoded data
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, Writer writer)
throws IOException {
// encode stream data in chunks;
// chunksize must be a multiple of 3 in order
// to avoid padding within output
byte[] buffer = new byte[9 * 1024];
int read;
while ((read = in.read(buffer)) > 0) {
encode(buffer, 0, read, writer);
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
/**
* Outputs base64 representation of the specified stream data to a
* <code>Writer</code>.
*
* @param in stream data to be encoded
* @param writer writer to output the encoded data
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, Writer writer)
throws IOException {
// encode stream data in chunks;
// chunksize must be a multiple of 3 in order
// to avoid padding within output
byte[] buffer = new byte[9 * 1024];
int read;
while ((read = in.read(buffer)) > 0) {
encode(buffer, 0, read, writer);
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Outputs base64 representation of the specified stream data to a
* <code>Writer</code>.
*
* @param in stream data to be encoded
* @param writer writer to output the encoded data
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, Writer writer)
throws IOException {
// encode stream data in chunks;
// chunksize must be a multiple of 3 in order
// to avoid padding within output
byte[] buffer = new byte[9 * 1024];
int read;
while ((read = in.read(buffer)) > 0) {
encode(buffer, 0, read, writer);
}
}
代码示例来源:origin: org.apache.jackrabbit/com.springsource.org.apache.jackrabbit.commons
/**
* Outputs base64 representation of the specified stream data to a
* <code>Writer</code>.
*
* @param in stream data to be encoded
* @param writer writer to output the encoded data
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, Writer writer)
throws IOException {
// encode stream data in chunks;
// chunksize must be a multiple of 3 in order
// to avoid padding within output
byte[] buffer = new byte[9 * 1024];
int read;
while ((read = in.read(buffer)) > 0) {
encode(buffer, 0, read, writer);
}
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons
/**
* Returns the base64 representation of UTF-8 encoded string.
*
* @since Apache Jackrabbit 2.3
* @param data the string to be encoded
* @return base64-encoding of the string
*/
public static String encode(String data) {
try {
StringWriter buffer = new StringWriter();
byte[] b = data.getBytes(StandardCharsets.UTF_8);
encode(b, 0, b.length, buffer);
return buffer.toString();
} catch (IOException e) { // should never happen
throw new RuntimeException(
"Unable to encode base64 data: " + data, e);
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Returns the base64 representation of UTF-8 encoded string.
*
* @since Apache Jackrabbit 2.3
* @param data the string to be encoded
* @return base64-encoding of the string
*/
public static String encode(String data) {
try {
StringWriter buffer = new StringWriter();
byte[] b = data.getBytes(StandardCharsets.UTF_8);
encode(b, 0, b.length, buffer);
return buffer.toString();
} catch (IOException e) { // should never happen
throw new RuntimeException(
"Unable to encode base64 data: " + data, e);
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Outputs base64 representation of the specified stream data to an
* <code>OutputStream</code>.
*
* @param in stream data to be encoded
* @param out stream where the encoded data should be written to
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, OutputStream out)
throws IOException {
Writer writer = new BufferedWriter(new OutputStreamWriter(out, CHARSET));
try {
encode(in, writer);
} finally {
try {
writer.flush();
} catch (IOException ignore) {
}
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
/**
* Returns the base64 representation of UTF-8 encoded string.
*
* @since Apache Jackrabbit 2.3
* @param data the string to be encoded
* @return base64-encoding of the string
*/
public static String encode(String data) {
try {
StringWriter buffer = new StringWriter();
byte[] b = data.getBytes(StandardCharsets.UTF_8);
encode(b, 0, b.length, buffer);
return buffer.toString();
} catch (IOException e) { // should never happen
throw new RuntimeException(
"Unable to encode base64 data: " + data, e);
}
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons
/**
* Outputs base64 representation of the specified stream data to an
* <code>OutputStream</code>.
*
* @param in stream data to be encoded
* @param out stream where the encoded data should be written to
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, OutputStream out)
throws IOException {
Writer writer = new BufferedWriter(new OutputStreamWriter(out, CHARSET));
try {
encode(in, writer);
} finally {
try {
writer.flush();
} catch (IOException ignore) {
}
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
/**
* Outputs base64 representation of the specified stream data to an
* <code>OutputStream</code>.
*
* @param in stream data to be encoded
* @param out stream where the encoded data should be written to
* @throws java.io.IOException if an i/o error occurs
*/
public static void encode(InputStream in, OutputStream out)
throws IOException {
Writer writer = new BufferedWriter(new OutputStreamWriter(out, CHARSET));
try {
encode(in, writer);
} finally {
try {
writer.flush();
} catch (IOException ignore) {
}
}
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr-commons
/**
* Base64-decodes or -encodes the given string, depending on whether
* or not it contains a "{base64}" prefix. If the string gets encoded,
* the "{base64}" prefix is added to it.
*
* @since Apache Jackrabbit 2.3
* @param data string to be decoded or encoded
* @return decoded or encoded string
*/
public static String decodeOrEncode(String data) {
if (data.startsWith("{base64}")) {
return decode(data.substring("{base64}".length()));
} else {
return "{base64}" + encode(data);
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Base64-decodes or -encodes the given string, depending on whether
* or not it contains a "{base64}" prefix. If the string gets encoded,
* the "{base64}" prefix is added to it.
*
* @since Apache Jackrabbit 2.3
* @param data string to be decoded or encoded
* @return decoded or encoded string
*/
public static String decodeOrEncode(String data) {
if (data.startsWith("{base64}")) {
return decode(data.substring("{base64}".length()));
} else {
return "{base64}" + encode(data);
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
/**
* Base64-decodes or -encodes the given string, depending on whether
* or not it contains a "{base64}" prefix. If the string gets encoded,
* the "{base64}" prefix is added to it.
*
* @since Apache Jackrabbit 2.3
* @param data string to be decoded or encoded
* @return decoded or encoded string
*/
public static String decodeOrEncode(String data) {
if (data.startsWith("{base64}")) {
return decode(data.substring("{base64}".length()));
} else {
return "{base64}" + encode(data);
}
}
代码示例来源:origin: apache/jackrabbit-oak
@Override
public String serialize(Blob blob) {
checkArgument(blob.length() < maxSize, "Cannot serialize Blob of size [%s] " +
"which is more than allowed maxSize of [%s]", blob.length(), maxSize);
try {
try (InputStream is = blob.getNewStream()) {
StringWriter writer = new StringWriter();
Base64.encode(is, writer);
return writer.toString();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
@Override
public String serialize(Blob blob) {
checkArgument(blob.length() < maxSize, "Cannot serialize Blob of size [%s] " +
"which is more than allowed maxSize of [%s]", blob.length(), maxSize);
try {
try (InputStream is = blob.getNewStream()) {
StringWriter writer = new StringWriter();
Base64.encode(is, writer);
return writer.toString();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/jackrabbit
Base64.encode(in, writer);
if (enforceBase64) {
byte bytes[] = textVal.getBytes(StandardCharsets.UTF_8);
Base64.encode(bytes, 0, bytes.length, writer);
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
Base64.encode(in, writer);
if (enforceBase64) {
byte bytes[] = textVal.getBytes(StandardCharsets.UTF_8);
Base64.encode(bytes, 0, bytes.length, writer);
代码示例来源:origin: apache/jackrabbit-oak
@Test
public void testCompleteDirectUploadSignatureMustMatch() throws DataRecordUploadException, DataStoreException {
DataRecordUpload uploadContext = getDataStore().initiateDataRecordUpload(ONE_MB, 1);
// Pull the blob id out and modify it
String uploadToken = uploadContext.getUploadToken();
String[] parts = uploadToken.split("#");
String tokenPart = parts[0];
String sigPart = parts[1];
String[] subParts = tokenPart.split("#");
String blobId = subParts[0];
char c = (char)((int)(blobId.charAt(blobId.length()-1))+1);
blobId = blobId.substring(0, blobId.length()-1) + c;
for (int i = 1; i<subParts.length; i++) {
blobId += "#" + subParts[i];
}
String newToken = Base64.encode(blobId) + "#" + sigPart;
try {
getDataStore().completeDataRecordUpload(newToken);
fail();
}
catch (IllegalArgumentException e) { }
}
内容来源于网络,如有侵权,请联系作者删除!