Java Properties Load from InputStream loadPropertiesFileFromStream(InputStream stream)

Here you can find the source of loadPropertiesFileFromStream(InputStream stream)

Description

Methode de chargement d'un fichier de proprietes a partir d'un stream

License

Apache License

Parameter

Parameter Description
stream Stream a charger

Return

Proprietes chargees

Declaration

public static Properties loadPropertiesFileFromStream(InputStream stream) 

Method Source Code

//package com.java2s;
/*//from   ww  w .  j a v  a 2s  .  c  om
 * #%L
 * Commons Tools
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2013 - 2015 Leadware
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class Main {
    /**
     * Methode de chargement d'un fichier de proprietes a partir d'un stream
     * @param stream Stream a charger   
     * @return Proprietes chargees
     */
    public static Properties loadPropertiesFileFromStream(InputStream stream) {

        // Si le chemin est vide
        if (stream == null)
            throw new RuntimeException("Erreur lors du chargement du fichier de proprietes: Le stream est null");

        // Proprietes
        Properties properties = new Properties();

        try {

            // Chargement du fichier de propriete
            properties.load(new InputStreamReader(stream));

        } catch (IOException e) {

            // Fermeture
            closeStream(stream);

            // On relance
            throw new RuntimeException("Erreur lors du chargement du fichier de proprietes", e);
        }

        // Fermeture
        closeStream(stream);

        // On retourne les proprietes
        return properties;
    }

    /**
     * Methode de fermeture d'un stream
     * @param stream   Stream a fermer
     */
    protected static void closeStream(InputStream stream) {

        // Si le stream est null
        if (stream == null)
            return;

        try {

            // Tentative de fermeture
            stream.close();

        } catch (IOException e) {
        }
    }
}

Related

  1. loadProperties(InputStream inputStream)
  2. loadProperties(InputStream inputStream)
  3. loadProperties(InputStream inputStream, Properties result)
  4. loadProperties(InputStream stream)
  5. loadProperties(Properties props, InputStream inputStream)
  6. loadPropertiesFromStream(InputStream inputStream)
  7. loadPropertiesInputStreamToMap(InputStream propertiesInputStream)
  8. loadPropertiesStream(InputStream input)