References:
http://code.google.com/p/syntaxhighlighter/
http://oneqonea.blogspot.tw/2012/04/how-do-i-add-syntax-highlighting-to-my.html
http://www.vixual.net/blog/archives/198
2013年1月14日 星期一
Decompress (extract) .tgz file in Java
To handle .tgz file, here is a method to handle it in java like handle Zip file.
Use GZIPInputStream to read .tgz file.
Use GZIPInputStream to read .tgz file.
Use TarInputStream to read the the GZIPInputStream.
Therefore we can get TarEntry and handle the .tgz file.
Here is an example that we would like to get file named version in a .tgz file.
package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
public class GZipTest {
public static void main(String[] args) {
byte[] buffer = new byte[1024];
String fileSorce = "/Users/Desktop/testgzip.tgz";
try {
// get the zip file content
TarInputStream zis = new TarInputStream(new GZIPInputStream(
new FileInputStream(new File(fileSorce))));
// get the zipped file list entry
TarEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
if (fileName.contains("version")) {
StringBuffer strBuffer = new StringBuffer();
while (zis.read(buffer) > 0) {
strBuffer.append(new String(buffer));
}
System.out.println(strBuffer.toString());
}
ze = zis.getNextEntry();
}
zis.close();
} catch (IOException e) {
System.out.println(e);
}
}
}
2012年8月21日 星期二
Get Android source code from .apk
To get Android source code from .apk, you need following tools:
- dex2jar - the tool helps we decode .apk to .class files
- JD-gui or JDEclipse - the tool helps we read the .class files. JD-gui can help you save all .class to .java at one time.
- android-apktool - the tool helps we get res and other properties in the .apk.
The steps to get the source code of XXX.apk:
The environment I used is Fedora 16. android-apktool was installed under /usr/local/bin directory.
First, we are going to take the .java files.
1. Use dex2jar to get the .class files.
# sh dex2jar.sh XXX.apk
Then we will get a file named "XXX.apk.dex2jar.jar".
# sh dex2jar.sh XXX.apk
Then we will get a file named "XXX.apk.dex2jar.jar".
2. Open JD-gui and open "XXX.apk.dex2jar.jar" file. (File -> OpenFile -> indicate XXX.apk.dex2jar.jar ).
3. Save all sources (File -> Save all sources -> to where you want to save the sources and make a name). Then you will get a zip file. Here we named it XXX.zip.
Now we have .java files in XXX.zip.
Second, we are going to get other files such as res directory and .xml files in XXX.apk.
1. Use android-apktool to get the files.
# apktool d XXX.apk XXX_dir
apktool will create XXX_dir. Then in XXX_dir, we have the files.
# apktool d XXX.apk XXX_dir
apktool will create XXX_dir. Then in XXX_dir, we have the files.
Finally, we can unzip XXX.zip to XXX_dir/src. And everything is done.
References:
2012年6月1日 星期五
Set up a CloudStack development Environment
I. Set up the development environment
Following are a brief steps of setting up CS development Environment. For the detail steps, check Citrix document 132013.
- Install Java JDK.
- Install Apache TomCat. (Avoid Tomcat 6.0.35, since it has some problem with CloudStack).
- Install Apache ANT.
- Install git.
II. Use Eclipse to develop
Import CS src to Eclipse:
Since CloudStack uses Java, it's easier to use Eclipse to develop our own program. After done the first part, all we need to do is to import the CS source code to Eclipse. Check the importing source to Eclipse part of CloudStack document.
Import Eclipse preference:
CloudStack provides the Eclipse preference, just download the attachment in the article, and import it into Eclipse. File->import->General->Preferences->the download file location.
III. Errors in Eclipse:
After CS src was imported to Eclipse, there are many errors. most of them is because awsapi this project.
awsapi project missed its Libraries. We just need to add the missed jars to it. The missed jars are in project deps/awsapi-lib. Add all jars in awsapi project, then lots of errors can be solved.
For other errors, still checking...
2012年5月30日 星期三
Install Openstack Swift.
References:
- Install on CentOS6: http://wiki.openstack.org/InstallInstructions/Swift/CentOS
- read the second part: Install storage node.
- Getting-started: http://swift.openstack.org/getting_started.html
- Swifts 1.5.1 documentation: http://swift.openstack.org/
More information:
- To install the required python libraries, it's easier to use easy_install to install them.
- To install easy_install, we need to install python-setuptools and python-setuptools-devel. Ref:http://www.question-defense.com/2009/03/16/install-easy_install-via-yum-on-linux-centos-server
- Then you can use easy_install as a command. E.g: # easy_install evenlet
2009年12月23日 星期三
[Eclipse] eclipse 裡如何加變數?
Eclipse 裡要如何加 runtime 的 path 變數呢?
請先run 要跑的程式,當出現no XX in java.lang.path之後
點Eclipse的 Run->Run Configurations
在出現的視窗內,左邊欄位點一下剛才run的檔案名
右邊欄位點選 Enviroment的 tab
新增一個變數 PATH
注意: 變數名一定要是 PATH (大小寫有差!)
value 請填入 XX.dll 的絕對路徑,多個檔案間要加;
按下 apply
run
基本上就可以跑啦~
p.s 可以將要用的.dll 放在一個資料夾下,path下的value可以設成該資料夾的路徑
這樣就不用一個個設啦
請先run 要跑的程式,當出現no XX in java.lang.path之後
點Eclipse的 Run->Run Configurations
在出現的視窗內,左邊欄位點一下剛才run的檔案名
右邊欄位點選 Enviroment的 tab
新增一個變數 PATH
注意: 變數名一定要是 PATH (大小寫有差!)
value 請填入 XX.dll 的絕對路徑,多個檔案間要加;
按下 apply
run
基本上就可以跑啦~
p.s 可以將要用的.dll 放在一個資料夾下,path下的value可以設成該資料夾的路徑
這樣就不用一個個設啦
[Eclipse] 執行出現no WiiuseJ in java.library.path 的錯誤
話說抓了某個大大所編寫的 headTracking code,高興的import進eclipse run
竟然出現下面的錯誤:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no WiiuseJ in java.library.path
試了加入windows user變數 -->失敗
最後是用 在IDE(eclipse) 裡設Run Configurations才解決
以下是步驟:
至於為啥在windows下設變數會有問題,目前只能猜是Eclipse會蓋掉PATH...
如果有大大有別的意見,也歡迎提出~
總之 祝大家跑程式成功
竟然出現下面的錯誤:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no WiiuseJ in java.library.path
試了加入windows user變數 -->失敗
最後是用 在IDE(eclipse) 裡設Run Configurations才解決
以下是步驟:
1. 先 run 出錯誤
2. 看錯誤顯示 xxx not in java.library.path
3. 猜檔名
linux -> libxxx.so
win -> xxx.dll
4. 把 xxx.so or xxxdll 的 path 加至 變數
5. 也可以建一個專用資料夾, 集中在一起, 加至變數(HOW?)
repeat 2~4 until no java.library.path problem至於為啥在windows下設變數會有問題,目前只能猜是Eclipse會蓋掉PATH...
如果有大大有別的意見,也歡迎提出~
總之 祝大家跑程式成功
訂閱:
文章 (Atom)