Java Properties Create toMap(byte[] source)

Here you can find the source of toMap(byte[] source)

Description

to Map

License

Apache License

Declaration

public static Map<String, String> toMap(byte[] source) throws IOException 

Method Source Code

//package com.java2s;
/**//from  w  w w  . ja v  a2s  .  c o m
 * Copyright (C) FuseSource, Inc.
 * http://fusesource.com
 *
 * 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.
 */

import java.io.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class Main {
    public static Map<String, String> toMap(Properties source) {
        Map<String, String> rc = new HashMap<String, String>();
        for (Map.Entry<Object, Object> entry : source.entrySet()) {
            rc.put((String) entry.getKey(), (String) entry.getValue());
        }
        return rc;
    }

    public static Map<String, String> toMap(byte[] source) throws IOException {
        return toMap(toProperties(source));
    }

    public static Properties toProperties(byte[] source) throws IOException {
        Properties rc = new Properties();
        rc.load(new ByteArrayInputStream(source));
        return rc;
    }

    public static Properties toProperties(Map<String, String> source) {
        Properties rc = new Properties();
        for (Map.Entry<String, String> entry : source.entrySet()) {
            rc.put(entry.getKey(), entry.getValue());
        }
        return rc;
    }

    public static Properties toProperties(String source) throws IOException {
        Properties rc = new Properties();
        rc.load(new StringReader(source));
        return rc;
    }
}

Related

  1. splitArrayElementsIntoProperties(String[] array, String delimiter)
  2. splitArrayElementsIntoProperties(String[] array, String delimiter)
  3. toDictionary(Map properties)
  4. toFileContent(Properties props)
  5. toPrettyPrintJSON(Object object)
  6. toProperties(byte[] source)
  7. toProperties(byte[] source)
  8. toProperties(File properties, File xml, String comment)