Java Properties Parse parseProperties(final String string)

Here you can find the source of parseProperties(final String string)

Description

parse Properties

License

Apache License

Declaration

public static Properties parseProperties(final String string) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static Properties parseProperties(final String string) {
        final Properties properties = new Properties();
        final int len = string.length();
        String key = null;/*from   www.  j a v a2 s  . com*/
        int index = 0;
        while (true) {
            final int newIndex = string.indexOf('=', index);
            if (newIndex < 0) {
                if (key != null && len > index) {
                    properties.setProperty(key, string.substring(index, len).trim());
                }
                break;
            }
            int end = newIndex - 1;
            while (end >= 0 && Character.isWhitespace(string.charAt(end))) {
                --end;
            }
            if (end > 0) {
                int start = end;
                while (start > 0 && !Character.isWhitespace(string.charAt(start - 1))) {
                    --start;
                }
                if (key != null && start > index) {
                    properties.setProperty(key, string.substring(index, start).trim());
                }
                key = string.substring(start, end + 1);
            }
            index = newIndex + 1;
        }
        return properties;
    }
}

Related

  1. parseBooleanProperty(Properties props, String keyword, boolean defaultValue)
  2. parseHtmlProperties(String s)
  3. parsePropertiesString(String s)
  4. parseProps(Properties p)