2007年12月15日 #
2007年12月7日 #
2007年11月11日 #
閱讀全文
2007年10月29日 #
2007年10月26日 #
筆者的場景是這樣的,筆者使用code smith作為代碼生成工具,并在Eclipse中做插件開發,code smith天生
對GB的支持比較弱,只能生成UTF-8編碼,這在Eclipse開發的過程中不會存在問題,但是在使用Eclipse的導出
功能時,Eclipse底層使用ANT的執行方式,ANT的默認字符集默認使用當前系統的字符集,這時在編譯導出的時候,
會出現字符無法識別的問題,導致導出或者打包失敗。
一種方式可以改變Eclipse工程的默認字符集,以及自動生成的ant配置文件中字符集的配置,這對于單個工程是有
效的,但處理工程間依賴時,被依賴的工程同樣會出現字符集問題,即使被依賴工程設定ant的字符集。
另一種方式,是手工轉換,講UTF-8的字符集轉換為GBK的,微軟的網站提供了一個批量轉換工具,但是在轉換之后,
文檔的最前面還會有可能存在多于字符,并導致ant打包失敗
最后,沒辦法自己寫了一個字符集轉換工具,因為是自己用,所以夠用就行,下面是轉換部分的代碼,實現UTF8到
GBK的轉換,其他轉換可以對代碼稍作修改。
import org.apache.commons.lang.ArrayUtils;
public class EncodeRepairTool {
public static final byte[] bPre = "EFBBBF".getBytes();
private int i = 0;
/**
* @param args
*/
public static void main(String[] args) {
String path = "D:\\eclipse-dev-3.3\\workspace";
File file = new File(path);
EncodeRepairTool scanner = new EncodeRepairTool();
scanner.scanFolder(file);
}
public void scanFolder(File file) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
scanFolder(files[i]);
}
} else if (file.getName().endsWith(".java")) {
removePreCode(file);
}
}
private void removePreCode(File file) {
try {
FileInputStream fis = new FileInputStream(file);
int size = fis.available();
if (size < 24) {
return;
}
i ++ ;
byte[] bs = new byte[size];
fis.read(bs);
byte[] tbs = ArrayUtils.subarray(bs, 0, 3);
byte[] tbs1 = new byte[] { new Integer(0xEF).byteValue(),
new Integer(0xBB).byteValue(),
new Integer(0xBF).byteValue() };
boolean bol = false;
if (tbs[0] == tbs1[0] && tbs[1] == tbs1[1] && tbs[2] == tbs1[2]) {
bol = true;
}
fis.close();
if (!bol) {
System.out.println(" " + i + " : " + file.getName());
tbs = bs;
}
else {
System.out.println("**" + i + " : " + file.getName());
tbs = ArrayUtils.subarray(bs, 3, size);
}
InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(tbs), "UTF-8");
BufferedReader br = new BufferedReader(reader);
StringBuffer buffer = new StringBuffer();
String s = br.readLine();
while (s != null) {
buffer.append(s);
buffer.append("\n");
s = br.readLine();
}
reader.close();
byte[] nbs = buffer.toString().getBytes("GBK");
FileOutputStream fos = new FileOutputStream(file);
fos.write(nbs);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
} catch (IOException e) {
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}
}
進入一個空目錄:
在serv-U下,調用fTPClient.changeWorkingDirectory("")方法沒有任何問題(指向一個空的目錄)
在x-light下,調用方法,會返回501信息
當下載完文件后:
使用 fTPClient.retrieveFileStream(url)方法下載文件,在serv-U下,可以直接下載下一個文件
但是在x-light下,調用 fTPClient.retrieveFileStream(url)方法后,
必須執行 fTPClient.completePendingCommand()方法,關閉當前下載操作,
才能執行下一個下載任務(在net包的API中有相關的規定)。
2007年4月2日 #
2007年3月30日 #
? ? 最近在看一篇介紹maven的文檔的時候,看到一個很不錯的網站:www.ibiblio.org,這兒包含了幾乎你用到的所有的開源項目,而且提供maven方式的下載。
??? 當然,在平時的使用時,不一定必須使用maven來構建,那就直接手工去找吧,可以在google中輸入如下的字符串(site:www.ibiblio.org maven2 xxx),就可以在該網站找到自己要的開源產品的jar和源碼,其中xxx代表開源產品的名字,例如要找log4j,可以輸入:site:www.ibiblio.org maven2 log4j。
2007年3月7日 #
今天看到兩種使用EMF解析.xml為EMF模型的策略:
一種是通過如下代碼:



另外一種方式是使用EMF模型自動生成的Process,該類一般在模型的Util包下面,引用代碼如下:




其實,對于EMF而言,上面兩種解釋方式,歸根到底都需要EMF獲得 業務模型相關的解析器,對于第一種方式,EMF是如何獲取到業務模型的解析器呢?主要是通過擴展的方式,擴展定義在模型的plugin.xml中,代碼片斷如下圖所示:





這樣,解析.xml文件時,EMF從ResourceFactory注冊中,根據相應的type,獲取解析器(DesignResourceFactoryImpl),完成解析。