我正在开发一个使用 HTTP GET 请求与服务器通信的 J2ME 应用程序。我已经有了一种生成 URL 编码参数的方法。
在目前的形式中,它不能满足空字符串,我见过的其他代码片段也有这个缺陷,因为它们都依赖于比较字符串参数的单个字符。我之前问过一个与这个空字符困境相关的问题
编辑:
对服务器(Play 1.0)的请求采用以下形式
http://server.com/setName/firstname/othername/lastname
参数不能为空,所以 http:server.com/setname/firstname//lastname 无效
参数是从 json 对象中检索的。目前,我拥有的 url 编码方法将对所有提取的参数进行正确编码,并保留任何无法按原样转换的字符。字符串中的空格如“Jo e”和空格字符本身将分别编码为 Jo%20e 和 %20。JSON 对象
{ "firstname":"joe"
"othername":""
"lastname":"bloggs"
}
Run Code Online (Sandbox Code Playgroud)
然而,将导致无效的 url http://server.com/setname/joe//bloggs因为 othername 参数是一个空字符串并且由我的方法保留。
我可以检查即将返回的字符串是否为空并返回一个空格字符。但我想知道是否对这种方法没有更好的修改,或者是否有一种更强大的全新方法?
public static String urlEncode(String s) {
ByteArrayOutputStream bOut = null;
DataOutputStream dOut = null;
ByteArrayInputStream bIn = null;
StringBuffer ret = new StringBuffer();
try {
bOut=new ByteArrayOutputStream();
dOut = new DataOutputStream(bOut);
//return value
dOut.writeUTF(s);
bIn = new ByteArrayInputStream(bOut.toByteArray());
bIn.read(); …Run Code Online (Sandbox Code Playgroud) 我正在使用j2me编写手机游戏.在这个游戏中,我使用多个Canvas对象.例如,游戏菜单是Canvas对象,实际游戏也是Canvas对象.我注意到,在某些设备上,当我从一个Canvas切换到另一个时,例如从主菜单切换到游戏,屏幕瞬间"闪烁".我正在使用自己的双缓冲Canvas.
反正有没有避免这个?
有谁能告诉我如何在BlackBerry中制作超链接?
我注意到我的很多谷歌搜索都把我带到了这里,所以我想也许我可以借用你的思想:)
作为我的三年级学位论文的一部分,我正在为移动设备(以及登录的网站)开发一次性密码生成器.
使用org.bouncycastle.crypto.digests.MD5Digest库,我将获取一个字节数组(来自字符串用户输入),然后将其散列X次.这也称为菊花链哈希字符串或灯串加密方法.
我的问题是,如果字符串被哈希一次然后它正确地哈希它,但是如果新哈希再次被哈希,结果是不正确的.
见下面的代码:
private String generateHash(String OTP, int loopNum)
{
byte[] secretBytes = OTP.getBytes();
for (int x = 0; x < loopNum; x++)
{
byte[] tempStore = new byte[16];
tempStore = hash(secretBytes);
secretBytes = tempStore;
}
return convertToHex(secretBytes);
}
public byte[] hash(byte[] secretBytes)
{
org.bouncycastle.crypto.digests.MD5Digest digest = new org.bouncycastle.crypto.digests.MD5Digest();
digest.reset();
// Update MD5 digest with user secret in byte format
digest.update(secretBytes, 0, secretBytes.length);
// get length of digest to initialise new md5 byte array
int length = digest.getDigestSize(); …Run Code Online (Sandbox Code Playgroud) 我想把应用程序放在哪里我可以得到所有图像,无论它是在手机还是在外部存储器中.我想在我的应用程序中导入所有图像.怎么可能?我开始知道通过文件连接是可能的.但没有得到确切的想法.
如何将使用lwuit库的J2ME应用程序转换为android apk?
我尝试使用mircoemulator转换,但是当我启动应用程序时,它显示错误并退出.
有人为BlackBerry应用程序实现了推送通知吗?
我为我的黑莓java应用程序(jar文件)创建了lib.但这不起作用.com.myapp.MyManager:错误!:缺少堆栈映射:getInstance at label:31这是什么?如果我将我的lib包复制到我的黑莓应用程序,它运行良好.但我需要lib.
我有一系列的Web服务方法调用,都遵循以下格式.每种方法的唯一区别是httpRequest.methodName().任何人都可以想到我可以封装共同逻辑的方法吗?另请注意,我的环境是J2ME.
public Response webserviceCall(Request request) {
HTTPRequest httpRequest = new HTTPRequest(new ConnectionProperties());
String errorMessage = "";
String errorCode = "";
try {
// the only thing different
httpRequest.methodName();
} catch (SDKException e) {
errorMessage = e.getMessage();
errorCode = e.getErrorCode();
}
Error error = new Error(errorMessage,errorCode);
return new Response(error);
}
Run Code Online (Sandbox Code Playgroud) 因为,我知道Hash表不允许null.如果我想放置密钥对值,如何处理它?黑莓还有其他选择吗?