@Test public void testDupJAVASerializable() throws Exception { Test1 test1 = new Test1(); Test2 test2 = new Test2(); Test3 test3 = new Test3(); test2.setTest1(test1); test1.setTest2(test2); test1.setTest3(test3); test3.setTest2(test2); try { String bigcontent = FileUtil.getFileContent( new File( "F:\\workspace\\bbossgroups-3.5\\bboss-core\\test\\org\\frameworkset\\soa\\testxstream.xml"), "UTF-8"); // 预热bboss和xstream test1.setXmlvalue(bigcontent); String xml = ObjectSerializable.toXML(test1); System.out.println("bboss:" + xml.getBytes().length); Test1 test1_ = (Test1) ObjectSerializable.toBean(xml, Test1.class); byte[] cs = oldObjectToByteBuffer(test1); System.out.println("java:" + cs.length); long s = System.currentTimeMillis(); test1_ = (Test1) oldObjectFromByteBuffer(cs, 0, cs.length); long e = System.currentTimeMillis(); System.out.println("java de times:" + (e - s)); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void testXMLTest1Len() { Test1 test1 = new Test1(); Test2 test2 = new Test2(); Test3 test3 = new Test3(); test2.setTest1(test1); test1.setTest2(test2); test1.setTest3(test3); test3.setTest2(test2); try { String bigcontent = FileUtil.getFileContent( new File( "F:\\workspace\\bbossgroups-3.5\\bboss-core\\test\\org\\frameworkset\\soa\\testxstream.xml"), "UTF-8"); // 预热bboss和xstream test1.setXmlvalue(bigcontent); String xml = ObjectSerializable.toXML(test1); System.out.println("bboss:" + xml.getBytes().length); Test1 test1_ = (Test1) ObjectSerializable.toBean(xml, Test1.class); String xmlXstream = xStream.toXML(test1); Test1 p = (Test1) xStream.fromXML(xmlXstream); System.out.println("xmlXstream:" + xmlXstream.getBytes().length); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
private String _getFileContent(String path, String charset, int encodeType) { String content = ""; try { if (encodeType == HTMLNoBREncode) content = StringUtil.HTMLNoBREncode(FileUtil.getFileContent(path, charset)); else if (encodeType == HTMLEncode) content = StringUtil.HTMLEncode(FileUtil.getFileContent(path, charset)); else if (encodeType == HTMLEncodej) content = StringUtil.HTMLEncodej(FileUtil.getFileContent(path, charset)); else content = FileUtil.getFileContent(path, charset); } catch (IOException e) { log.error( "Get File Content Error:path=" + path + ",charset=" + charset + ",convertHtmlTag=" + encodeType, e); } return content; }
@Test public void testHessianSerializable() throws Exception { Test1 test1 = new Test1(); Test2 test2 = new Test2(); Test3 test3 = new Test3(); test2.setTest1(test1); test1.setTest2(test2); test1.setTest3(test3); test3.setTest2(test2); try { String bigcontent = FileUtil.getFileContent( new File( "F:\\workspace\\bbossgroups-3.5\\bboss-core\\test\\org\\frameworkset\\soa\\testxstream.xml"), "UTF-8"); // 预热bboss和xstream test1.setXmlvalue(bigcontent); long s = System.currentTimeMillis(); String xml = ObjectSerializable.toXML(test1); long e = System.currentTimeMillis(); System.out.println("bboss:" + xml.getBytes().length + ",times:" + (e - s)); s = System.currentTimeMillis(); Test1 test1_ = (Test1) ObjectSerializable.toBean(xml, Test1.class); e = System.currentTimeMillis(); System.out.println("bboss de times:" + (e - s)); s = System.currentTimeMillis(); ByteArrayOutputStream os = new ByteArrayOutputStream(); HessianOutput ho = new HessianOutput(os); ho.writeObject(test1); byte[] cs = os.toByteArray(); e = System.currentTimeMillis(); System.out.println("hessian:" + cs.length + ",times:" + (e - s)); s = System.currentTimeMillis(); ByteArrayInputStream is = new ByteArrayInputStream(cs); HessianInput hi = new HessianInput(is); test1_ = (Test1) hi.readObject(); e = System.currentTimeMillis(); System.out.println("hessian de times:" + (e - s)); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** @throws IOException */ @Test public void testBigData() throws IOException { // 这个文件中内容有47565 字节,约47k的数据 String bigcontent = FileUtil.getFileContent( new File( "F:\\workspace\\bbossgroups-3.5\\bboss-core\\test\\org\\frameworkset\\soa\\testxstream.xml"), "UTF-8"); PhoneNumber phone = new PhoneNumber(); phone.setCode(123); phone.setNumber("1234-456"); PhoneNumber fax = new PhoneNumber(); fax.setCode(123); fax.setNumber(bigcontent); Set dataSet = new TreeSet(); dataSet.add("aa"); dataSet.add("bb"); List dataList = new ArrayList(); dataList.add("aa"); dataList.add("bb"); Map dataMap = new HashMap(); dataMap.put("aa", "aavalue"); dataMap.put("bb", "bbvalue"); String[] dataArray = new String[] {"aa", "bb"}; Person joe = new Person(); joe.setFirstname("Joe"); // joe.setLastname("Walnes"); // 用来验证bboss和Xstream是否会按照null值传递,也就是说lastname有默认值"ssss" // 这样我们手动把lastname设置为null,理论上来说反序列化后joe中的lastname应该是null而不是默认值"ssss" joe.setLastname(null); joe.setPhone(phone); joe.setFax(fax); joe.setDataArray(dataArray); joe.setDataList(dataList); joe.setDataMap(dataMap); joe.setDataSet(dataSet); try { // 预热bboss和xstream String xml = ObjectSerializable.toXML(joe); System.out.println(xml); Person person = ObjectSerializable.toBean(xml, Person.class); String xmlXstream = xStream.toXML(joe); Person p = (Person) xStream.fromXML(xmlXstream); System.out.println(xmlXstream); System.out.println(); System.out.println("bboss序列化测试用例开始"); System.out.println(); long start = System.currentTimeMillis(); ObjectSerializable.toXML(joe); long end = System.currentTimeMillis(); System.out.println("执行bboss beantoxml 1次,耗时:" + (end - start) + "毫秒"); convertBeanToXml(10, joe); convertBeanToXml(100, joe); convertBeanToXml(1000, joe); convertBeanToXml(10000, joe); System.out.println(); System.out.println("xstream序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); xStream.toXML(joe); end = System.currentTimeMillis(); System.out.println("执行XStream beantoxml 1次,耗时:" + (end - start) + "毫秒"); convertBeanToXStreamXml(10, joe); convertBeanToXStreamXml(100, joe); convertBeanToXStreamXml(1000, joe); convertBeanToXStreamXml(10000, joe); System.out.println(); System.out.println("bboss反序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); person = ObjectSerializable.toBean(xml, Person.class); end = System.currentTimeMillis(); System.out.println("执行bboss xmltobean 1次,耗时:" + (end - start) + "豪秒"); convertXMLToBean(10, xml); convertXMLToBean(100, xml); convertXMLToBean(1000, xml); convertXMLToBean(10000, xml); System.out.println(); System.out.println("xstream反序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); xStream.fromXML(xmlXstream); end = System.currentTimeMillis(); System.out.println("执行XStream xmltobean 1次,耗时:" + (end - start) + "豪秒"); convertXStreamXMLToBean(10, xmlXstream); convertXStreamXMLToBean(100, xmlXstream); convertXStreamXMLToBean(1000, xmlXstream); convertXStreamXMLToBean(10000, xmlXstream); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void testXMLTest1() { Test1 test1 = new Test1(); Test2 test2 = new Test2(); Test3 test3 = new Test3(); test2.setTest1(test1); test1.setTest2(test2); test1.setTest3(test3); test3.setTest2(test2); try { String bigcontent = FileUtil.getFileContent( new File( "F:\\workspace\\bbossgroups-3.5\\bboss-core\\test\\org\\frameworkset\\soa\\testxstream.xml"), "UTF-8"); // 预热bboss和xstream test1.setXmlvalue(bigcontent); String xml = ObjectSerializable.toXML(test1); Test1 test1_ = (Test1) ObjectSerializable.toBean(xml, Test1.class); String xmlXstream = xStream.toXML(test1); Test1 p = (Test1) xStream.fromXML(xmlXstream); System.out.println(xmlXstream); System.out.println(); System.out.println("bboss序列化测试用例开始"); System.out.println(); long start = System.currentTimeMillis(); ObjectSerializable.toXML(test1); long end = System.currentTimeMillis(); System.out.println("执行bboss beantoxml 1次,耗时:" + (end - start) + "毫秒"); convertBeanToXml(10, test1); convertBeanToXml(100, test1); convertBeanToXml(1000, test1); convertBeanToXml(10000, test1); System.out.println(); System.out.println("xstream序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); xStream.toXML(test1); end = System.currentTimeMillis(); System.out.println("执行XStream beantoxml 1次,耗时:" + (end - start) + "毫秒"); convertBeanToXStreamXml(10, test1); convertBeanToXStreamXml(100, test1); convertBeanToXStreamXml(1000, test1); convertBeanToXStreamXml(10000, test1); System.out.println(); System.out.println("bboss反序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); test1 = ObjectSerializable.toBean(xml, Test1.class); end = System.currentTimeMillis(); System.out.println("执行bboss xmltobean 1次,耗时:" + (end - start) + "豪秒"); convertXMLToBean(10, xml); convertXMLToBean(100, xml); convertXMLToBean(1000, xml); convertXMLToBean(10000, xml); System.out.println(); System.out.println("xstream反序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); xStream.fromXML(xmlXstream); end = System.currentTimeMillis(); System.out.println("执行XStream xmltobean 1次,耗时:" + (end - start) + "豪秒"); convertXStreamXMLToBean(10, xmlXstream); convertXStreamXMLToBean(100, xmlXstream); convertXStreamXMLToBean(1000, xmlXstream); convertXStreamXMLToBean(10000, xmlXstream); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }