Here you can find the source of toProperties(final String value)
public static Properties toProperties(final String value)
//package com.java2s; /*/*from w w w . j a v a 2 s . co m*/ * ==================== * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 2008-2009 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of the Common Development * and Distribution License("CDDL") (the "License"). You may not use this file * except in compliance with the License. * * You can obtain a copy of the License at * http://opensource.org/licenses/cddl1.php * See the License for the specific language governing permissions and limitations * under the License. * * When distributing the Covered Code, include this CDDL Header Notice in each file * and include the License file at http://opensource.org/licenses/cddl1.php. * If applicable, add the following below this CDDL Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * ==================== */ import java.io.ByteArrayInputStream; import java.util.Properties; public class Main { /** * Returns a properties object w/ the key/value pairs parsed from the string * passed in. */ public static Properties toProperties(final String value) { final Properties ret = new Properties(); // make sure there's a value present.. if (isNotBlank(value)) { try { // get the bytes.. final byte[] bytes = value.getBytes("ISO-8859-1"); // load into the properties object.. ret.load(new ByteArrayInputStream(bytes)); } catch (RuntimeException ex) { // don't stop the runtime exception throw ex; } catch (Exception ex) { // throw the error.. throw new IllegalStateException(ex); } } return ret; } /** * Checks if a String is not empty (""), not null and not whitespace only. * * <pre> * StringUtil.isBlank(null) = true * StringUtil.isBlank("") = true * StringUtil.isBlank(" ") = true * StringUtil.isBlank("bob") = false * StringUtil.isBlank(" bob ") = false * </pre> * * @param val * the String to check, may be null * * @return {@code true} if the String is not empty and not null and not * whitespace */ public static boolean isNotBlank(final String val) { return !isBlank(val); } /** * Checks if a String is whitespace, empty ("") or null. * * <pre> * StringUtil.isBlank(null) = true * StringUtil.isBlank("") = true * StringUtil.isBlank(" ") = true * StringUtil.isBlank("bob") = false * StringUtil.isBlank(" bob ") = false * </pre> * * @param val * the String to check, may be null * * @return {@code true} if the String is null, empty or whitespace */ public static boolean isBlank(final String val) { return (val == null) ? true : isEmpty(val.trim()); } /** * Determines if a string is empty. Empty is defined as null or empty * string. * * <pre> * StringUtil.isEmpty(null) = true * StringUtil.isEmpty("") = true * StringUtil.isEmpty(" ") = false * StringUtil.isEmpty("bob") = false * StringUtil.isEmpty(" bob ") = false * </pre> * * @param val * string to evaluate as empty. * @return true if the string is empty else false. */ public static boolean isEmpty(final String val) { return (val == null) ? true : "".equals(val) ? true : false; } }