| 1 | |
package com.ctrip.framework.apollo.core.utils; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.io.StringWriter; |
| 5 | |
import java.util.Properties; |
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | 0 | public class PropertiesUtil { |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
public static String toString(Properties properties) throws IOException { |
| 18 | 0 | StringWriter writer = new StringWriter(); |
| 19 | 0 | properties.store(writer, null); |
| 20 | 0 | StringBuffer stringBuffer = writer.getBuffer(); |
| 21 | 0 | filterPropertiesComment(stringBuffer); |
| 22 | 0 | return stringBuffer.toString(); |
| 23 | |
} |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
static boolean filterPropertiesComment(StringBuffer stringBuffer) { |
| 31 | |
|
| 32 | 0 | if (stringBuffer.charAt(0) != '#') { |
| 33 | 0 | return false; |
| 34 | |
} |
| 35 | 0 | int commentLineIndex = stringBuffer.indexOf("\n"); |
| 36 | 0 | if (commentLineIndex == -1) { |
| 37 | 0 | return false; |
| 38 | |
} |
| 39 | 0 | stringBuffer.delete(0, commentLineIndex + 1); |
| 40 | 0 | return true; |
| 41 | |
} |
| 42 | |
} |