com.thoughtworks.xstream.io.xml.CompactWriter Java Examples

The following examples show how to use com.thoughtworks.xstream.io.xml.CompactWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public void marshalWriter(Object graph, Writer writer, @Nullable DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(writer), dataHolder);
	}
	else {
		doMarshal(graph, new CompactWriter(writer), dataHolder);
	}
}
 
Example #2
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
public void marshalWriter(Object graph, Writer writer, @Nullable DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(writer), dataHolder);
	}
	else {
		doMarshal(graph, new CompactWriter(writer), dataHolder);
	}
}
 
Example #3
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public void marshalWriter(Object graph, Writer writer, DataHolder dataHolder)
		throws XmlMappingException, IOException {

	if (this.streamDriver != null) {
		doMarshal(graph, this.streamDriver.createWriter(writer), dataHolder);
	}
	else {
		doMarshal(graph, new CompactWriter(writer), dataHolder);
	}
}
 
Example #4
Source File: TransportFormat.java    From javamelody with Apache License 2.0 5 votes vote down vote up
static void writeToXml(Serializable serializable, BufferedOutputStream bufferedOutput)
		throws IOException {
	final XStream xstream = createXStream(false);
	// on wrappe avec un CompactWriter pour gagner 25% en taille de flux (retours chariots)
	// et donc un peu en performances
	final CompactWriter writer = new CompactWriter(
			new OutputStreamWriter(bufferedOutput, XML_CHARSET_NAME));
	try {
		xstream.marshal(serializable, writer);
	} finally {
		writer.close();
	}
}
 
Example #5
Source File: XStreamXmlProvider.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public void writeTo(Object o, Class<?> aClass, Type type, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> map, OutputStream stream)
        throws IOException, WebApplicationException {
    String encoding = getCharsetAsString(mediaType);
    XStream xStream = getXStream(o.getClass());
    xStream.marshal(o, new CompactWriter(new OutputStreamWriter(stream, encoding)));
}
 
Example #6
Source File: XStreamXMLSerialization.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
protected HierarchicalStreamWriter getWriter() {
	try {
		PrintWriter writer = response.getWriter();
		return indented ? new PrettyPrintWriter(writer) : new CompactWriter(writer);
	} catch (IOException e) {
		throw new ResultException("Unable to serialize data", e);
	}
}
 
Example #7
Source File: PendingResultHandler.java    From Cheddar with Apache License 2.0 4 votes vote down vote up
private String toCompactXml(final Object object) {
    final StringWriter stringWriter = new StringWriter();
    xStream.marshal(object, new CompactWriter(stringWriter));
    return stringWriter.toString();
}
 
Example #8
Source File: XStreamCloning.java    From pitest with Apache License 2.0 4 votes vote down vote up
public static String toXml(final Object o) {
  final Writer writer = new StringWriter();
  XSTREAM_INSTANCE.marshal(o, new CompactWriter(writer));

  return writer.toString();
}
 
Example #9
Source File: XStreamExtensionProvider.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toXML() {
  StringWriter writer = new StringWriter(512);
  provider.xstream.marshal(this, new CompactWriter(writer));
  return writer.toString();
}
 
Example #10
Source File: FileListTest.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
private static String toXML(FileList list) {
  StringWriter writer = new StringWriter(512 * 1024);
  xstream.marshal(list, new CompactWriter(writer));
  return writer.toString();
}
 
Example #11
Source File: HibernateXmlConverter.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param writer
 * @param includeHistory
 * @param session
 * @throws DataAccessException
 * @throws HibernateException
 */
private void writeObjects(final Writer writer, final boolean includeHistory, final Session session, final boolean preserveIds)
    throws DataAccessException, HibernateException
    {
  // Container für die Objekte
  final List<Object> all = new ArrayList<Object>();
  final XStream stream = initXStream(session, true);
  final XStream defaultXStream = initXStream(session, false);

  session.flush();
  // Alles laden
  final List<Class< ? >> entities = new ArrayList<Class< ? >>();
  entities.addAll(HibernateEntities.instance().getOrderedEntities());
  entities.addAll(HibernateEntities.instance().getOrderedHistoryEntities());
  for (final Class< ? > entityClass : entities) {
    final String entitySimpleName = entityClass.getSimpleName();
    final String entityType = entityClass.getName();
    if (includeHistory == false && entityType.startsWith("de.micromata.hibernate.history.") == true) {
      // Skip history entries.
      continue;
    }
    List< ? > list = session.createQuery("select o from " + entityType + " o").setReadOnly(true).list();
    list = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate());
    final int size = list.size();
    log.info("Writing " + size + " objects");
    for (final Iterator< ? > it = list.iterator(); it.hasNext();) {
      final Object obj = it.next();
      if (log.isDebugEnabled()) {
        log.debug("loaded object " + obj);
      }
      Hibernate.initialize(obj);
      final Class< ? > targetClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
      final ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(targetClass);
      if (classMetadata == null) {
        log.fatal("Can't init " + obj + " of type " + targetClass);
        continue;
      }
      // initalisierung des Objekts...
      defaultXStream.marshal(obj, new CompactWriter(new NullWriter()));

      if (preserveIds == false) {
        // Nun kann die ID gelöscht werden
        classMetadata.setIdentifier(obj, null, EntityMode.POJO);
      }
      if (log.isDebugEnabled()) {
        log.debug("loading evicted object " + obj);
      }
      if (this.ignoreFromTopLevelListing.contains(targetClass) == false) {
        all.add(obj);
      }
    }
  }
  // und schreiben
  try {
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
  } catch (final IOException ex) {
    // ignore, will fail on stream.marshal()
  }
  log.info("Wrote " + all.size() + " objects");
  final MarshallingStrategy marshallingStrategy = new ProxyIdRefMarshallingStrategy();
  stream.setMarshallingStrategy(marshallingStrategy);
  stream.marshal(all, new PrettyPrintWriter(writer));
    }