/** * Loads a {@link Map} from a {@link Reader} assuming strings as keys * and values. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * * @param reader the {@link Reader} containing a {@link Properties}-like * layout of keys and values. * @return the read data as a {@link Map}. */ public static Map<String, String> loadStrictly( Reader reader ) { try { return load( reader ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Loads a {@link Map} from an {@link InputStream} assuming strings as keys * and values. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * * @param stream the {@link InputStream} containing a * {@link Properties}-like layout of keys and values. * @return the read data as a {@link Map}. */ public static Map<String, String> loadStrictly( InputStream stream ) { try { return load( stream ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Loads a {@link Map} from a {@link File} assuming strings as keys * and values. * * @param file the {@link File} containing a {@link Properties}-like * layout of keys and values. * @return the read data as a {@link Map}. * @throws IOException if the file reader throws {@link IOException}. */ public static Map<String, String> load( File file ) throws IOException { FileInputStream stream = null; try { stream = new FileInputStream( file ); return load( stream ); } finally { closeIfNotNull( stream ); } }
@Test void loadSpacedValue() throws Exception { // expecting Map<String,String> expected = new HashMap<>(); expected.put( "key", "value" ); // given InputStream inputStream = new ByteArrayInputStream( " key = value ".getBytes() ); // when Map<String,String> result = MapUtil.load( inputStream ); // then assertEquals( expected, result ); }
@Test void loadNothing() throws Exception { // expecting Map<String,String> expected = new HashMap<>(); expected.put( "key", "" ); // given InputStream inputStream = new ByteArrayInputStream( " key = ".getBytes() ); // when Map<String,String> result = MapUtil.load( inputStream ); // then assertEquals( expected, result ); } }
@Test public void mustPrintRecommendationsAsConfigReadableOutput() throws Exception { StringBuilder output = new StringBuilder(); Path homeDir = Paths.get( "home" ); Path configDir = Paths.get( "home", "config" ); OutsideWorld outsideWorld = new RealOutsideWorld() { @Override public void stdOutLine( String text ) { output.append( text ).append( System.lineSeparator() ); } }; MemoryRecommendationsCommand command = new MemoryRecommendationsCommand( homeDir, configDir, outsideWorld ); String heap = bytesToString( recommendHeapMemory( gibiBytes( 8 ) ) ); String pagecache = bytesToString( recommendPageCacheMemory( gibiBytes( 8 ) ) ); command.execute( new String[]{"--memory=8g"} ); Map<String,String> stringMap = load( new StringReader( output.toString() ) ); assertThat( stringMap.get( initialHeapSize.name() ), is( heap ) ); assertThat( stringMap.get( maxHeapSize.name() ), is( heap ) ); assertThat( stringMap.get( pagecache_memory.name() ), is( pagecache ) ); }
Map<String,String> stringMap = load( new StringReader( memrecString ) ); assertThat( stringMap.get( initialHeapSize.name() ), is( heap ) ); assertThat( stringMap.get( maxHeapSize.name() ), is( heap ) );
/** * Loads a {@link Map} from a {@link Reader} assuming strings as keys * and values. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * * @param reader the {@link Reader} containing a {@link Properties}-like * layout of keys and values. * @return the read data as a {@link Map}. */ public static Map<String, String> loadStrictly( Reader reader ) { try { return load( reader ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
/** * Loads a {@link Map} from an {@link InputStream} assuming strings as keys * and values. Any {@link IOException} is wrapped and thrown as a * {@link RuntimeException} instead. * * @param stream the {@link InputStream} containing a * {@link Properties}-like layout of keys and values. * @return the read data as a {@link Map}. */ public static Map<String, String> loadStrictly( InputStream stream ) { try { return load( stream ); } catch ( IOException e ) { throw new RuntimeException( e ); } }
public static Map<String, String> config(String fileName) { Map<String, String> config = new HashMap<String, String>(); try { if (new File(fileName).exists()) { System.out.println("Using Existing Configuration File"); } else { System.out.println("Writing Configuration File to batch.properties"); FileWriter fw = new FileWriter(fileName); fw.append("use_memory_mapped_buffers=true\n" + "neostore.nodestore.db.mapped_memory=100M\n" + "neostore.relationshipstore.db.mapped_memory=500M\n" + "neostore.propertystore.db.mapped_memory=1G\n" + "neostore.propertystore.db.strings.mapped_memory=200M\n" + "neostore.propertystore.db.arrays.mapped_memory=0M\n" + "neostore.propertystore.db.index.keys.mapped_memory=15M\n" + "neostore.propertystore.db.index.mapped_memory=15M"); fw.close(); } config = MapUtil.load(new File(fileName)); } catch (Exception e) { System.out.println(e.getMessage()); } return config; }
/** * Loads a {@link Map} from a {@link File} assuming strings as keys * and values. * * @param file the {@link File} containing a {@link Properties}-like * layout of keys and values. * @return the read data as a {@link Map}. * @throws IOException if the file reader throws {@link IOException}. */ public static Map<String, String> load( File file ) throws IOException { FileInputStream stream = null; try { stream = new FileInputStream( file ); return load( stream ); } finally { closeIfNotNull( stream ); } }
private Config loadAdditionalConfigFile( Path path ) { try ( InputStream in = Files.newInputStream( path ) ) { return Config.fromSettings( MapUtil.load( in ) ).build(); } catch ( IOException e ) { throw new UncheckedIOException( "Could not read additional configuration from " + path + ". " + "The file either does not exist, is not a regular file, or is not readable.", e ); } } }
private static Config readConfiguration( Args arguments ) throws ToolFailureException { Map<String, String> specifiedConfig = stringMap(); String configFilePath = arguments.get( CONFIG, null ); if ( configFilePath != null ) { File configFile = new File( configFilePath ); try { specifiedConfig = MapUtil.load( configFile ); } catch ( IOException e ) { throw new ToolFailureException( String.format( "Could not read configuration file [%s]", configFilePath ), e ); } } return Config.defaults( specifiedConfig ); }