Mercurial > hg > FederatedLinda
changeset 106:342446d56b47
string bytebuffer interaction
author | one |
---|---|
date | Fri, 28 May 2010 21:49:52 +0900 |
parents | be9b84a77b15 |
children | 3c532f771c56 |
files | src/fdl/test/TestTree.java |
diffstat | 1 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fdl/test/TestTree.java Thu May 27 19:30:20 2010 +0900 +++ b/src/fdl/test/TestTree.java Fri May 28 21:49:52 2010 +0900 @@ -387,22 +387,26 @@ public String getString(ByteBuffer reply) { - char c; - String s = ""; + byte c; + int position = reply.position(); + int len = 0; while(reply.hasRemaining()) { - c = reply.getChar(); + c = reply.get(); + len ++; if (c== 0) break; - s += c; - } - return s; + } + return new String(reply.array(),position,len-1); + } public void putString(ByteBuffer reply,String s) { - for(int i=0; i<s.length(); i++) { - char c= s.charAt(i); - reply.putChar(c); - } - reply.putChar((char) 0); + reply.put(s.getBytes()); +// +// for(int i=0; i<s.length(); i++) { +// char c= s.charAt(i); +// reply.putChar(c); +// } + reply.put((byte)0); } public static void main(String[] arg) throws InterruptedException { @@ -429,13 +433,13 @@ */ private ByteBuffer makeConfig() { ByteBuffer config = ByteBuffer.allocate(4096); - putHostRun(config,"localhost",PORT); - putHostRun(config,"localhost",PORT+1); - putHostRun(config,"localhost",PORT+2); - putHostRun(config,"localhost",PORT+3); - putHostRun(config,"localhost",PORT+4); - putHostRun(config,"localhost",PORT+5); - putHostRun(config,"localhost",PORT+6); + putHostRun(config,"127.0.0.1",PORT); + putHostRun(config,"127.0.0.1",PORT+1); + putHostRun(config,"127.0.0.1",PORT+2); + putHostRun(config,"127.0.0.1",PORT+3); + putHostRun(config,"127.0.0.1",PORT+4); + putHostRun(config,"127.0.0.1",PORT+5); + putHostRun(config,"127.0.0.1",PORT+6); config.putInt(HOST_LIST_END_MARK); putTree(config,NO_HOST,1,2); putTree(config,0,3,4);