public void encodeJsonP(
      Integer jsonpIndex, Queue<Packet> packets, ByteBuf out, ByteBufAllocator allocator, int limit)
      throws IOException {
    boolean jsonpMode = jsonpIndex != null;

    ByteBuf buf = allocateBuffer(allocator);

    int i = 0;
    while (true) {
      Packet packet = packets.poll();
      if (packet == null || i == limit) {
        break;
      }

      ByteBuf packetBuf = allocateBuffer(allocator);
      encodePacket(packet, packetBuf, allocator, true);

      int packetSize = packetBuf.writerIndex();
      buf.writeBytes(toChars(packetSize));
      buf.writeBytes(B64_DELIMITER);
      buf.writeBytes(packetBuf);

      packetBuf.release();

      i++;

      for (ByteBuf attachment : packet.getAttachments()) {
        ByteBuf encodedBuf = Base64.encode(attachment, Base64Dialect.URL_SAFE);
        buf.writeBytes(toChars(encodedBuf.readableBytes() + 2));
        buf.writeBytes(B64_DELIMITER);
        buf.writeBytes(BINARY_HEADER);
        buf.writeBytes(encodedBuf);
      }
    }

    if (jsonpMode) {
      out.writeBytes(JSONP_HEAD);
      out.writeBytes(toChars(jsonpIndex));
      out.writeBytes(JSONP_START);
    }

    processUtf8(buf, out, jsonpMode);
    buf.release();

    if (jsonpMode) {
      out.writeBytes(JSONP_END);
    }
  }
예제 #2
0
  private void addFaviconToStatusResponse(ServerStatusResponse response) {
    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);
        response.setFavicon("data:image/png;base64," + var5.toString(Charsets.UTF_8));
      } catch (Exception var9) {
        logger.error("Couldn\'t load server icon", var9);
      } finally {
        var3.release();
      }
    }
  }
예제 #3
0
  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();
      }
    }
  }
 /**
  * Base 64 encoding
  *
  * @param bytes Bytes to encode
  * @return encoded string
  */
 protected String base64Encode(byte[] bytes) {
   ChannelBuffer hashed = ChannelBuffers.wrappedBuffer(bytes);
   return Base64.encode(hashed).toString(CharsetUtil.UTF_8);
 }