use of com.thoughtworks.xstream.XStreamException in project spacesettlers by amymcgovern.
the class PacifistHeuristicAsteroidCollectorTeamClient method shutDown.
/**
* Demonstrates saving out to the xstream file
* You can save out other ways too. This is a human-readable way to examine
* the knowledge you have learned.
*/
@Override
public void shutDown(Toroidal2DPhysics space) {
XStream xstream = new XStream();
xstream.alias("ExampleKnowledge", ExampleKnowledge.class);
try {
// if you want to compress the file, change FileOuputStream to a GZIPOutputStream
xstream.toXML(myKnowledge, new FileOutputStream(new File(knowledgeFile)));
} catch (XStreamException e) {
// if you get an error, handle it somehow as it means your knowledge didn't save
// the error will happen the first time you run
myKnowledge = new ExampleKnowledge();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
myKnowledge = new ExampleKnowledge();
}
}
use of com.thoughtworks.xstream.XStreamException in project spacesettlers by amymcgovern.
the class ExampleGAClient method shutDown.
@Override
public void shutDown(Toroidal2DPhysics space) {
XStream xstream = new XStream();
xstream.alias("ExampleGAPopulation", ExampleGAPopulation.class);
try {
// if you want to compress the file, change FileOuputStream to a GZIPOutputStream
xstream.toXML(population, new FileOutputStream(new File(getKnowledgeFile())));
} catch (XStreamException e) {
// if you get an error, handle it somehow as it means your knowledge didn't save
System.out.println("Can't save knowledge file in shutdown ");
System.out.println(e.getMessage());
} catch (FileNotFoundException e) {
// file is missing so start from scratch (but tell the user)
System.out.println("Can't save knowledge file in shutdown ");
System.out.println(e.getMessage());
}
}
use of com.thoughtworks.xstream.XStreamException in project camel by apache.
the class XmlRestProcessor method processResponse.
@Override
protected void processResponse(Exchange exchange, InputStream responseEntity, SalesforceException exception, AsyncCallback callback) {
final XStream localXStream = xStream.get();
try {
// do we need to un-marshal a response
if (responseEntity != null) {
final Class<?> responseClass = exchange.getProperty(RESPONSE_CLASS, Class.class);
Object response;
if (responseClass != null) {
// its ok to call this multiple times, as xstream ignores duplicate calls
localXStream.processAnnotations(responseClass);
final String responseAlias = exchange.getProperty(RESPONSE_ALIAS, String.class);
if (responseAlias != null) {
// extremely dirty, need to flush entire cache if its holding on to an old alias!!!
final CachingMapper mapper = (CachingMapper) localXStream.getMapper();
try {
if (mapper.realClass(responseAlias) != responseClass) {
mapper.flushCache();
}
} catch (CannotResolveClassException ignore) {
// recent XStream versions add a ClassNotFoundException to cache
mapper.flushCache();
}
localXStream.alias(responseAlias, responseClass);
}
response = responseClass.newInstance();
localXStream.fromXML(responseEntity, response);
} else {
// return the response as a stream, for getBlobField
response = responseEntity;
}
exchange.getOut().setBody(response);
} else {
exchange.setException(exception);
}
// copy headers and attachments
exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
exchange.getOut().getAttachmentObjects().putAll(exchange.getIn().getAttachmentObjects());
} catch (XStreamException e) {
String msg = "Error parsing XML response: " + e.getMessage();
exchange.setException(new SalesforceException(msg, e));
} catch (Exception e) {
String msg = "Error creating XML response: " + e.getMessage();
exchange.setException(new SalesforceException(msg, e));
} finally {
// cleanup temporary exchange headers
exchange.removeProperty(RESPONSE_CLASS);
exchange.removeProperty(RESPONSE_ALIAS);
// consume response entity
if (responseEntity != null) {
try {
responseEntity.close();
} catch (IOException ignored) {
}
}
// notify callback that exchange is done
callback.done(false);
}
}
use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.
the class SettingsManager method unsafeLoadFitEngineConfiguration.
/**
* Load the configuration within the specified file
*
* @param filename
* @return The configuration (or null)
*/
public static FitEngineConfiguration unsafeLoadFitEngineConfiguration(String filename) {
XStream xs = createXStream();
FitEngineConfiguration config = null;
FileInputStream fs = null;
try {
fs = new FileInputStream(filename);
config = (FitEngineConfiguration) xs.fromXML(fs);
} catch (ClassCastException ex) {
//ex.printStackTrace();
} catch (FileNotFoundException ex) {
//ex.printStackTrace();
} catch (XStreamException ex) {
ex.printStackTrace();
} finally {
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return config;
}
use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.
the class BatchPeakFit method saveRunSettings.
private String saveRunSettings(String prefix, String imageFilename, FitEngineConfiguration fitConfig) {
BatchRun batchRun = new BatchRun(imageFilename, fitConfig);
FileOutputStream fs = null;
try {
String settingsFilename = prefix + ".xml";
fs = new FileOutputStream(settingsFilename);
xs.toXML(batchRun, fs);
return settingsFilename;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (XStreamException e) {
e.printStackTrace();
} finally {
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
Aggregations