io.fabric8.utils.DataStoreUtils Maven / Gradle / Ivy
/**
* Copyright 2005-2016 Red Hat, Inc.
*
* Red Hat licenses this file to you 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.
*/
package io.fabric8.utils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class DataStoreUtils {
public static byte[] toBytes(Properties source) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
source.store(baos, null);
} catch (IOException ex) {
throw new IllegalArgumentException("Cannot store properties", ex);
}
return baos.toByteArray();
}
public static byte[] toBytes(Map source) {
return toBytes(toProperties(source));
}
public static Properties toProperties(byte[] source) {
Properties rc = new Properties();
if (source != null) {
try {
rc.load(new ByteArrayInputStream(source));
} catch (IOException ex) {
throw new IllegalArgumentException("Cannot load properties", ex);
}
}
return rc;
}
public static Map toMap(Properties source) {
Map rc = new HashMap();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy