private MountPoint readExistingData(Filer filer, JAXBContext context) throws IOException, JAXBException {
FileObject file = filer.getResource(StandardLocation.CLASS_OUTPUT, "", XML_FILE_NAME);
InputStream stream = null;
MountPoint mountPoint = null;
try {
stream = new BufferedInputStream(file.openInputStream());
Unmarshaller unmarshaller = context.createUnmarshaller();
LOGGER.info("XML file exists.");
Object unmarshalled = unmarshaller.unmarshal(stream);
if (unmarshalled != null) {
if ((unmarshalled instanceof MountPoint) == false) {
throw new IllegalArgumentException("Unmarshalled Object is not an instance of MountPoint.");
}
mountPoint = (MountPoint) unmarshalled;
}
} catch(FileNotFoundException ex) {
LOGGER.info("XML file does not exists.");
mountPoint = new MountPoint();
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException ex) {
LOGGER.error("Can not close a file.", ex);
}
}
}
if(mountPoint == null) mountPoint = new MountPoint();
return mountPoint;
}