private static String extractPemString(JsonObject json, String fieldName, String msgPrefix) throws NetworkConfigurationException {

        String path = null;
        String pemString = null;

        JsonObject jsonField = getJsonValueAsObject(json.get(fieldName));
        if (jsonField != null) {
            path = getJsonValueAsString(jsonField.get("path"));
            pemString = getJsonValueAsString(jsonField.get("pem"));
        }

        if (path != null && pemString != null) {
            throw new NetworkConfigurationException(format("%s should not specify both %s path and pem", msgPrefix, fieldName));
        }

        if (path != null) {
            // Determine full pathname and ensure the file exists
            File pemFile = new File(path);
            String fullPathname = pemFile.getAbsolutePath();
            if (!pemFile.exists()) {
                throw new NetworkConfigurationException(format("%s: %s file %s does not exist", msgPrefix, fieldName, fullPathname));
            }
            try (FileInputStream stream = new FileInputStream(pemFile)) {
                pemString = IOUtils.toString(stream, "UTF-8");
            } catch (IOException ioe) {
                throw new NetworkConfigurationException(format("Failed to read file: %s", fullPathname), ioe);
            }

        }

        return pemString;
    }
private static String extractPemString ( JsonObject json , String fieldName , String msgPrefix ) throws NetworkConfigurationException { String path = null ; String pemString = null ; JsonObject jsonField = getJsonValueAsObject ( json . get ( fieldName ) ) ; if ( jsonField != null ) { path = getJsonValueAsString ( jsonField . get ( "path" ) ) ; pemString = getJsonValueAsString ( jsonField . get ( "pem" ) ) ; } if ( path != null && pemString != null ) { throw new NetworkConfigurationException ( format ( "%s should not specify both %s path and pem" , msgPrefix , fieldName ) ) ; } if ( path != null ) { File pemFile = new File ( path ) ; String fullPathname = pemFile . getAbsolutePath ( ) ; if ( ! pemFile . exists ( ) ) { throw new NetworkConfigurationException ( format ( "%s: %s file %s does not exist" , msgPrefix , fieldName , fullPathname ) ) ; } try ( FileInputStream stream = new FileInputStream ( pemFile ) ) { pemString = IOUtils . toString ( stream , "UTF-8" ) ; } catch ( IOException ioe ) { throw new NetworkConfigurationException ( format ( "Failed to read file: %s" , fullPathname ) , ioe ) ; } } return pemString ; }
Returns the PEM (as a String) from either a path or a pem field