private void readPreferences(final BufferedReader reader) throws IOException, InvalidPreferencesFormatException {
		final String kvPid = _application.getConnection().getLocalConfigurationAuthority().getPid();

		final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(byteArrayOutputStream));

		String line;
		boolean replaceNextLine = false;
		boolean replaced = false;
		while(true){
			line = reader.readLine();
			if (line == null)
				break;
			if(replaced){
				writer.write(line + "\n");
			}
			else if(!replaceNextLine && line.matches("\\s*<node name=\"gtm\">")) {
				replaceNextLine = true;
				writer.write(line + "\n");
			}
			else if(replaceNextLine && line.matches("\\s*<node name=\".+\">")) {
				writer.write("<node name=\"" + kvPid + "\">\n");
				replaceNextLine = false;
				replaced = true;
			}
			else{
				writer.write(line + "\n");
			}
		}

		writer.close();
		
		final byte[] buf = byteArrayOutputStream.toByteArray();

		final ByteArrayInputStream inputStream = new ByteArrayInputStream(buf);
		Preferences.importPreferences(inputStream);
	}