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();
}
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 "";
}
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;
}
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);
}
}
Aggregations