UserDataHelpers { static void interceptWritingFiles( Properties props, File outputDirectory ) throws IOException { if( outputDirectory == null ) return; Logger logger = Logger.getLogger( UserDataHelpers.class.getName()); Set<String> keys = props.stringPropertyNames(); for( final String key : keys ) { if( ! key.startsWith( ENCODE_FILE_CONTENT_PREFIX )) continue; String encodedFileContent = props.getProperty( key ); String realKey = key.substring( ENCODE_FILE_CONTENT_PREFIX.length()); if( encodedFileContent == null ) { logger.fine( "No file content was provided for " + realKey + ". Skipping it..." ); continue; } byte[] fileContent = decodeFromBase64( encodedFileContent ); String targetFile = props.getProperty( realKey ); if( targetFile == null ) { logger.fine( "No property named " + realKey + " was found. Skipping it..." ); continue; } Utils.createDirectory( outputDirectory ); File output = new File( outputDirectory, new File( targetFile ).getName()); Utils.copyStream( new ByteArrayInputStream( fileContent ), output ); logger.finer( "Writing " + key + " from user data in " + output.getAbsolutePath()); props.remove( key ); props.setProperty( realKey, output.getAbsolutePath()); } } private  UserDataHelpers(); static String writeUserDataAsString(
			Map<String,String> messagingConfiguration,
			String domain,
			String applicationName,
			String scopedInstancePath ); static Properties writeUserDataAsProperties(
			Map<String,String> messagingConfiguration,
			String domain,
			String applicationName,
			String scopedInstancePath ); static Properties readUserData( String rawProperties, File outputDirectory ); static Properties processUserData( Properties properties, File outputDirectory ); static final String SCOPED_INSTANCE_PATH; static final String APPLICATION_NAME; static final String DOMAIN; static final String ENCODE_FILE_CONTENT_PREFIX; }
@Test public void testInterceptWritingFiles_inexistingOutputDirectory() throws Exception { File outputDirectory = this.folder.newFolder(); Utils.deleteFilesRecursively( outputDirectory ); Assert.assertFalse( outputDirectory.isDirectory()); UserDataHelpers.interceptWritingFiles( new Properties(), outputDirectory ); Assert.assertFalse( outputDirectory.isDirectory()); }
@Test public void testInterceptWritingFiles_inexistingOutputDirectory_withFiles() throws Exception { File outputDirectory = this.folder.newFolder(); Utils.deleteFilesRecursively( outputDirectory ); Assert.assertFalse( outputDirectory.isDirectory()); File file = this.folder.newFile(); Properties props = new Properties(); props.put( "loc", file.getAbsolutePath()); props.put( UserDataHelpers.ENCODE_FILE_CONTENT_PREFIX + "loc", "" ); UserDataHelpers.interceptWritingFiles( props, outputDirectory ); Assert.assertTrue( outputDirectory.isDirectory()); Assert.assertTrue( file.isFile()); }