Refine search
public HierarchicalStreamReader createReader(Reader in) { return createReader(new InputSource(in)); }
public HierarchicalStreamWriter createWriter(OutputStream out) { try { return createWriter(encoding != null ? new OutputStreamWriter(out, encoding) : new OutputStreamWriter(out)); } catch (UnsupportedEncodingException e) { throw new StreamException(e); } }
private HierarchicalStreamReader createReader(InputSource source) { try { if (documentBuilderFactory == null) { synchronized (this) { if (documentBuilderFactory == null) { documentBuilderFactory = createDocumentBuilderFactory(); } } } final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); if (encoding != null) { source.setEncoding(encoding); } Document document = documentBuilder.parse(source); return new DomReader(document, getNameCoder()); } catch (FactoryConfigurationError e) { throw new StreamException(e); } catch (ParserConfigurationException e) { throw new StreamException(e); } catch (SAXException e) { throw new StreamException(e); } catch (IOException e) { throw new StreamException(e); } }
XStream xStream = new XStream(new DomDriver()); xStream.registerConverter(new MapEntryConverter()); xStream.alias("xml", java.util.Map.class); // from XML, convert back to map Map<String, List<Object>> map = (Map<String, List<Object>>) xStream.fromXML(xmlData); /*System.out.println("MAP: \n" + map.entrySet().toString());*/ String xml = xStream.toXML(map); /*System.out.println("XML: \n"+xml);*/
public static <T> T toBean(String xmlStr,Class<T> cls){ XStream xstream=new XStream(new DomDriver()); xstream.processAnnotations(cls); @SuppressWarnings("unchecked") T obj=(T)xstream.fromXML(xmlStr); return obj; } }
if (client.executeMethod(method) == 200) { InputStream is = method.getResponseBodyAsStream(); XStream xstream = new XStream(new DomDriver()); xstream.alias("useraccount", UserAccountVO.class); xstream.aliasField("id", UserAccountVO.class, "uuid"); try(ObjectInputStream in = xstream.createObjectInputStream(is);) { return (UserAccountVO)in.readObject();
/** * 将执行计划序列化成字符串 */ public static String createStringPlan(PhysicalPlan plan) { XStream xstream = new XStream(new DomDriver(XML_CHARSET)); xstream.autodetectAnnotations(true); PhysicalPlanLoader.setAlias(xstream); xstream.registerConverter(new MapConverter(new DefaultMapper(new ClassLoaderReference(PhysicalPlanWriter.class.getClassLoader())))); return xstream.toXML(plan); }
public void noteConfiguration() { if (isConfigurationChanged()) { ActivityAndBeanWrapper newConfig = new ActivityAndBeanWrapper(); newConfig.setActivity(configuration.getActivity()); newConfig.setBean(clonedConfig); configuration = newConfig; XStream xstream = new XStream(new DomDriver()); xstream.setClassLoader(configuration.getActivity().getClass().getClassLoader()); origConfigXML = xstream.toXML(clonedConfig); } }
@Before public void setUp() { converter = new ConfigurationConverter(); xStream = new XStream(new DomDriver()); xStream.registerConverter(converter); xStream.alias("configuration", DefaultConfiguration.class); }
XStream xs = new XStream(new DomDriver()); xs.alias("root", ParentElement.class); xs.useAttributeFor(ChildElement.class, "aaa"); // read as attribute xs.useAttributeFor(ChildElement.class, "bbb"); ParentElement parent = new ParentElement(); try { FileInputStream fis = new FileInputStream("readfile"); xs.fromXML(fis, parent); } catch (FileNotFoundException ex) { ex.printStackTrace(); }
... XStream xstream = new XStream(new DomDriver()); xstream.alias("myclass", MyClass.class); xstream.aliasField("countTotal", MyClass.class, "totalCountValue"); String xml = xstream.toXML(this); ...
protected static XStream getXStream() { final XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library xstream.registerConverter(new Converter(xstream.getMapper(), xstream.getReflectionProvider())); return xstream; }
private HierarchicalStreamReader createReader(InputSource source) { try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); if (encoding != null) { source.setEncoding(encoding); } Document document = documentBuilder.parse(source); return new DomReader(document, getNameCoder()); } catch (FactoryConfigurationError e) { throw new StreamException(e); } catch (ParserConfigurationException e) { throw new StreamException(e); } catch (SAXException e) { throw new StreamException(e); } catch (IOException e) { throw new StreamException(e); } }