本文整理汇总了Java中io.netty.handler.codec.base64.Base64.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encode方法的具体用法?Java Base64.encode怎么用?Java Base64.encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.base64.Base64
的用法示例。
在下文中一共展示了Base64.encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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);
}
示例3: 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();
}
}
}
}
示例4: 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();
}
}
示例5: 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();
}
}
}
示例6: 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);
}
}
}
示例7: 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);
}
示例8: 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();
}
}
示例9: 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));
}
示例10: 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;
}
示例11: 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();
}
}
}
示例12: applyServerIconToResponse
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
public void applyServerIconToResponse(ServerStatusResponse response)
{
File file1 = this.getFile("server-icon.png");
if (!file1.exists())
{
file1 = this.getActiveAnvilConverter().getFile(this.getFolderName(), "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)
{
LOG.error((String)"Couldn\'t load server icon", (Throwable)exception);
}
finally
{
bytebuf.release();
}
}
}
示例13: Base64AuthToken
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
public Base64AuthToken(String user, String password) throws Exception
{
_user = user;
String data = user + ":" + password;
ByteBuf digest = Base64.encode(Unpooled.wrappedBuffer(data
.getBytes("UTF-8")));
byte[] digestBytes = new byte[digest.readableBytes()];
digest.readBytes(digestBytes);
super.setPassword(new String(digestBytes));
}
示例14: encodeNBT
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
static String encodeNBT(NBTTagCompound tag) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(baos));
CompressedStreamTools.write(tag, dos);
dos.close();
byte[] compressedData = baos.toByteArray();
ByteBuf enc = Base64.encode(Unpooled.copiedBuffer(compressedData));
return new String(enc.array());
}
示例15: base64
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
/**
* Performs base64 encoding on the specified data
*
* @param data The data to encode
* @return An encoded string containing the data
*/
static String base64(byte[] data) {
ByteBuf encodedData = Unpooled.wrappedBuffer(data);
ByteBuf encoded = Base64.encode(encodedData);
String encodedString = encoded.toString(CharsetUtil.UTF_8);
encoded.release();
return encodedString;
}