- 浏览: 326154 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
hdwmp123:
GGGGeek 写道HTMLLayout布局的邮件被QQ邮箱拒 ...
logback配置错误邮件发送 -
GGGGeek:
HTMLLayout布局的邮件被QQ邮箱拒收了,代理服务用的是 ...
logback配置错误邮件发送 -
Inmethetiger:
在windows下面用;分隔,linux下面用:分隔。 在 ...
【转】程序包com.sun.image.codec.jpeg不存在 问题的完美解决 -
wuxiaozeng2440:
感动了,谢谢
这世界上你最在乎的人 -
ahong520:
很重要的一点,安装完xcode后还需要到xcode prefe ...
MAC下配置Eclipse Java/C++ 开发环境
package util;
import java.io.UnsupportedEncodingException;
/**
* Provides encoding of raw bytes to base64-encoded characters, and decoding of
* base64 characters to raw bytes.
*
* @author Kevin Kelley (kelley@ruralnet.net)
* @version 1.3
* @date 06 August 1998
* @modified 14 February 2000
* @modified 22 September 2000
*/
public class Base64
{
private static final String URL_ENCODE = "UTF-8";
private static final String BASE64_ENCODE = "GBK";
public static String encodeURL(String str)
{
try
{
str = java.net.URLEncoder.encode(str, URL_ENCODE);
} catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
public static String decodeURL(String str)
{
try
{
str = java.net.URLDecoder.decode(str, URL_ENCODE);
} catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
/**
* returns an array of base64-encoded characters to represent the passed
* data array.
*
* @param data
* the array of bytes to encode
* @return base64-coded character array.
*/
static public char[] encode(byte[] data)
{
char[] out = new char[((data.length + 2) / 3) * 4];
//
// 3 bytes encode to 4 chars. Output is always an even
// multiple of 4 characters.
//
for (int i = 0, index = 0; i < data.length; i += 3, index += 4)
{
boolean quad = false;
boolean trip = false;
int val = (0xFF & (int) data[i]);
val <<= 8;
if ((i + 1) < data.length)
{
val |= (0xFF & (int) data[i + 1]);
trip = true;
}
val <<= 8;
if ((i + 2) < data.length)
{
val |= (0xFF & (int) data[i + 2]);
quad = true;
}
out[index + 3] = alphabet[(quad ? (val & 0x3F) : 64)];
val >>= 6;
out[index + 2] = alphabet[(trip ? (val & 0x3F) : 64)];
val >>= 6;
out[index + 1] = alphabet[val & 0x3F];
val >>= 6;
out[index + 0] = alphabet[val & 0x3F];
}
return out;
}
/**
* Decodes a BASE-64 encoded stream to recover the original data. White
* space before and after will be trimmed away, but no other manipulation of
* the input will be performed.
*
* As of version 1.2 this method will properly handle input containing junk
* characters (newlines and the like) rather than throwing an error. It does
* this by pre-parsing the input and generating from that a count of VALID
* input characters.
*/
static public byte[] decode(char[] data)
{
// as our input could contain non-BASE64 data (newlines,
// whitespace of any sort, whatever) we must first adjust
// our count of USABLE data so that...
// (a) we don't misallocate the output array, and
// (b) think that we miscalculated our data length
// just because of extraneous throw-away junk
int tempLen = data.length;
for (int ix = 0; ix < data.length; ix++)
{
if ((data[ix] > 255) || codes[data[ix]] < 0)
--tempLen; // ignore non-valid chars and padding
}
// calculate required length:
// -- 3 bytes for every 4 valid base64 chars
// -- plus 2 bytes if there are 3 extra base64 chars,
// or plus 1 byte if there are 2 extra.
int len = (tempLen / 4) * 3;
if ((tempLen % 4) == 3)
len += 2;
if ((tempLen % 4) == 2)
len += 1;
byte[] out = new byte[len];
int shift = 0; // # of excess bits stored in accum
int accum = 0; // excess bits
int index = 0;
// we now go through the entire array (NOT using the 'tempLen' value)
for (int ix = 0; ix < data.length; ix++)
{
int value = (data[ix] > 255) ? -1 : codes[data[ix]];
if (value >= 0) // skip over
// non-code
{
accum <<= 6; // bits
// shift up
// by 6 each
// time thru
shift += 6; // loop,
// with new
// bits
// being put
// in
accum |= value; // at the
// bottom.
if (shift >= 8) // whenever
// there are
// 8 or more
// shifted
// in,
{
shift -= 8; // write
// them out
// (from the
// top,
// leaving
// any
out[index++] = // excess at the
// bottom for
// next
// iteration.
(byte) ((accum >> shift) & 0xff);
}
}
// we will also have skipped processing a padding null byte
// ('=') here;
// these are used ONLY for padding to an even length and do not
// legally
// occur as encoded data. for this reason we can ignore the fact
// that
// no index++ operation occurs in that special case: the out[]
// array is
// initialized to all-zero bytes to start with and that works to
// our
// advantage in this combination.
}
// if there is STILL something wrong we just have to throw up now!
if (index != out.length)
{
throw new Error("Miscalculated data length (wrote " + index
+ " instead of " + out.length + ")");
}
return out;
}
/**
* added by Neal
*
* @param str
* String
* @return String
*/
public static String encodeString(String str)
{
byte[] bt = null;
try
{
bt = str.getBytes(BASE64_ENCODE);
} catch (UnsupportedEncodingException e)
{
// TODO Auto-generated catch block
bt = str.getBytes();
e.printStackTrace();
}
char[] cArray = Base64.encode(bt);
return new String(cArray);
}
/**
* added by Neal
*
* @param str
* String
* @return String
*/
public static String decodeString(String str)
{
char[] cArray = str.toCharArray();
byte[] bt = Base64.decode(cArray);
return (new String(bt));
}
//
// code characters for values 0..63
//
static private char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
.toCharArray();
//
// lookup table for converting base64 characters to value in range 0..63
//
static private byte[] codes = new byte[256];
static
{
for (int i = 0; i < 256; i++)
codes[i] = -1;
for (int i = 'A'; i <= 'Z'; i++)
codes[i] = (byte) (i - 'A');
for (int i = 'a'; i <= 'z'; i++)
codes[i] = (byte) (26 + i - 'a');
for (int i = '0'; i <= '9'; i++)
codes[i] = (byte) (52 + i - '0');
codes['+'] = 62;
codes['/'] = 63;
}
public static void main(String[] args)
{
String str = "中文测试";
String encodeStr = Base64.encodeURL(Base64.encodeString(str));
System.out.println(encodeStr);
System.out.println(Base64.decodeString(Base64.decodeURL(encodeStr)));
}
}
发表评论
-
将本地已有的一个项目上传到新建的git仓库的方法
2019-03-21 16:33 565将本地已有的一个非git项目上传到新建的git仓库的方法一共有 ... -
mac 忘记root密码
2014-04-14 22:14 824sudo bash password:输入你的当前用户密码 b ... -
RESTEasy 3 broken with Spring 4.0
2014-03-26 13:18 2415问题描述: ------------------------- ... -
eclipse中文注释字体大小如何修改
2014-03-21 12:03 9351貌似没有直接的办法,但是可以取个巧: Window --> ... -
eclipse中集成jad反编译
2014-03-18 14:06 905转载地址:http://www.blogjava.net/sy ... -
eclipse 插件 File Explorer
2014-03-17 17:58 3917ExploreFS的安装地址: 在eclipse中Help – ... -
[转]Mac下搭建svn服务器和XCode配置svn
2014-03-02 19:33 1221转载自:http://blog.csdn.net/jjunjo ... -
[转]Wireshark基本介绍和学习TCP三次握手
2013-11-17 16:04 892Wireshark基本介绍和学习TCP三次握手http:/ ... -
数据压缩解压缩(zip)
2013-11-05 14:06 1003网络上传输数据大部分都需要压缩数据后传递,常见的有zip方式压 ... -
html页面内容自动换行显示
2013-03-25 11:32 1293style="word-break:break-al ... -
js编码转码中文
2013-03-25 11:29 3393javascript汉字编码与转码: <!DOCT ... -
Eclipse get/set方法 自动加上字段注释
2013-03-15 10:47 2882编码的时候通常要用到 JavaBean ,而在我们经常把注释写 ... -
gcd算法(求最大公约数)
2012-12-27 15:37 4583gcd算法:给定俩个正整数m,n(m>=n),求它们 ... -
xml内容解析,包含命名空间时需特殊处理(dom4j)
2012-12-19 12:53 2048你是否在解析xml内容的时候遇到包含命名空间的解析不到内容的情 ... -
标准对联广告Js代码
2012-07-30 17:09 1319标准对联广告Js代码 用于门户网站两侧的“对联广告” &l ... -
制作Mountain Lion安装U盘
2012-07-27 09:56 1238转自:http://tech.sina.com.cn/s/20 ... -
【转】linux文件系统构成 与硬盘操作
2012-06-01 14:10 1211转载自:http://blog.chinaunix.net/u ... -
【转】linux下常用的故障排查命令行
2012-05-31 11:55 12001.查看TCP连接状态 netstat ... -
HttpClient支持使用代理服务器以及身份认证
2012-05-30 22:51 5595HttpClient Authentication Doume ... -
[转]Linux的五个查找命令:find,locate,whereis,which,type
2012-04-15 11:37 1315在Linux中,有很多方法 ...
相关推荐
1.程序功能说明: MATLAB实现多种群遗传算法(完整代码) 逼近C=[9,8,7,6,5,4,3,2,1]的9维向量. 2.代码说明:注释清晰,参数和变量说明清晰,方便更改、方便初学者使用,模块化编程,方便替换目标函数。运行环境Windows7及以上操作系统,MATLAB2014a及以上版本。 3.适用专业:计算机、电子信息工程、数学、物理、机械工程、土木工程等专业的大学生、研究生毕业设计,各类专业的课程设计、海外留学生作业等。 4作者介绍:资深算法工程师, 从事Matlab、Python算法仿真工作15年,专业研究遗传算法、粒子群算法、蚁群算法、鲸鱼算法、狼群算法等. 有问题联系QQ: 1579325979
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
免费JAVA毕业设计 2024成品源码+论文+录屏+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
小学元旦晚会PPT 模版
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
MATLAB中的语义分割技术探究与应用实践,matlab,语义分割 ,matlab; 语义分割,Matlab语义分割技术解析
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
1、文件内容:pulseaudio-10.0-6.el7_9.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/pulseaudio-10.0-6.el7_9.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、安装指导:私信博主,全程指导安装
"基于OpenCV与深度学习的人脸表情识别系统:利用Python与PyQt构建的可视化实时检测工具",基于OpenCV的人脸表情识别系统 相关技术:python,opencv,pyqt,深度学习 (请自行安装向日葵远程软件,以便提供远程帮助) 可编译为.exe文件。 软件说明:摄像头实时检测,加载照片,视频均可。 有基础的同学,可自行修改完善。 第一张和第二张为运行截图。 ,基于OpenCV的人脸表情识别系统; Python; OpenCV; PyQt; 深度学习; 实时检测; 照片和视频支持; 可编译为.exe文件; 运行截图。,"基于OpenCV与深度学习的人脸表情识别系统"
,步进方案,步进源码,两相步进矢量控制,超前角控制两种模式,成熟产品方案 支持特殊功能定制
三相储能PCS双向能量流动与Matlab仿真控制研究——基于SVPWM调制技术的建模与应用,三相储能PCS(Matlab仿真) 1.可实现Grid to Battery,Battery to Grid的能量双向流动。 2.本仿真基于Matlab仿真建立的模型, 3.采用SVPWM进行控制 ,三相储能PCS; 双向能量流动; Matlab仿真; SVPWM控制,三相储能PCS:能量双向流Matlab仿真模型(SVPWM控制)
deepseek部署教程.md
nodejs010-nodejs-ansicolors-0.3.2-1.el6.centos.alt.noarch.rpm
基于三菱PLC的四路抢答器控制系统原理及实践:含带解释的梯形图与IO分配图解,三菱 MCGS 基于PLC的四路抢答器控制系统 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,三菱MCGS; PLC四路抢答器; 控制系统; 梯形图接线图; 原理图图纸; IO分配; 组态画面。,三菱PLC四路抢答器控制系统原理图及组态画面解析
基于运动数据时空特征提取的人类运动片段.pdf
基于机器学习的选股模型及投资组合研究.pdf
ollama安装包。。。。。。。。。。。。。。。。。
nodejs010-nodejs-ansistyles-0.1.3-1.el6.centos.alt.x86_64.rpm
Screenshot_20250201_111207_com_tencent_mm_LauncherUI.jpg
基于时空Transformer的端到端的视频注视目标检测.pdf