Java Properties Load from File loadUniversal(InputStream in)

Here you can find the source of loadUniversal(InputStream in)

Description

Determines if the the input stream is xml if it is, use create properties loaded from xml format, otherwise create properties from default format.

License

Open Source License

Parameter

Parameter Description
in a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static Properties loadUniversal(InputStream in)
        throws IOException 

Method Source Code

//package com.java2s;
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
 * (c) 2001 - 2013 OpenPlans//from   w w w . j a v a 2 s .  c  o m
 * This code is licensed under the GPL 2.0 license, available at the root
 * application directory.
 */

import java.io.BufferedInputStream;
import java.io.BufferedReader;

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

import java.util.Properties;

public class Main {
    /**
     * Determines if the the input stream is xml
     * if it is, use create properties loaded from xml
     * format, otherwise create properties from default
     * format.
     * 
     * @param in
     *
     * @throws IOException
     */
    public static Properties loadUniversal(InputStream in)
            throws IOException {
        final String xmlDeclarationStart = "<?xml";
        BufferedInputStream bin = new BufferedInputStream(in);
        bin.mark(4096);

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                bin));
        String line = reader.readLine();
        boolean isXML = line.startsWith(xmlDeclarationStart);

        bin.reset();
        Properties props = new Properties();

        if (isXML)
            props.loadFromXML(bin);
        else
            props.load(bin);

        return props;
    }
}

Related

  1. loadStrictly(File file)
  2. loadSystemProperty(String evn, String fileName)
  3. loadTestProperties(String filename)
  4. loadToStringFromFile(String fullFileName)
  5. loadTrimedProperties(String filename)
  6. loadUserSettings()
  7. loadWithNormalMode(final String propertyFilePath)
  8. loadWithTrimmedValues(InputStream iStr, Properties prop)