dingfirst

          On the Road

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            8 隨筆 :: 2 文章 :: 3 評論 :: 0 Trackbacks

          2006年7月18日 #

          勵精圖治
          posted @ 2007-09-11 16:29 dingfirst 閱讀(179) | 評論 (0)編輯 收藏

          現在在干啥啊!
          沒有方向,沒有動力。
          十年之后會是什么樣子呢?
          nnd
          郁悶!
          極其郁悶!!!

          改變,
          要改變啊!!

          posted @ 2007-04-25 17:13 dingfirst 閱讀(221) | 評論 (0)編輯 收藏

          問題:
          ??????直接用URLEncoder.encode(fileName,"UTF-8"),得到的文件名長度會被截斷。

          解決方法是:
          ??????文件名先用“GB2312”編碼,然后用“ISO8859_1”解碼。當然也可以在將文件名保存到數據庫之前用“GB2312”編碼。

          代碼如下:

          ?1conn?=?DBUtil.getConnection();
          ?2????????????ps?=?conn.prepareStatement("SELECT?FILE_NAME,?CONTENT_TYPE,?CONTENT?FROM?PUB_JOB_ATTACHMENTS?WHERE?ATTACHID?=??");
          ?3????????????ps.setString(1,getAttachId());
          ?4????????????rs?=?ps.executeQuery();
          ?5????????????if(rs.next())
          ?6????????????{
          ?7????????????????//java.net.URLEncoder.encode(rs.getString("FILE_NAME"),?"UTF-8")
          ?8????????????????response.setContentType(rs.getString("CONTENT_TYPE"));
          ?9????????????????String?fileName=rs.getString("FILE_NAME");
          10????????????????fileName=URLEncoder.encode(fileName,"GB2312");
          11????????????????fileName=URLDecoder.decode(fileName,?"ISO8859_1");
          12????????????????response.addHeader("Content-Disposition",?"attachment;?filename=\""?+?fileName?+?"\"");
          13????????????????Blob?content?=?rs.getBlob("CONTENT");
          14????????????????InputStream?ins?=?content.getBinaryStream();
          15????????????????byte?buffer[]?=?new?byte[1024];
          16????????????????int?length?=?-1;
          17????????????????outs?=?response.getOutputStream();
          18????????????????while((length?=?ins.read(buffer))?!=?-1)
          19????????????????????outs.write(buffer,?0,?length);
          20????????????????ins.close();
          21????????????????outs.flush();
          22????????????}

          posted @ 2006-11-27 18:59 dingfirst 閱讀(1176) | 評論 (0)編輯 收藏

          先看一下Proxy的兩種用法:

          public ? interface ?Foo? {
          ????
          int ?doSomthing();
          }
          ???一個基本的實現:
          public?class?FooImpl?implements?Foo?{
          ????
          public?FooImpl()?{
          ????}


          ????
          public?int?doSomthing()?{
          ????????System.out.println(
          "FooImpl?doSomthing");
          ????????
          return?10;
          ????}

          ????
          }
          ???調用處理類,這也是aop的一種實現方式,呵呵。
          public?class?MyInvocationHandler?implements?InvocationHandler{
          ????Object?proxyObject;
          ????
          ????
          public?MyInvocationHandler(Object?_proxyObject)?{
          ????????
          this.proxyObject=_proxyObject;
          ????}


          ????
          public?Object?invoke(Object?proxy,?Method?method,?Object[]?args)?throws?Throwable?{
          ????????System.out.println(
          "in?proxy?instance");
          ????????
          return?method.invoke(proxyObject,args);
          ????}

          }
          ???兩種實現方式:
          public?class?ProxyUse?{
          ????
          public?ProxyUse()?{
          ????}


          ????
          public?void?useProxy1()?throws?SecurityException,?NoSuchMethodException,?InvocationTargetException,
          ????????????IllegalArgumentException,?IllegalAccessException,?InstantiationException?
          {
          ????????FooImpl?obj?
          =?new?FooImpl();
          ????????InvocationHandler?handler?
          =?new?MyInvocationHandler(obj);
          ????????Class?proxyClass?
          =?Proxy.getProxyClass(
          ????????????????Foo.
          class.getClassLoader(),?new?Class[]?{Foo.class});
          ????????Foo?f?
          =?(Foo)?proxyClass.
          ????????????????getConstructor(
          new?Class[]?{InvocationHandler.class}).
          ????????????????newInstance(
          new?Object[]?{handler});
          ????????System.out.println(f.doSomthing());
          ????}

          ????
          ????
          public?void?useProxy2()?throws?SecurityException,?NoSuchMethodException,?InvocationTargetException,
          ????????????IllegalArgumentException,?IllegalAccessException,?InstantiationException?
          {
          ????????FooImpl?obj?
          =?new?FooImpl();
          ????????InvocationHandler?handler?
          =?new?MyInvocationHandler(obj);
          ????????Foo?f?
          =?(Foo)?Proxy.newProxyInstance(
          ????????????Foo.
          class.getClassLoader(),
          ????????????
          new?Class[]?{?Foo.class?},
          ????????????handler
          ????????????);
          ????????System.out.println(f.doSomthing());
          ????}

          ????
          ????
          public?static?void?main(String?[]?args){
          ????????ProxyUse?use
          =new?ProxyUse();
          ????????
          try{
          ????????????use.useProxy1();
          ????????????use.useProxy2();
          ????????}
          catch(Exception?ex){
          ????????????ex.printStackTrace();
          ????????}

          ????}


          }

          看一下java api doc

          static?InvocationHandlergetInvocationHandler(Object?proxy)
          ??????????返回指定代理實例的調用處理程序。
          static?Class<?>getProxyClass(ClassLoader?loader, Class<?>...?interfaces)
          ??????????返回代理類的 java.lang.Class 對象,并向其提供類加載器和接口數組。
          static?booleanisProxyClass(Class<?>?cl)
          ??????????當且僅當指定的類通過 getProxyClass 方法或 newProxyInstance 方法動態生成為代理類時,返回 true。
          static?ObjectnewProxyInstance(ClassLoader?loader, Class<?>[]?interfaces, InvocationHandler?h)
          ??????????返回一個指定接口的代理類實例,該接口可以將方法調用指派到指定的調用處理程序。

          沒時間了,先這樣吧。


          ?

          posted @ 2006-07-26 17:48 dingfirst 閱讀(267) | 評論 (0)編輯 收藏

               摘要: 原文名稱:Double-checked locking and the Singleton pattern ???????????????????????????A comprehensive look at this broken programming idiom 1,請首先看一下下面的這個類,只有第一個getInstance()方法是正確的。其中get...  閱讀全文
          posted @ 2006-07-18 19:17 dingfirst 閱讀(333) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 涿鹿县| 建阳市| 新河县| 灯塔市| 印江| 绥芬河市| 泰宁县| 商水县| 邹城市| 达日县| 北川| 仁化县| 龙海市| 葵青区| 格尔木市| 成都市| 芜湖市| 鸡泽县| 广元市| 通渭县| 木兰县| 钟祥市| 华亭县| 农安县| 乐安县| 越西县| 昌都县| 文化| 吉首市| 云林县| 花莲县| 盘山县| 浮梁县| 峡江县| 巫山县| 永丰县| 怀安县| 兴和县| 陇西县| 长沙县| 肥乡县|