Search in sources :

Example 21 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project spacesettlers by amymcgovern.

the class ExampleGAClient method initialize.

/**
 * Initialize the population by either reading it from the file or making a new one from scratch
 *
 * @param space
 */
@Override
public void initialize(Toroidal2DPhysics space) {
    XStream xstream = new XStream();
    xstream.alias("ExampleGAPopulation", ExampleGAPopulation.class);
    // try to load the population from the existing saved file.  If that failes, start from scratch
    try {
        population = (ExampleGAPopulation) xstream.fromXML(new File(getKnowledgeFile()));
    } catch (XStreamException e) {
        // if you get an error, handle it other than a null pointer because
        // the error will happen the first time you run
        System.out.println("No existing population found - starting a new one from scratch");
        population = new ExampleGAPopulation(populationSize);
    }
    currentPolicy = population.getFirstMember();
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) File(java.io.File)

Example 22 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.

the class ImageSource method toXml.

/**
 * Serialise to XML.
 *
 * @return An XML representation of this object
 * @see #fromXml(String)
 */
public String toXml() {
    final XStream xs = new XStream(new DomDriver());
    try {
        xs.allowTypesByWildcard(new String[] { "uk.ac.sussex.gdsc.smlm.**" });
        xs.autodetectAnnotations(true);
        return xs.toXML(this);
    } catch (final XStreamException ex) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to serialise to XML", ex);
    }
    return "";
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream)

Example 23 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.

the class PcPalmAnalysis method loadResult.

private static boolean loadResult(List<CorrelationResult> results, XStream xs, String path) {
    try (InputStream fs = Files.newInputStream(Paths.get(path))) {
        CorrelationResult result = (CorrelationResult) xs.fromXML(fs);
        // Replace a result with the same id
        for (int i = 0; i < results.size(); i++) {
            if (results.get(i).id == result.id) {
                results.set(i, result);
                result = null;
                break;
            }
        }
        // Add to the results if we did not replace any
        if (result != null) {
            results.add(result);
        }
        return true;
    } catch (final XStreamException | IOException ex) {
        ImageJUtils.log("Failed to load correlation result from file: %s\n%s", path, ex.getMessage());
    }
    return false;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 24 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project intellij-plugins by StepicOrg.

the class StepikProjectManager method loadState.

@Override
public void loadState(Element state) {
    try {
        logger.info("Start load the StepikProjectManager state");
        int version = StudySerializationUtils.getVersion(state);
        switch(version) {
            case 1:
                state = StudySerializationUtils.convertToSecondVersion(state);
            case 2:
                state = StudySerializationUtils.convertToThirdVersion(state);
            case 3:
                state = StudySerializationUtils.convertToFourthVersion(state);
        }
        String xml = elementToXml(state);
        XStream xs = getXStream();
        xs.fromXML(xml, this);
        this.version = CURRENT_VERSION;
        refreshCourse();
        updateSelection();
        logger.info("The StepikProjectManager state loaded");
    } catch (XStreamException | StudyUnrecognizedFormatException e) {
        logger.warn("Failed deserialization StepikProjectManager \n" + e.getMessage() + "\n" + project);
    }
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) StudyUnrecognizedFormatException(org.stepik.core.serialization.StudyUnrecognizedFormatException) XStream(com.thoughtworks.xstream.XStream)

Aggregations

XStreamException (com.thoughtworks.xstream.XStreamException)24 IOException (java.io.IOException)13 XStream (com.thoughtworks.xstream.XStream)12 FileNotFoundException (java.io.FileNotFoundException)9 FileOutputStream (java.io.FileOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)3 InputStream (java.io.InputStream)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Response (javax.ws.rs.core.Response)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)2 StringReader (java.io.StringReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)2 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)1