static ByteBuf[] readCertificates(File file) throws CertificateException { String content; try { content = readContent(file); } catch (IOException e) { throw new CertificateException("failed to read a file: " + file, e); } List<ByteBuf> certs = new ArrayList<ByteBuf>(); Matcher m = CERT_PATTERN.matcher(content); int start = 0; for (; ; ) { if (!m.find(start)) { break; } ByteBuf base64 = Unpooled.copiedBuffer(m.group(1), CharsetUtil.US_ASCII); ByteBuf der = Base64.decode(base64); base64.release(); certs.add(der); start = m.end(); } if (certs.isEmpty()) { throw new CertificateException("found no certificates: " + file); } return certs.toArray(new ByteBuf[certs.size()]); }
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); } }
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; }
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(); } } }
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); }