|
From: <rm...@hy...> - 2007-03-26 17:22:03
|
Author: rmorgan Date: 2007-03-26 09:22:00 -0800 (Mon, 26 Mar 2007) New Revision: 3906 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3906 Modified: trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java Log: Use UTF-8 when converting bytes to Strings, use Base64 encoded strings as the transport between the server and agent. Modified: trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java =================================================================== --- trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java 2007-03-26 12:44:51 UTC (rev 3905) +++ trunk/src/org/hyperic/hq/livedata/agent/commands/LiveData_result.java 2007-03-26 17:22:00 UTC (rev 3906) @@ -28,6 +28,7 @@ import org.hyperic.hq.agent.AgentRemoteValue; import org.hyperic.hq.agent.AgentAssertionException; import org.hyperic.hq.agent.AgentRemoteException; +import org.hyperic.util.encoding.Base64; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -86,44 +87,40 @@ throws IOException { Deflater compressor = new Deflater(); - compressor.setInput(s.getBytes()); + compressor.setInput(s.getBytes("UTF-8")); compressor.finish(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - int total = 0; byte[] buf = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buf); - total += count; bos.write(buf, 0, count); } bos.close(); byte[] compressedData = bos.toByteArray(); - return new String(compressedData, 0, total); + return Base64.encode(compressedData); } private String decompress(String s) throws IOException, DataFormatException { Inflater decompressor = new Inflater(); - decompressor.setInput(s.getBytes()); + decompressor.setInput(Base64.decode(s)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - int total = 0; byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); - total += count; bos.write(buf, 0, count); } bos.close(); byte[] decompressedData = bos.toByteArray(); - return new String(decompressedData, 0, total); + return new String(decompressedData, 0, decompressedData.length, "UTF-8"); } } |