FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file, false);
final Marshaller marshaller = factory.createMarshaller(configuration);
marshaller.start(new OutputStreamByteOutput(fileOutputStream));
marshaller.writeObject(entity);
marshaller.finish();
fileOutputStream.flush();
fileOutputStream.getFD().sync();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);