/** * Update the resources file given an input Nodes set * * @param nodeset nodes * @throws UpdateUtils.UpdateException if an error occurs while trying to update the resources * file or generate nodes */ @Override public void updateNodesResourceFile(final INodeSet nodeset, final String nodesResourceFilePath) throws UpdateUtils.UpdateException { final ResourceFormatGenerator generator; File destfile = new File(nodesResourceFilePath); try { generator = resourceFormatGeneratorService.getGeneratorForFileExtension(destfile); } catch (UnsupportedFormatException e) { throw new UpdateUtils.UpdateException( "Unable to determine file format for file: " + nodesResourceFilePath, e); } File resfile = null; try { resfile = File.createTempFile("resource-temp", destfile.getName()); resfile.deleteOnExit(); } catch (IOException e) { throw new UpdateUtils.UpdateException("Unable to create temp file: " + e.getMessage(), e); } // serialize nodes and replace the nodes resource file try { final FileOutputStream stream = new FileOutputStream(resfile); try { generator.generateDocument(nodeset, stream); } finally { stream.close(); } } catch (IOException e) { throw new UpdateUtils.UpdateException( "Unable to generate resources file: " + e.getMessage(), e); } catch (ResourceFormatGeneratorException e) { throw new UpdateUtils.UpdateException( "Unable to generate resources file: " + e.getMessage(), e); } updateNodesResourceFile(resfile, nodesResourceFilePath); if (!resfile.delete()) { logger.warn("failed to remove temp file: " + resfile); } logger.debug("generated resources file: " + resfile.getAbsolutePath()); }