XStreamを使用して、ユーザーのオブジェクトをファイルに保存しています。StreamException:無効なXML文字(Unicode:0x1a)
private void store() {
XStream xStream = new XStream(new DomDriver("UTF-8"));
xStream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
xStream.alias("configuration", Configuration.class);
xStream.alias("user", User.class);
synchronized (ConfigurationDAOImpl.class) {
try {
xStream.toXML(configuration, new FileOutputStream(filename.getFile()));
} catch (IOException e) {
throw new RuntimeException("Failed to write to " + filename, e);
}
}
}
私は次のコードでそれを読みしようとしている私は例外を取得:com.thoughtworks.xstream.io.StreamException:無効なXML文字(ユニコード:0x1a)がの要素の内容で発見されましたドキュメント。
private void lazyLoad() {
synchronized (ConfigurationDAOImpl.class) {
// Has the configuration been loaded
if (configuration == null) {
if (filename.exists()) {
try {
XStream xStream = new XStream(new DomDriver("UTF-8"));
xStream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);
xStream.alias("configuration", Configuration.class);
xStream.alias("user", User.class);
configuration = (Configuration) xStream
.fromXML(filename.getInputStream());
LOGGER.debug("Loaded configuration from {}.", filename);
} catch (Exception e) {
LOGGER.error("Failed to load configuration.", e);
}
} else {
LOGGER.debug("{} does not exist.", filename);
LOGGER.debug("Creating blank configuration.");
configuration = new Configuration();
configuration.setUsers(new ArrayList<User>());
// and store it
store();
}
}
}
}
おそらく関連:http://stackoverflow.com/a/8427929/486504 –