Here you can find the source of loadProperties(InputStream stream)
Parameter | Description |
---|---|
stream | The stream to read from |
Parameter | Description |
---|---|
IOException | propagated from the load method. |
public static Map<String, String> loadProperties(InputStream stream) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2010 Cloudsmith Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w ww. jav a2 s .c o m * Cloudsmith Inc. - initial API and implementation *******************************************************************************/ import java.io.*; import java.util.*; public class Main { /** * Reads a property list using the {@link Properties#load(InputStream)} method. The * properties are stored in a map. * @param stream The stream to read from * @return The resulting map * @throws IOException propagated from the load method. */ public static Map<String, String> loadProperties(InputStream stream) throws IOException { Properties properties = new Properties(); properties.load(stream); return toMap(properties); } /** * Copies all elements from <code>properties</code> into a Map. The returned map might be unmodifiable * @param properties * @return The map containing all elements */ public static Map<String, String> toMap(Properties properties) { if (properties == null || properties.isEmpty()) return emptyMap(); Map<String, String> props = new HashMap<String, String>(properties.size()); putAll(properties, props); return props; } /** * The emptyMap() method was introduced in Java 1.5 so we need this here to be able to * down compile to 1.4. * @param <K> The type of the map keys * @param <V> The type of the map values * @return An empty set */ @SuppressWarnings("unchecked") public static <K, V> Map<K, V> emptyMap() { return Collections.EMPTY_MAP; } /** * Copies all elements from <code>properties</code> into the given <code>result</code>. * @param properties * @param result */ public static void putAll(Properties properties, Map<String, String> result) { for (Enumeration<Object> keys = properties.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); result.put(key, properties.getProperty(key)); } } }