yegucheng

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            9 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

          2007年10月26日 #

               摘要: 圖片縮放功能的實現(這里只實現了圖片縮小功能,放大原理類似)  閱讀全文
          posted @ 2007-12-15 16:06 yegucheng 閱讀(1879) | 評論 (0)編輯 收藏

               摘要: 在weblogic中,不能將 JDBC 存儲配置為使用配置為支持全局事務的 JDBC 數據源  閱讀全文
          posted @ 2007-12-07 21:36 yegucheng 閱讀(2294) | 評論 (0)編輯 收藏

               摘要: 很多筆記本的讀卡器,在2003下都不能識別,使用上面的驅動可以解決這一問題
            閱讀全文
          posted @ 2007-11-11 15:28 yegucheng 閱讀(488) | 評論 (0)編輯 收藏

               摘要: 使用Collections.emptyList()生成的List不支持add方法  閱讀全文
          posted @ 2007-10-29 12:28 yegucheng 閱讀(2461) | 評論 (1)編輯 收藏

          筆者的場景是這樣的,筆者使用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();
            }

           }

          }

          posted @ 2007-10-26 10:01 yegucheng 閱讀(2238) | 評論 (5)編輯 收藏

          在使用apache的net包處理Serv-U和x-lighgt時遇到的幾點不同
          進入一個空目錄:
           在serv-U下,調用fTPClient.changeWorkingDirectory("")方法沒有任何問題(指向一個空的目錄)
           在x-light下,調用方法,會返回501信息
          當下載完文件后:
           使用 fTPClient.retrieveFileStream(url)方法下載文件,在serv-U下,可以直接下載下一個文件
           但是在x-light下,調用 fTPClient.retrieveFileStream(url)方法后,
           必須執行 fTPClient.completePendingCommand()方法,關閉當前下載操作,
           才能執行下一個下載任務(在net包的API中有相關的規定)。
           
          posted @ 2007-10-26 09:08 yegucheng 閱讀(742) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 南平市| 兴化市| 马龙县| 拜泉县| 黑龙江省| 陆川县| 丰宁| 扶沟县| 云阳县| 买车| 迁西县| 井陉县| 新疆| 靖江市| 温州市| 泰州市| 宜兰市| 红原县| 逊克县| 无极县| 广东省| 呼和浩特市| 利辛县| 阿勒泰市| 纳雍县| 扎鲁特旗| 夹江县| 德惠市| 鹤山市| 栾城县| 文水县| 湘阴县| 宜川县| 龙胜| 抚松县| 建平县| 同江市| 大城县| 孝义市| 白水县| 信阳市|