本文整理汇总了Java中io.netty.handler.codec.base64.Base64类的典型用法代码示例。如果您正苦于以下问题:Java Base64类的具体用法?Java Base64怎么用?Java Base64使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Base64类属于io.netty.handler.codec.base64包,在下文中一共展示了Base64类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveKeyPairAndCertificateToFile
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
protected void saveKeyPairAndCertificateToFile() throws Exception {
if(localPrivateKeyFile==null){
LOGGER.info("not saving private key nor certificate");
return;
}
//Encode in PEM format, the format prefered by openssl
// if(false){
// PEMWriter pemWriter=new PEMWriter(new FileWriter(localPrivateKeyFile));
// pemWriter.writeObject(localPrivateECKey);
// pemWriter.close();
// }
// else{
String keyText = "-----BEGIN EC PRIVATE KEY-----\n" +
Base64.encode(Unpooled.wrappedBuffer(localPrivateECKey.getEncoded()), true).toString(CharsetUtil.US_ASCII) +
"\n-----END EC PRIVATE KEY-----\n";
Files.write(keyText, localPrivateKeyFile, CharsetUtil.US_ASCII);
Files.write(localId.toString(), new File(localPrivateKeyFile.getParentFile(), "localPublic.hash"), CharsetUtil.US_ASCII);
// }
PEMWriter certificateWriter=new PEMWriter(new FileWriter(localCertificateFile));
certificateWriter.writeObject(cert);
certificateWriter.close();
LOGGER.info("Saved to "+localCertificateFile.getAbsolutePath());
}
示例2: hashToBase64
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
public static String hashToBase64(ByteBuf objectState) {
ByteBuffer bf = objectState.internalNioBuffer(objectState.readerIndex(), objectState.readableBytes());
long h1 = LongHashFunction.farmUo().hashBytes(bf);
long h2 = LongHashFunction.xx().hashBytes(bf);
ByteBuf buf = ByteBufAllocator.DEFAULT.buffer((2 * Long.SIZE) / Byte.SIZE);
try {
buf.writeLong(h1).writeLong(h2);
ByteBuf b = Base64.encode(buf);
try {
String s = b.toString(CharsetUtil.UTF_8);
return s.substring(0, s.length() - 2);
} finally {
b.release();
}
} finally {
buf.release();
}
}
示例3: encode
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
protected void encode(ChannelHandlerContext ctx, Object msg, List out)
throws Exception {
ByteBuf ENC =
Unpooled.wrappedBuffer("ENC ".getBytes(data.encoding));
ByteBuf RN =
Unpooled.wrappedBuffer("\r\n".getBytes(data.encoding));
Log.finer("Sending command: ", msg);
ByteBuf raw =
Unpooled.wrappedBuffer(msg.toString().getBytes(data.encoding));
if (data.security != null) {
ByteBuf eb = Base64.encode(data.security.protect(raw), false);
ctx.write(ENC);
ctx.write(eb);
} else {
ctx.write(raw);
}
ctx.writeAndFlush(RN);
}
示例4: getBase64EncodedString
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
/** Return a Base64-encoded string. */
private static String getBase64EncodedString(String str) {
ByteBuf byteBuf = null;
ByteBuf encodedByteBuf = null;
try {
byteBuf = Unpooled.wrappedBuffer(str.getBytes(StandardCharsets.UTF_8));
encodedByteBuf = Base64.encode(byteBuf);
return encodedByteBuf.toString(StandardCharsets.UTF_8);
} finally {
// The release is called to suppress the memory leak error messages raised by netty.
if (byteBuf != null) {
byteBuf.release();
if (encodedByteBuf != null) {
encodedByteBuf.release();
}
}
}
}
示例5: encode
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
/**
* Encodes the buffered image into the encoded favicon string.
*
* @param image the buffered image
* @return the favicon string
*/
private static String encode(BufferedImage image) throws IOException {
checkArgument(image.getWidth() == 64, "favicon must be 64 pixels wide");
checkArgument(image.getHeight() == 64, "favicon must be 64 pixels high");
ByteBuf buf = Unpooled.buffer();
try {
ImageIO.write(image, "PNG", new ByteBufOutputStream(buf));
ByteBuf base64 = Base64.encode(buf);
try {
return FAVICON_PREFIX + base64.toString(StandardCharsets.UTF_8);
} finally {
base64.release();
}
} finally {
buf.release();
}
}
示例6: decode
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
/**
* Decodes the buffered image from the encoded favicon string.
*
* @param encoded the encoded string
* @return the buffered image
*/
private static BufferedImage decode(String encoded) throws IOException {
checkArgument(encoded.startsWith(FAVICON_PREFIX), "unknown favicon format");
ByteBuf base64 = Unpooled.copiedBuffer(encoded.substring(FAVICON_PREFIX.length()), StandardCharsets.UTF_8);
try {
ByteBuf buf = Base64.decode(base64);
try {
BufferedImage result = ImageIO.read(new ByteBufInputStream(buf));
checkState(result.getWidth() == 64, "favicon must be 64 pixels wide");
checkState(result.getHeight() == 64, "favicon must be 64 pixels high");
return result;
} finally {
buf.release();
}
} finally {
base64.release();
}
}
示例7: readPrivateKey
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
static ByteBuf readPrivateKey(File file) throws KeyException {
String content;
try {
content = readContent(file);
} catch (IOException e) {
throw new KeyException("failed to read a file: " + file, e);
}
Matcher m = KEY_PATTERN.matcher(content);
if (!m.find()) {
throw new KeyException("found no private key: " + file);
}
ByteBuf base64 = Unpooled.copiedBuffer(m.group(1), CharsetUtil.US_ASCII);
ByteBuf der = Base64.decode(base64);
base64.release();
return der;
}
示例8: a
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
private void a(ServerPing serverping) {
File file = this.d("server-icon.png");
if (file.isFile()) {
ByteBuf bytebuf = Unpooled.buffer();
try {
BufferedImage bufferedimage = ImageIO.read(file);
Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
ImageIO.write(bufferedimage, "PNG", new ByteBufOutputStream(bytebuf));
ByteBuf bytebuf1 = Base64.encode(bytebuf);
serverping.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
} catch (Exception exception) {
MinecraftServer.LOGGER.error("Couldn\'t load server icon", exception);
} finally {
bytebuf.release();
}
}
}
示例9: func_147138_a
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
private void func_147138_a(ServerStatusResponse p_147138_1_)
{
File var2 = this.getFile("server-icon.png");
if (var2.isFile())
{
ByteBuf var3 = Unpooled.buffer();
try
{
BufferedImage var4 = ImageIO.read(var2);
Validate.validState(var4.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(var4.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
ImageIO.write(var4, "PNG", new ByteBufOutputStream(var3));
ByteBuf var5 = Base64.encode(var3);
p_147138_1_.func_151320_a("data:image/png;base64," + var5.toString(Charsets.UTF_8));
}
catch (Exception var6)
{
logger.error("Couldn\'t load server icon", var6);
}
}
}
示例10: performAuth
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
/**
* Performs auth.
*/
private void performAuth() {
byte[] authToken = ("\0" + jid.getNode() + "\0" + password).getBytes(StandardCharsets.UTF_8);
Element auth = new Element("auth", "urn:ietf:params:xml:ns:xmpp-sasl");
auth.setAttribute("mechanism", "PLAIN");
ByteBuf rawCredentials = channel.get().alloc().buffer().writeBytes(authToken);
ByteBuf encodedCredentials = Base64.encode(rawCredentials);
String encodedCredentialsString = encodedCredentials.toString(StandardCharsets.UTF_8);
encodedCredentials.release();
rawCredentials.release();
auth.setText(encodedCredentialsString);
channel.get().writeAndFlush(auth);
}
示例11: create
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
public static String create(BufferedImage image) throws IOException {
checkArgument(image.getWidth() == 64, "favicon must be 64 pixels wide");
checkArgument(image.getHeight() == 64, "favicon must be 64 pixels high");
ByteBuf buf = Unpooled.buffer();
try {
ImageIO.write(image, "PNG", new ByteBufOutputStream(buf));
ByteBuf base64 = Base64.encode(buf);
try {
return FAVICON_PREFIX + base64.toString(Charsets.UTF_8);
} finally {
base64.release();
}
} finally {
buf.release();
}
}
示例12: loadServerIcon0
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
static CraftIconCache loadServerIcon0(BufferedImage image) throws Exception {
ByteBuf bytebuf = Unpooled.buffer();
Validate.isTrue(image.getWidth() == 64, "Must be 64 pixels wide");
Validate.isTrue(image.getHeight() == 64, "Must be 64 pixels high");
ImageIO.write(image, "PNG", new ByteBufOutputStream(bytebuf));
ByteBuf bytebuf1 = Base64.encode(bytebuf);
return new CraftIconCache("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
}
示例13: decodeProtected
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
private void decodeProtected(Reply reply) {
if (!reply.isProtected()) throw new
RuntimeException("Unprotected reply on protected channel.");
for (String s : reply.lines()) try {
ByteBuf eb = Unpooled.wrappedBuffer(s.getBytes(data.encoding));
ByteBuf db = data.security.unprotect(Base64.decode(eb));
protCodec.feed(new Slice(db).asBytes());
} catch (Exception e) {
throw new RuntimeException("Bad reply from server.", e);
}
}
示例14: handshake
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
private Bell<Reply> handshake(final SecurityContext sec, ByteBuf it) {
final Bell<Reply> bell = new Bell<Reply>();
try {
ByteBuf ot = Base64.encode(sec.handshake(it), false);
Log.finer("Sending ADAT: ", ot);
new Command("ADAT", ot.toString(data.encoding)) {
public void done(Reply r) throws Exception {
if (r.isIncomplete()) {
String line = r.message().substring(5);
ByteBuf bb = Unpooled.wrappedBuffer(line.getBytes(data.encoding));
ByteBuf token = Base64.decode(bb);
handshake(sec, token).promise(bell);
} else if (r.isComplete()) {
promise(bell);
} else {
throw r.asError();
}
}
};
} catch (Exception e) {
Log.fine("ADAT failed: ", e);
bell.ring(e);
}
return bell;
}
示例15: addFaviconToStatusResponse
import io.netty.handler.codec.base64.Base64; //导入依赖的package包/类
private void addFaviconToStatusResponse(ServerStatusResponse response)
{
File file1 = this.getFile("server-icon.png");
if (file1.isFile())
{
ByteBuf bytebuf = Unpooled.buffer();
try
{
BufferedImage bufferedimage = ImageIO.read(file1);
Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf)));
ByteBuf bytebuf1 = Base64.encode(bytebuf);
response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
}
catch (Exception exception)
{
logger.error((String)"Couldn\'t load server icon", (Throwable)exception);
}
finally
{
bytebuf.release();
}
}
}