private Map < MetaKey , String > readProperties ( final InputStream stream ) throws IOException { try { // wrap the input stream since we don't want the XML parser to close the stream while parsing final Document doc = this . xmlToolsFactory . newDocumentBuilder ( ) . parse ( new FilterInputStream ( stream ) { @ Override public void close ( ) { // do nothing } } ) ; final Element root = doc . getDocumentElement ( ) ; if ( ! "properties" . equals ( root . getNodeName ( ) ) ) { throw new IllegalStateException ( String . format ( "Root element must be of type '%s'" , "properties" ) ) ; } final Map < MetaKey , String > result = new HashMap <> ( ) ; for ( final Element ele : XmlHelper . iterElement ( root , "property" ) ) { final String namespace = ele . getAttribute ( "namespace" ) ; final String key = ele . getAttribute ( "key" ) ; final String value = ele . getTextContent ( ) ; if ( namespace . isEmpty ( ) || key . isEmpty ( ) ) { continue ; } result . put ( new MetaKey ( namespace , key ) , value ) ; } return result ; } catch ( final Exception e ) { throw new IOException ( "Failed to read properties" , e ) ; } }
Read in a map of properties