From 3fadb8ad4172b321df296b6e417694a6fb459fd0 Mon Sep 17 00:00:00 2001 From: yuqing Date: Mon, 17 Apr 2017 10:41:25 +0800 Subject: [PATCH] change charactor encoding to UTF-8 --- src/README | 6 +- src/build.xml | 4 +- src/fdfs_client.conf | 6 +- src/org/csource/common/Base64.java | 2 +- src/org/csource/common/IniFileReader.java | 139 ++++++++-------------- src/org/csource/fastdfs/test/Test1.java | 109 +++++++++-------- 6 files changed, 120 insertions(+), 146 deletions(-) diff --git a/src/README b/src/README index 2ca67fc..fa8c6a3 100644 --- a/src/README +++ b/src/README @@ -14,14 +14,14 @@ run the FastDFS Java Client test: java -cp org.csource.fastdfs.test.TestClient eg.: -java -cp fastdfs_client_v1.22.jar org.csource.fastdfs.test.TestClient fdfs_client.conf c:\windows\system32\notepad.exe +java -cp fastdfs_client_v1.25.jar org.csource.fastdfs.test.TestClient fdfs_client.conf c:\windows\system32\notepad.exe or: -java -cp fastdfs_client_v1.22.jar org.csource.fastdfs.test.TestClient fdfs_client.conf /usr/include/stdlib.h +java -cp fastdfs_client_v1.25.jar org.csource.fastdfs.test.TestClient fdfs_client.conf /usr/include/stdlib.h run the FastDFS monitor: java -cp org.csource.fastdfs.test.Monitor eg.: -java -cp fastdfs_client_v1.22.jar org.csource.fastdfs.test.Monitor fdfs_client.conf +java -cp fastdfs_client_v1.25.jar org.csource.fastdfs.test.Monitor fdfs_client.conf diff --git a/src/build.xml b/src/build.xml index 23e2fb2..44693f1 100644 --- a/src/build.xml +++ b/src/build.xml @@ -26,7 +26,7 @@ destdir="${fastdfs_client.bin_dir}" includes="org/**/*.java" debug="on" - encoding="ISO8859-1" + encoding="UTF-8" failonerror="true"/> @@ -52,4 +52,4 @@ - \ No newline at end of file + diff --git a/src/fdfs_client.conf b/src/fdfs_client.conf index 84b6b50..df531db 100644 --- a/src/fdfs_client.conf +++ b/src/fdfs_client.conf @@ -1,9 +1,9 @@ connect_timeout = 2 network_timeout = 30 -charset = ISO8859-1 +charset = UTF-8 http.tracker_http_port = 8080 http.anti_steal_token = no http.secret_key = FastDFS1234567890 -tracker_server = 192.168.0.116:22122 -tracker_server = 192.168.0.119:22122 +tracker_server = 10.0.11.243:22122 +tracker_server = 10.0.11.244:22122 diff --git a/src/org/csource/common/Base64.java b/src/org/csource/common/Base64.java index 937481b..f044b0f 100644 --- a/src/org/csource/common/Base64.java +++ b/src/org/csource/common/Base64.java @@ -461,7 +461,7 @@ public class Base64 try { Base64 b64 = new Base64(); - String str = "agfrtu喀et什1234假大erty空234发喀2344什的"; + String str = "agfrtu驴娄et脢虏1234录脵麓贸erty驴脮234路垄驴娄2344脢虏碌脛"; String str64 = ""; //encode diff --git a/src/org/csource/common/IniFileReader.java b/src/org/csource/common/IniFileReader.java index 3515802..c86f6bf 100644 --- a/src/org/csource/common/IniFileReader.java +++ b/src/org/csource/common/IniFileReader.java @@ -127,91 +127,56 @@ public class IniFileReader } private void loadFromFile(String conf_filename) throws FileNotFoundException, IOException - { - //淇敼浜 瀛熼箯椋烇紝闂璇存槑 浣跨敤涓彂鐜板師鏉ュ鎴风鎵搄ar鍖呭悗锛屽湪鍙︿竴涓」鐩腑寮曠敤锛屽彟涓涓」鐩墦jar鍖呭悗杩愯鏃舵壘涓嶅埌瀹㈡埛绔厤缃枃浠 锛岃兘涓嶈兘鎶婃垜鍚嶅瓧鍔犱笂锛屼互鍚庡ソ鎵惧伐浣 - // FileReader fReader; - // BufferedReader buffReader; - // String line; - // String[] parts; - String name; - String value; - Object obj; - ArrayList valueList; - InputStream is=null; -// fReader = new FileReader(conf_filename); -// buffReader = new BufferedReader(fReader); - this.paramTable = new Hashtable(); - - try - { -// while ((line=buffReader.readLine()) != null) -// { -// line = line.trim(); -// if (line.length() == 0 || line.charAt(0) == '#') -// { -// continue; -// } -// -// parts = line.split("=", 2); -// if (parts.length != 2) -// { -// continue; -// } - is = Thread.currentThread().getContextClassLoader().getResourceAsStream(conf_filename); -// System.out.println(conf_filename+"========================================"); - Properties props = new Properties(); - props.load(is); - Iterator> it = props.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = it.next(); - name= entry.getKey().toString(); - value = entry.getValue().toString(); -// System.out.println(name+"======================================"); - obj = this.paramTable.get(name); - if (obj == null) - { - this.paramTable.put(name, value); - } - else if (obj instanceof String) - { - valueList = new ArrayList(); - valueList.add(obj); - valueList.add(value); - this.paramTable.put(name, valueList); - } - else - { - valueList = (ArrayList)obj; - valueList.add(value); - } - } -// name = parts[0].trim(); -// value = parts[1].trim(); - -// obj = this.paramTable.get(name); -// if (obj == null) -// { -// this.paramTable.put(name, value); -// } -// else if (obj instanceof String) -// { -// valueList = new ArrayList(); -// valueList.add(obj); -// valueList.add(value); -// this.paramTable.put(name, valueList); -// } -// else -// { -// valueList = (ArrayList)obj; -// valueList.add(value); -// } -// } - } - finally - { - if (is!=null) - is.close(); -// fReader.close(); - } - } + { + //淇敼浜 瀛熼箯椋烇紝闂璇存槑 浣跨敤涓彂鐜板師鏉ュ鎴风鎵搄ar鍖呭悗锛屽湪鍙︿竴涓」鐩腑寮曠敤锛屽彟涓涓」鐩墦jar鍖呭悗杩愯鏃舵壘涓嶅埌瀹㈡埛绔厤缃枃浠 锛岃兘涓嶈兘鎶婃垜鍚嶅瓧鍔犱笂锛屼互鍚庡ソ鎵惧伐浣 + String name; + String value; + Object obj; + ArrayList valueList; + InputStream is=null; + this.paramTable = new Hashtable(); + + try + { + Properties props; + try { + is = Thread.currentThread().getContextClassLoader().getResourceAsStream(conf_filename); + props = new Properties(); + props.load(is); + } catch (Exception ex) { + is = new FileInputStream(conf_filename); + props = new Properties(); + props.load(is); + } + Iterator> it = props.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + name= entry.getKey().toString(); + value = entry.getValue().toString(); + obj = this.paramTable.get(name); + if (obj == null) + { + this.paramTable.put(name, value); + } + else if (obj instanceof String) + { + valueList = new ArrayList(); + valueList.add(obj); + valueList.add(value); + this.paramTable.put(name, valueList); + } + else + { + valueList = (ArrayList)obj; + valueList.add(value); + } + } + } + finally + { + if (is != null) { + is.close(); + } + } + } } diff --git a/src/org/csource/fastdfs/test/Test1.java b/src/org/csource/fastdfs/test/Test1.java index 42a80a4..53a8673 100644 --- a/src/org/csource/fastdfs/test/Test1.java +++ b/src/org/csource/fastdfs/test/Test1.java @@ -1,50 +1,59 @@ - -package org.csource.fastdfs.test; - -import java.io.*; -import java.net.*; -import java.util.*; -import org.csource.common.*; -import org.csource.fastdfs.*; - -public class Test1 -{ - public static void main(String args[]) - { - try - { - ClientGlobal.init("fdfs_client.conf"); - System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms"); - System.out.println("charset=" + ClientGlobal.g_charset); - - TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("192.168.0.196", 22122)}); - TrackerClient tc = new TrackerClient(tg); - - TrackerServer ts = tc.getConnection(); - if (ts == null) - { - System.out.println("getConnection return null"); - return; - } - - StorageServer ss = tc.getStoreStorage(ts); - if (ss == null) - { - System.out.println("getStoreStorage return null"); - } - - StorageClient1 sc1 = new StorageClient1(ts, ss); - - NameValuePair[] meta_list = null; //new NameValuePair[0]; - String item = "c:/windows/system32/notepad.exe"; - String fileid = sc1.upload_file1(item, "exe", meta_list); //此行异常 - - System.out.println("Upload local file "+item+" ok, fileid="+fileid); - } - catch(Exception ex) - { - ex.printStackTrace(); - } - - } -} + +package org.csource.fastdfs.test; + +import java.io.*; +import java.net.*; +import java.util.*; +import org.csource.common.*; +import org.csource.fastdfs.*; + +public class Test1 +{ + public static void main(String args[]) + { + try + { + ClientGlobal.init("fdfs_client.conf"); + System.out.println("network_timeout=" + ClientGlobal.g_network_timeout + "ms"); + System.out.println("charset=" + ClientGlobal.g_charset); + + TrackerGroup tg = new TrackerGroup(new InetSocketAddress[]{new InetSocketAddress("10.0.11.243", 22122)}); + TrackerClient tc = new TrackerClient(tg); + + TrackerServer ts = tc.getConnection(); + if (ts == null) + { + System.out.println("getConnection return null"); + return; + } + + StorageServer ss = tc.getStoreStorage(ts); + if (ss == null) + { + System.out.println("getStoreStorage return null"); + } + + StorageClient1 sc1 = new StorageClient1(ts, ss); + + NameValuePair[] meta_list = null; //new NameValuePair[0]; + String item; + String fileid; + if (System.getProperty("os.name").equalsIgnoreCase("windows")) + { + item = "c:/windows/system32/notepad.exe"; + fileid = sc1.upload_file1(item, "exe", meta_list); + } + else + { + item = "/etc/hosts"; + fileid = sc1.upload_file1(item, "", meta_list); + } + + System.out.println("Upload local file "+item+" ok, fileid="+fileid); + } + catch(Exception ex) + { + ex.printStackTrace(); + } + } +}