2323import javax .xml .parsers .DocumentBuilder ;
2424import javax .xml .parsers .DocumentBuilderFactory ;
2525import javax .xml .parsers .ParserConfigurationException ;
26- import java .io .File ;
2726import java .io .IOException ;
2827import java .io .InputStream ;
2928import java .net .MalformedURLException ;
@@ -49,24 +48,23 @@ private DDIReader() {
4948 * @param ddiUrlString : Path to the DDI file.
5049 *
5150 * @return The variables found in the DDI.
52- * @throws MetadataParserException
51+ * @throws MetadataParserException when metadata can't be read
5352 */
5453 public static MetadataModel getMetadataFromDDI (String ddiUrlString , InputStream ddiInputStream ) throws MetadataParserException {
5554
5655 try {
5756 // Path of the output 'variables.xml' temp file
58- File variablesFile = File .createTempFile ("variables" , ".xml" );
59- variablesFile .deleteOnExit ();
60- Path variablesTempFilePath = variablesFile .toPath ();
57+ Path variablesFile = Files .createTempFile ("variables" , ".xml" );
58+ variablesFile .toFile ().deleteOnExit ();
6159
62- transformDDI (ddiUrlString , ddiInputStream , variablesTempFilePath );
63- MetadataModel metadataModel = readVariables (variablesTempFilePath );
64- Files .delete (variablesFile . toPath () );
60+ transformDDI (ddiUrlString , ddiInputStream , variablesFile );
61+ MetadataModel metadataModel = readVariables (variablesFile );
62+ Files .delete (variablesFile );
6563 return metadataModel ;
6664 }
6765
6866 catch (MalformedURLException e ) {
69- log .error (String . format ( "Error when converting file path '%s ' to an URL." , ddiUrlString ) , e );
67+ log .error ("Error when converting file path '{} ' to an URL." , ddiUrlString , e );
7068 return null ;
7169 } catch (IOException e ) {
7270 log .error ("Unable to write temp file." , e );
@@ -94,7 +92,7 @@ private static void transformDDI(String ddiUrlString, InputStream ddiInputStream
9492 *
9593 * @param variablesFilePath Path to the transformed xml file.
9694 * @return The variables described in the file.
97- * @throws MetadataParserException
95+ * @throws MetadataParserException when metadata can't be read
9896 * @throws IOException
9997 * @throws SAXException
10098 * @throws ParserConfigurationException
@@ -144,8 +142,7 @@ private static MetadataModel readVariables(Path variablesFilePath)
144142
145143 }
146144 } catch (NullPointerException e ) {
147- log .error (String .format ("Missing field in mandatory information for variable %s" ,
148- ((Element ) groupElements .item (i )).getAttribute ("name" )));
145+ log .error ("Missing field in mandatory information for variable {}" , ((Element ) groupElements .item (i )).getAttribute ("name" ));
149146 }
150147
151148 String finalRootGroupName = rootGroupName ;
0 commit comments