Here you can find the source of loadUniversal(InputStream in)
Parameter | Description |
---|---|
in | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static Properties loadUniversal(InputStream in) throws IOException
//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; } }