Here you can find the source of serialize(Map
public static void serialize(Map<String, Map<String, String>> in, OutputStream out) throws IOException
//package com.java2s; /*//from w ww . jav a2s . c o m * IniUtils.java * * Copyright (C) 2012-2014 LucasEasedUp * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.Map; public class Main { public static void serialize(Map<String, Map<String, String>> in, OutputStream out) throws IOException { try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out))) { for (Map.Entry<String, Map<String, String>> section : in.entrySet()) { bw.write("["); bw.write(section.getKey()); bw.write("]"); bw.newLine(); for (Map.Entry<String, String> kv : section.getValue().entrySet()) { if (kv.getValue() != null) { bw.write(kv.getKey()); bw.write("="); bw.write(kv.getValue()); bw.newLine(); } } bw.newLine(); } } } public static String serialize(Map<String, Map<String, String>> in) throws IOException { OutputStream outputStream = new ByteArrayOutputStream(); serialize(in, outputStream); return outputStream.toString(); } }