io.netty.handler.codec.base64.Base64 # decode ( ) 源码实例Demo

下面列出了 io.netty.handler.codec.base64.Base64 # decode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: WeCross   文件: KeyCertLoader.java

ByteBuf readPrivateKey(InputStream in) throws KeyException {
    String content;
    try {
        content = readContent(in);
    } catch (IOException e) {
        throw new KeyException("failed to read key input stream", e);
    }

    Matcher m = KEY_PATTERN.matcher(content);
    if (!m.find()) {
        throw new KeyException(
                "could not find a PKCS #8 private key in input stream"
                        + " (see https://netty.io/wiki/sslcontextbuilder-and-private-key.html for more information)");
    }

    ByteBuf base64 = Unpooled.copiedBuffer(m.group(1), CharsetUtil.US_ASCII);
    ByteBuf der = Base64.decode(base64);
    base64.release();
    return der;
}
 

/**
 * Decodes the settings header and returns a {@link Http2Settings} object.
 */
private Http2Settings decodeSettingsHeader(ChannelHandlerContext ctx, CharSequence settingsHeader)
        throws Http2Exception {
    ByteBuf header = ByteBufUtil.encodeString(ctx.alloc(), CharBuffer.wrap(settingsHeader), CharsetUtil.UTF_8);
    try {
        // Decode the SETTINGS payload.
        ByteBuf payload = Base64.decode(header, URL_SAFE);

        // Create an HTTP/2 frame for the settings.
        ByteBuf frame = createSettingsFrame(ctx, payload);

        // Decode the SETTINGS frame and return the settings object.
        return decodeSettings(ctx, frame);
    } finally {
        header.release();
    }
}
 
源代码3 项目: netty-4.1.22   文件: PemReader.java

static ByteBuf readPrivateKey(InputStream in) throws KeyException {
    String content;
    try {
        content = readContent(in);
    } catch (IOException e) {
        throw new KeyException("failed to read key input stream", e);
    }

    Matcher m = KEY_PATTERN.matcher(content);
    if (!m.find()) {
        throw new KeyException("could not find a PKCS #8 private key in input stream" +
                " (see http://netty.io/wiki/sslcontextbuilder-and-private-key.html for more information)");
    }

    ByteBuf base64 = Unpooled.copiedBuffer(m.group(1), CharsetUtil.US_ASCII);
    ByteBuf der = Base64.decode(base64);
    base64.release();
    return der;
}
 
源代码4 项目: netty4.0.27Learn   文件: PemReader.java

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;
}
 
源代码5 项目: The-5zig-Mod   文件: Base64Renderer.java

private void prepareImage() {
	if (base64String == null) {
		delete(resourceLocation);
		this.dynamicImage = null;
		return;
	}
	ByteBuf localByteBuf1 = Unpooled.copiedBuffer(base64String, Charsets.UTF_8);
	ByteBuf localByteBuf2 = null;
	BufferedImage localBufferedImage;
	try {
		localByteBuf2 = Base64.decode(localByteBuf1);
		localBufferedImage = read(new ByteBufInputStream(localByteBuf2));
		Validate.validState(localBufferedImage.getWidth() == width, "Must be " + width + " pixels wide");
		Validate.validState(localBufferedImage.getHeight() == height, "Must be " + height + " pixels high");
	} catch (Exception e) {
		The5zigMod.logger.error("Could not prepare base64 renderer image", e);
		delete(resourceLocation);
		dynamicImage = null;
		return;
	} finally {
		localByteBuf1.release();
		if (localByteBuf2 != null) {
			localByteBuf2.release();
		}
	}
	if (this.dynamicImage == null) {
		this.dynamicImage = The5zigMod.getVars().loadDynamicImage(resourceLocation.callGetResourcePath(), localBufferedImage);
	}
}
 
源代码6 项目: The-5zig-Mod   文件: Base64Renderer.java

private void prepareImage() {
	if (base64String == null) {
		delete(resourceLocation);
		this.dynamicImage = null;
		return;
	}
	ByteBuf localByteBuf1 = Unpooled.copiedBuffer(base64String, Charsets.UTF_8);
	ByteBuf localByteBuf2 = null;
	BufferedImage localBufferedImage;
	try {
		localByteBuf2 = Base64.decode(localByteBuf1);
		localBufferedImage = read(new ByteBufInputStream(localByteBuf2));
		Validate.validState(localBufferedImage.getWidth() == width, "Must be " + width + " pixels wide");
		Validate.validState(localBufferedImage.getHeight() == height, "Must be " + height + " pixels high");
	} catch (Exception e) {
		The5zigMod.logger.error("Could not prepare base64 renderer image", e);
		delete(resourceLocation);
		dynamicImage = null;
		return;
	} finally {
		localByteBuf1.release();
		if (localByteBuf2 != null) {
			localByteBuf2.release();
		}
	}
	if (this.dynamicImage == null) {
		this.dynamicImage = The5zigMod.getVars().loadDynamicImage(resourceLocation.getResourcePath(), localBufferedImage);
	}
}
 
源代码7 项目: WeCross   文件: KeyCertLoader.java

public ByteBuf[] readCertificates(InputStream in) throws CertificateException {
    String content;
    try {
        content = readContent(in);
    } catch (IOException e) {
        throw new CertificateException("failed to read certificate input stream", 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 in input stream");
    }

    return certs.toArray(new ByteBuf[0]);
}
 
源代码8 项目: netty-4.1.22   文件: HttpProxyServer.java

private boolean authenticate(ChannelHandlerContext ctx, FullHttpRequest req) {
    assertThat(req.method(), is(HttpMethod.CONNECT));

    if (testMode != TestMode.INTERMEDIARY) {
        ctx.pipeline().addBefore(ctx.name(), "lineDecoder", new LineBasedFrameDecoder(64, false, true));
    }

    ctx.pipeline().remove(HttpObjectAggregator.class);
    ctx.pipeline().get(HttpServerCodec.class).removeInboundHandler();

    boolean authzSuccess = false;
    if (username != null) {
        CharSequence authz = req.headers().get(HttpHeaderNames.PROXY_AUTHORIZATION);
        if (authz != null) {
            String[] authzParts = authz.toString().split(" ", 2);
            ByteBuf authzBuf64 = Unpooled.copiedBuffer(authzParts[1], CharsetUtil.US_ASCII);
            ByteBuf authzBuf = Base64.decode(authzBuf64);

            String expectedAuthz = username + ':' + password;
            authzSuccess = "Basic".equals(authzParts[0]) &&
                           expectedAuthz.equals(authzBuf.toString(CharsetUtil.US_ASCII));

            authzBuf64.release();
            authzBuf.release();
        }
    } else {
        authzSuccess = true;
    }

    return authzSuccess;
}
 
源代码9 项目: netty-4.1.22   文件: PemReader.java

static ByteBuf[] readCertificates(InputStream in) throws CertificateException {
    String content;
    try {
        content = readContent(in);
    } catch (IOException e) {
        throw new CertificateException("failed to read certificate input stream", 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 in input stream");
    }

    return certs.toArray(new ByteBuf[certs.size()]);
}
 
源代码10 项目: netty4.0.27Learn   文件: PemReader.java

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()]);
}
 
源代码11 项目: netty-cookbook   文件: NettyHttpUtil.java

public static FullHttpResponse theBase64Image1pxGif() {
	ByteBuf byteBuf = Base64.decode(Unpooled.copiedBuffer(BASE64GIF_BYTES));
	FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK , byteBuf);
	response.headers().set(CONTENT_TYPE, ContentTypePool.GIF);
	response.headers().set(CONTENT_LENGTH, byteBuf.readableBytes());
	response.headers().set(CONNECTION, HEADER_CONNECTION_CLOSE);
	return response;
}
 
源代码12 项目: netty-cookbook   文件: NettyHttpUtil.java

public static FullHttpResponse theBase64Image1pxGif() {
	ByteBuf byteBuf = Base64.decode(Unpooled.copiedBuffer(BASE64GIF_BYTES));
	FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK , byteBuf);
	response.headers().set(CONTENT_TYPE, ContentTypePool.GIF);
	response.headers().set(CONTENT_LENGTH, byteBuf.readableBytes());
	response.headers().set(CONNECTION, HEADER_CONNECTION_CLOSE);
	return response;
}
 
源代码13 项目: netty-cookbook   文件: NettyHttpUtil.java

public static FullHttpResponse theBase64Image1pxGif() {
	ByteBuf byteBuf = Base64.decode(Unpooled.copiedBuffer(BASE64GIF_BYTES));
	FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK , byteBuf);
	response.headers().set(CONTENT_TYPE, ContentTypePool.GIF);
	response.headers().set(CONTENT_LENGTH, byteBuf.readableBytes());
	response.headers().set(CONNECTION, HEADER_CONNECTION_CLOSE);
	return response;
}
 
源代码14 项目: netty-cookbook   文件: NettyHttpUtil.java

public static FullHttpResponse theBase64Image1pxGif() {
	ByteBuf byteBuf = Base64.decode(Unpooled.copiedBuffer(BASE64GIF_BYTES));
	FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK , byteBuf);
	response.headers().set(CONTENT_TYPE, ContentTypePool.GIF);
	response.headers().set(CONTENT_LENGTH, byteBuf.readableBytes());
	response.headers().set(CONNECTION, HEADER_CONNECTION_CLOSE);
	return response;
}
 
源代码15 项目: netty-cookbook   文件: NettyHttpUtil.java

public static FullHttpResponse theBase64Image1pxGif() {
	ByteBuf byteBuf = Base64.decode(Unpooled.copiedBuffer(BASE64GIF_BYTES));
	FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK , byteBuf);
	response.headers().set(CONTENT_TYPE, ContentTypePool.GIF);
	response.headers().set(CONTENT_LENGTH, byteBuf.readableBytes());
	response.headers().set(CONNECTION, HEADER_CONNECTION_CLOSE);
	return response;
}
 
源代码16 项目: netty-cookbook   文件: NettyHttpUtil.java

public static FullHttpResponse theBase64Image1pxGif() {
	ByteBuf byteBuf = Base64.decode(Unpooled.copiedBuffer(BASE64GIF_BYTES));
	FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK , byteBuf);
	response.headers().set(CONTENT_TYPE, ContentTypePool.GIF);
	response.headers().set(CONTENT_LENGTH, byteBuf.readableBytes());
	response.headers().set(CONNECTION, HEADER_CONNECTION_CLOSE);
	return response;
}
 
源代码17 项目: netty-cookbook   文件: NettyHttpUtil.java

public static FullHttpResponse theBase64Image1pxGif() {
	ByteBuf byteBuf = Base64.decode(Unpooled.copiedBuffer(BASE64GIF_BYTES));
	FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK , byteBuf);
	response.headers().set(CONTENT_TYPE, ContentTypePool.GIF);
	response.headers().set(CONTENT_LENGTH, byteBuf.readableBytes());
	response.headers().set(CONNECTION, HEADER_CONNECTION_CLOSE);
	return response;
}