yegucheng

BlogJava 首页 新随笔 联系 聚合 管理
  9 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

2007年4月2日 #

     摘要: 图片缩放功能的实现(这里只实现了图片缩小功能,放大原理类似)  阅读全文
posted @ 2007-12-15 16:06 yegucheng 阅读(1862) | 评论 (0)编辑 收藏

     摘要: 在weblogic中,不能将 JDBC 存储配置为使用配置为支持全局事务的 JDBC 数据源  阅读全文
posted @ 2007-12-07 21:36 yegucheng 阅读(2276) | 评论 (0)编辑 收藏

     摘要: 很多笔记本的读卡器,在2003下都不能识别,使用上面的驱动可以解决这一问题
  阅读全文
posted @ 2007-11-11 15:28 yegucheng 阅读(470) | 评论 (0)编辑 收藏

     摘要: 使用Collections.emptyList()生成的List不支持add方法  阅读全文
posted @ 2007-10-29 12:28 yegucheng 阅读(2440) | 评论 (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 阅读(2214) | 评论 (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 阅读(728) | 评论 (0)编辑 收藏

     摘要: 在使用TAB型的属性页时,设定Section标题的方法  阅读全文
posted @ 2007-04-02 15:36 yegucheng 阅读(1030) | 评论 (0)编辑 收藏