Refine search
/** * Returns a list of any plugins that are persisted in the installing list */ @SuppressWarnings("unchecked") public static synchronized @CheckForNull Map<String,String> getPersistedInstallStatus() { File installingPluginsFile = getInstallingPluginsFile(); if(installingPluginsFile == null || !installingPluginsFile.exists()) { return null; } return (Map<String,String>)new XStream().fromXML(installingPluginsFile); }
public static boolean toXML(Object object, File file) { XStream xStream = new XStream(); OutputStream outputStream = null; Writer writer = null; try { outputStream = new FileOutputStream(file); writer = new OutputStreamWriter(outputStream, Charset.forName("UTF-8")); xStream.toXML(object, writer); } catch (Exception exp) { log.error(null, exp); return false; } finally { close(writer); close(outputStream); } return true; }
XStream xstream = new XStream(); xstream.alias("person", Person.class); xstream.alias("persons", PersonList.class); xstream.addImplicitCollection(PersonList.class, "list"); PersonList list = new PersonList(); list.add(new Person("ABC",12,"address")); list.add(new Person("XYZ",20,"address2")); String xml = xstream.toXML(list);
public static <T> T serializeAndDeserializeWithXStream(T input) { XStream xStream = new XStream(); xStream.setMode(XStream.ID_REFERENCES); if (input != null) { xStream.processAnnotations(input.getClass()); } XStream.setupDefaultSecurity(xStream); xStream.addPermission(new AnyTypePermission()); String xmlString = xStream.toXML(input); return (T) xStream.fromXML(xmlString); }
private static XStream createXStream(boolean json) { final XStream xstream; if (json) { // format json xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); } else { // sinon format xml, utilise la dépendance XPP3 par défaut xstream = new XStream(); } for (final Map.Entry<String, Class<?>> entry : XStreamAlias.getMap().entrySet()) { xstream.alias(entry.getKey(), entry.getValue()); } final MapConverter mapConverter = new MapConverter(xstream.getMapper()) { /** {@inheritDoc} */ @SuppressWarnings("rawtypes") @Override public boolean canConvert(Class type) { return true; // Counter.requests est bien une map } }; xstream.registerLocalConverter(Counter.class, "requests", mapConverter); xstream.registerLocalConverter(Counter.class, "rootCurrentContextsByThreadId", mapConverter); return xstream; } }
map.put("island","faranga"); XStream magicApi = new XStream(); magicApi.registerConverter(new MapEntryConverter()); magicApi.alias("root", Map.class); String xml = magicApi.toXML(map); System.out.println("Result of tweaked XStream toXml()"); System.out.println(xml); Map<String, String> extractedMap = (Map<String, String>) magicApi.fromXML(xml); assert extractedMap.get("name").equals("chris"); assert extractedMap.get("island").equals("faranga");
InputStream is = method.getResponseBodyAsStream(); XStream xstream = new XStream(new DomDriver()); xstream.alias("account", RegionAccount.class); xstream.alias("user", RegionUser.class); xstream.aliasField("id", RegionAccount.class, "uuid"); xstream.aliasField("name", RegionAccount.class, "accountName");
private Collection<ProcessRoleConfig> getRoles(InputStream input) { if (input == null) { return null; } XStream xstream = new XStream(); xstream.aliasPackage("config", ProcessRoleConfig.class.getPackage().getName()); xstream.useAttributeFor(String.class); xstream.useAttributeFor(Boolean.class); xstream.useAttributeFor(Integer.class); return (Collection<ProcessRoleConfig>) xstream.fromXML(input); }
protected <S extends Score, W extends TestScoreWrapper<S>> void assertSerializeAndDeserialize(S expectedScore, W input) { XStream xStream = new XStream(); xStream.setMode(XStream.ID_REFERENCES); xStream.processAnnotations(input.getClass()); XStream.setupDefaultSecurity(xStream); xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.config\\..*", "org\\.optaplanner\\.persistence\\.xstream\\..*\\$Test\\w+ScoreWrapper"}); String xmlString = xStream.toXML(input); W output = (W) xStream.fromXML(xmlString); assertEquals(expectedScore, output.getScore()); String regex; if (expectedScore != null) { regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?>" // Start of element + "\\s*<score( id=\"\\d+\")?>" + expectedScore.toString().replaceAll("\\[", "\\\\[").replaceAll("\\]", "\\\\]") // Score + "</score>" + "\\s*</\\1>"; // End of element } else { regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?/>"; // Start and end of element } if (!xmlString.matches(regex)) { fail("Regular expression match failed.\nExpected regular expression: " + regex + "\nActual string: " + xmlString); } }
/** * Reads configuration from given file and delete the file after. * * @param fileName File name. * @return Readed configuration. * @throws IOException If failed. * @see #storeToFile(IgniteConfiguration, boolean) * @throws IgniteCheckedException On error. */ private static IgniteConfiguration readCfgFromFileAndDeleteFile(String fileName) throws IOException, IgniteCheckedException { try(BufferedReader cfgReader = new BufferedReader(new FileReader(fileName))) { IgniteConfiguration cfg = (IgniteConfiguration)new XStream().fromXML(cfgReader); if (cfg.getMarshaller() == null) { Marshaller marsh = IgniteTestResources.getMarshaller(); cfg.setMarshaller(marsh); } X.println("Configured marshaller class: " + cfg.getMarshaller().getClass().getName()); if (cfg.getDiscoverySpi() == null) { TcpDiscoverySpi disco = new TcpDiscoverySpi(); disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER); cfg.setDiscoverySpi(disco); } X.println("Configured discovery: " + cfg.getDiscoverySpi().getClass().getName()); return cfg; } finally { new File(fileName).delete(); } }
/** * Persists a list of installing plugins; this is used in the case Jenkins fails mid-installation and needs to be restarted * @param installingPlugins */ public static synchronized void persistInstallStatus(List<UpdateCenterJob> installingPlugins) { File installingPluginsFile = getInstallingPluginsFile(); if(installingPlugins == null || installingPlugins.isEmpty()) { installingPluginsFile.delete(); return; } LOGGER.fine("Writing install state to: " + installingPluginsFile.getAbsolutePath()); Map<String,String> statuses = new HashMap<String,String>(); for(UpdateCenterJob j : installingPlugins) { if(j instanceof InstallationJob && j.getCorrelationId() != null) { // only include install jobs with a correlation id (directly selected) InstallationJob ij = (InstallationJob)j; InstallationStatus status = ij.status; String statusText = status.getType(); if(status instanceof Installing) { // flag currently installing plugins as pending statusText = "Pending"; } statuses.put(ij.plugin.name, statusText); } } try { String installingPluginXml = new XStream().toXML(statuses); FileUtils.write(installingPluginsFile, installingPluginXml); } catch (IOException e) { LOGGER.log(SEVERE, "Failed to save " + installingPluginsFile.getAbsolutePath(), e); } }
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);) {