本文整理汇总了Java中io.netty.handler.codec.base64.Base64.decode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.decode方法的具体用法?Java Base64.decode怎么用?Java Base64.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.base64.Base64
的用法示例。
在下文中一共展示了Base64.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
/**
* Decodes the buffered image from the encoded favicon string.
*
* @param encoded the encoded string
* @return the buffered image
*/
private static BufferedImage decode(String encoded) throws IOException {
checkArgument(encoded.startsWith(FAVICON_PREFIX), "unknown favicon format");
ByteBuf base64 = Unpooled.copiedBuffer(encoded.substring(FAVICON_PREFIX.length()), StandardCharsets.UTF_8);
try {
ByteBuf buf = Base64.decode(base64);
try {
BufferedImage result = ImageIO.read(new ByteBufInputStream(buf));
checkState(result.getWidth() == 64, "favicon must be 64 pixels wide");
checkState(result.getHeight() == 64, "favicon must be 64 pixels high");
return result;
} finally {
buf.release();
}
} finally {
base64.release();
}
}
示例2: readPrivateKey
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
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;
}
示例3: 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;
}
示例4: extractBasicAuthSubject
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
/**
* Extracts the username and password details from the HTTP basic header Authorization.
* <p/>
* This requires that the <tt>Authorization</tt> HTTP header is provided, and its using Basic.
* Currently Digest is <b>not</b> supported.
*
* @return {@link HttpPrincipal} with username and password details, or <tt>null</tt> if not possible to extract
*/
protected static HttpPrincipal extractBasicAuthSubject(HttpRequest request) {
String auth = request.headers().get("Authorization");
if (auth != null) {
String constraint = ObjectHelper.before(auth, " ");
if (constraint != null) {
if ("Basic".equalsIgnoreCase(constraint.trim())) {
String decoded = ObjectHelper.after(auth, " ");
// the decoded part is base64 encoded, so we need to decode that
ByteBuf buf = NettyConverter.toByteBuffer(decoded.getBytes());
ByteBuf out = Base64.decode(buf);
try {
String userAndPw = out.toString(Charset.defaultCharset());
String username = ObjectHelper.before(userAndPw, ":");
String password = ObjectHelper.after(userAndPw, ":");
HttpPrincipal principal = new HttpPrincipal(username, password);
LOG.debug("Extracted Basic Auth principal from HTTP header: {}", principal);
return principal;
} finally {
buf.release();
out.release();
}
}
}
}
return null;
}
示例5: theBase64Image1pxGif
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
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;
}
示例6: readCertificates
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
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()]);
}
示例7: getPrivateKeyBytes
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
/**
* Obtains the private key data as a byte array from the PEM file.
* <p>
* Within the PEM file the private key data is base 64 encoded. This method will decode the data for the returned private key
* data.
* <p>
* Note that for an encrypted private key the data will remain encrypted.
*
* @return The private key data.
* @throws KeyException If a private key cannot be found in the PEM file.
* @throws IOException If the PEM file cannot be read for any reason.
*/
public byte[] getPrivateKeyBytes() throws KeyException, IOException {
final String methodName = "getPrivateKeyBytes";
logger.entry(this, methodName);
final String fileData = getPemFileData();
Matcher m = KEY_PATTERN.matcher(fileData);
final byte[] keyBytes;
final String base64KeyDataStr;
if (m.find()) {
base64KeyDataStr = m.group(1);
} else {
m = ENCRYPTED_KEY_PATTERN.matcher(fileData);
if (m.find()) {
base64KeyDataStr = m.group(1);
} else {
final KeyException exception = new KeyException("Private key not found in PEM file: " + pemFile);
logger.throwing(this, methodName, exception);
throw exception;
}
}
final ByteBuf base64KeyData = Unpooled.copiedBuffer(base64KeyDataStr, Charset.forName("US-ASCII"));
final ByteBuf keyData = Base64.decode(base64KeyData);
base64KeyData.release();
keyBytes = new byte[keyData.readableBytes()];
keyData.readBytes(keyBytes).release();
logger.exit(this, methodName, keyBytes);
return keyBytes;
}
示例8: base64ToByteArray
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
public static byte[] base64ToByteArray(String base64Msg) {
ByteBuf buffer = Base64
.decode(Unpooled.wrappedBuffer(base64Msg.getBytes(Charset.forName("ASCII"))));
byte[] msg = new byte[buffer.readableBytes()];
buffer.readBytes(msg);
buffer.release();
return msg;
}
示例9: prepareServerIcon
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
private void prepareServerIcon()
{
if (this.field_148301_e.getBase64EncodedIconData() == null)
{
this.mc.getTextureManager().deleteTexture(this.field_148306_i);
this.field_148305_h = null;
}
else
{
ByteBuf bytebuf = Unpooled.copiedBuffer((CharSequence)this.field_148301_e.getBase64EncodedIconData(), Charsets.UTF_8);
ByteBuf bytebuf1 = Base64.decode(bytebuf);
BufferedImage bufferedimage;
label101:
{
try
{
bufferedimage = TextureUtil.readBufferedImage(new ByteBufInputStream(bytebuf1));
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]);
break label101;
}
catch (Throwable throwable)
{
logger.error("Invalid icon for server " + this.field_148301_e.serverName + " (" + this.field_148301_e.serverIP + ")", throwable);
this.field_148301_e.setBase64EncodedIconData((String)null);
}
finally
{
bytebuf.release();
bytebuf1.release();
}
return;
}
if (this.field_148305_h == null)
{
this.field_148305_h = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
this.mc.getTextureManager().loadTexture(this.field_148306_i, this.field_148305_h);
}
bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.field_148305_h.getTextureData(), 0, bufferedimage.getWidth());
this.field_148305_h.updateDynamicTexture();
}
}
示例10: authenticate
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
public static boolean authenticate(HTTPCarbonMessage httpCarbonMessage) {
if (HttpIODataHolder.getInstance().getBundleContext() == null) {
//this will handle the events at non osgi mode.
return true;
} else {
String authHeader = httpCarbonMessage.getHeaders().get(HttpConstants.AUTHORIZATION_HEADER);
if (authHeader != null) {
String usernamePasswordEncoded = authHeader.replace(HttpConstants.AUTHORIZATION_METHOD, "");
ByteBuf usernamePasswordBuf = Base64.decode(Unpooled.copiedBuffer(usernamePasswordEncoded.getBytes
(Charset
.defaultCharset())));
String[] usernamePassword = usernamePasswordBuf.toString(Charset.defaultCharset()).split(":");
IdPClient idPClient = HttpIODataHolder.getInstance().getClient();
if ((idPClient != null) && (usernamePassword.length == 2)) {
try {
Map<String, String> loginProperties = new HashMap<>();
loginProperties.put(IdPClientConstants.USERNAME, usernamePassword[0]);
loginProperties.put(IdPClientConstants.PASSWORD, usernamePassword[1]);
loginProperties.put(IdPClientConstants.GRANT_TYPE, IdPClientConstants.PASSWORD_GRANT_TYPE);
Map<String, String> login = idPClient.login(loginProperties);
String loginStatus = login.get(IdPClientConstants.LOGIN_STATUS);
if (loginStatus.equals(IdPClientConstants.LoginStatus.LOGIN_SUCCESS)) {
return true;
} else {
logger.error("Authentication failed for username '" + usernamePassword[0] + "'. Error : '"
+ login.get(IdPClientConstants.ERROR) + "'. Error Description : '"
+ login.get(IdPClientConstants.ERROR_DESCRIPTION) + "'");
return false;
}
} catch (IdPClientException e) {
logger.error("Authorization process fails for " + usernamePassword[0] + ":" +
usernamePassword[1], e);
return false;
}
} else {
logger.error("Authorization header in incorrect format. header: " + usernamePasswordEncoded);
return false;
}
} else {
logger.error("Authorization header 'null' ");
return false;
}
}
}
示例11: prepareServerIcon
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
private void prepareServerIcon()
{
if (this.server.getBase64EncodedIconData() == null)
{
this.mc.getTextureManager().deleteTexture(this.serverIcon);
this.icon = null;
}
else
{
ByteBuf bytebuf = Unpooled.copiedBuffer((CharSequence)this.server.getBase64EncodedIconData(), Charsets.UTF_8);
ByteBuf bytebuf1 = null;
BufferedImage bufferedimage;
label103:
{
try
{
bytebuf1 = Base64.decode(bytebuf);
bufferedimage = TextureUtil.readBufferedImage(new ByteBufInputStream(bytebuf1));
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]);
break label103;
}
catch (Throwable throwable)
{
LOGGER.error("Invalid icon for server {} ({})", new Object[] {this.server.serverName, this.server.serverIP, throwable});
this.server.setBase64EncodedIconData((String)null);
}
finally
{
bytebuf.release();
if (bytebuf1 != null)
{
bytebuf1.release();
}
}
return;
}
if (this.icon == null)
{
this.icon = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
this.mc.getTextureManager().loadTexture(this.serverIcon, this.icon);
}
bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.icon.getTextureData(), 0, bufferedimage.getWidth());
this.icon.updateDynamicTexture();
}
}
示例12: prepareServerIcon
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
private void prepareServerIcon()
{
if (this.server.getBase64EncodedIconData() == null)
{
this.mc.getTextureManager().deleteTexture(this.serverIcon);
this.icon = null;
}
else
{
ByteBuf bytebuf = Unpooled.copiedBuffer((CharSequence)this.server.getBase64EncodedIconData(), Charsets.UTF_8);
ByteBuf bytebuf1 = Base64.decode(bytebuf);
BufferedImage bufferedimage;
label101:
{
try
{
bufferedimage = TextureUtil.readBufferedImage(new ByteBufInputStream(bytebuf1));
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]);
break label101;
}
catch (Throwable throwable)
{
LOGGER.error("Invalid icon for server {} ({})", new Object[] {this.server.serverName, this.server.serverIP, throwable});
this.server.setBase64EncodedIconData((String)null);
}
finally
{
bytebuf.release();
bytebuf1.release();
}
return;
}
if (this.icon == null)
{
this.icon = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
this.mc.getTextureManager().loadTexture(this.serverIcon, this.icon);
}
bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.icon.getTextureData(), 0, bufferedimage.getWidth());
this.icon.updateDynamicTexture();
}
}
示例13: decodeNBT
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
static NBTTagCompound decodeNBT(String contents) throws IOException {
ByteBuf decoded = Base64.decode(Unpooled.copiedBuffer(contents.getBytes()));
ByteBufInputStream bais = new ByteBufInputStream(decoded);
return CompressedStreamTools.read(new DataInputStream(new GZIPInputStream(bais)));
}
示例14: prepareServerIcon
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
private void prepareServerIcon()
{
if (this.serverData.getBase64EncodedIconData() == null)
{
this.mc.getTextureManager().deleteTexture(this.resourceLocation);
this.texture = null;
}
else
{
ByteBuf bytebuf = Unpooled.copiedBuffer((CharSequence)this.serverData.getBase64EncodedIconData(), Charsets.UTF_8);
ByteBuf bytebuf1 = Base64.decode(bytebuf);
BufferedImage bufferedimage;
label101:
{
try
{
bufferedimage = TextureUtil.readBufferedImage(new ByteBufInputStream(bytebuf1));
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]);
break label101;
}
catch (Throwable throwable)
{
logger.error("Invalid icon for server " + this.serverData.serverName + " (" + this.serverData.serverIP + ")", throwable);
this.serverData.setBase64EncodedIconData((String)null);
}
finally
{
bytebuf.release();
bytebuf1.release();
}
return;
}
if (this.texture == null)
{
this.texture = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
this.mc.getTextureManager().loadTexture(this.resourceLocation, this.texture);
}
bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.texture.getTextureData(), 0, bufferedimage.getWidth());
this.texture.updateDynamicTexture();
}
}
示例15: func_148297_b
import io.netty.handler.codec.base64.Base64; //导入方法依赖的package包/类
private void func_148297_b()
{
if (this.field_148301_e.func_147409_e() == null)
{
this.field_148300_d.getTextureManager().func_147645_c(this.field_148306_i);
this.field_148305_h = null;
}
else
{
ByteBuf var2 = Unpooled.copiedBuffer(this.field_148301_e.func_147409_e(), Charsets.UTF_8);
ByteBuf var3 = Base64.decode(var2);
BufferedImage var1;
label74:
{
try
{
var1 = ImageIO.read(new ByteBufInputStream(var3));
Validate.validState(var1.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
Validate.validState(var1.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
break label74;
}
catch (Exception var8)
{
logger.error("Invalid icon for server " + this.field_148301_e.serverName + " (" + this.field_148301_e.serverIP + ")", var8);
this.field_148301_e.func_147407_a((String)null);
}
finally
{
var2.release();
var3.release();
}
return;
}
if (this.field_148305_h == null)
{
this.field_148305_h = new DynamicTexture(var1.getWidth(), var1.getHeight());
this.field_148300_d.getTextureManager().loadTexture(this.field_148306_i, this.field_148305_h);
}
var1.getRGB(0, 0, var1.getWidth(), var1.getHeight(), this.field_148305_h.getTextureData(), 0, var1.getWidth());
this.field_148305_h.updateDynamicTexture();
}
}