当前位置: 首页>>代码示例>>Java>>正文


Java Base64.encode方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:Hash.java

示例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);
}
 
开发者ID:didclab,项目名称:onedatashare,代码行数:22,代码来源:FTPChannel.java

示例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();
      }
    }
  }
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:19,代码来源:SparkSaslServer.java

示例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();
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:26,代码来源:LanternFavicon.java

示例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();
        }
    }

}
 
开发者ID:Prismarine,项目名称:Prismarine,代码行数:24,代码来源:MinecraftServer.java

示例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);
        }
    }
}
 
开发者ID:MinecraftModdedClients,项目名称:Resilience-Client-Source,代码行数:24,代码来源:MinecraftServer.java

示例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);
  }
 
开发者ID:Kixeye,项目名称:kixmpp,代码行数:20,代码来源:KixmppClient.java

示例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();
    }
}
 
开发者ID:Minecrell,项目名称:ServerListPlus,代码行数:18,代码来源:Favicon.java

示例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));
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:11,代码来源:CraftServer.java

示例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;
}
 
开发者ID:didclab,项目名称:onedatashare,代码行数:29,代码来源:FTPChannel.java

示例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();
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:28,代码来源:MinecraftServer.java

示例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();
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:33,代码来源:MinecraftServer.java

示例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));
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:11,代码来源:Base64AuthToken.java

示例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());
}
 
开发者ID:purpleposeidon,项目名称:Factorization,代码行数:10,代码来源:DocumentationModule.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:14,代码来源:WebSocketUtil.java


注:本文中的io.netty.handler.codec.base64.Base64.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。