📄 colondelimitedproperties.java
字号:
/**
* Copyright (c) 2003-2005 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.core.internal.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
/**
* A special Properties subclass that reads and writes using ':' instead of '='
* for the key/value separator.
* <p />
* Copyright (c) 2003-2005 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.8 $
* <br>
* $Date: 2007/01/20 22:25:49 $
* <br>
* @author Craig Setera
*/
public class ColonDelimitedProperties extends Properties {
/**
* Creates an empty property list with no default values.
*/
public ColonDelimitedProperties() {
super();
}
/**
* Creates a property list with the specified defaults.
*
* @param defaults the defaults.
*/
public ColonDelimitedProperties(Properties defaults) {
super(defaults);
}
/**
* @see java.util.Properties#load(java.io.InputStream)
*/
public synchronized void load(InputStream inStream) throws IOException {
Reader dataReader = new InputStreamReader(inStream, "UTF-8");
load(dataReader);
}
/**
* Load the colon-delimited properties from the specified
* Reader.
*
* @param reader the reader containing the properties
* @throws IOException if an error occurs loading the properties
*/
public synchronized void load(Reader reader)
throws IOException
{
BufferedReader bufferedReader = new BufferedReader(reader);
try {
String line = null;
while ((line = bufferedReader.readLine()) != null) {
// Find the first colon and break the string up
line = line.trim();
if ((line.length() > 0) && !line.startsWith("#")) {
int colonIndex = line.indexOf(':');
if (colonIndex != -1) {
String name = line.substring(0, colonIndex);
if (colonIndex + 1 < line.length()) {
String value = line.substring(colonIndex + 1).trim();
setProperty(name, value);
}
}
}
}
} finally {
try { bufferedReader.close(); } catch (IOException e) {}
}
}
/**
* @see java.util.Properties#store(java.io.OutputStream, java.lang.String)
*/
public synchronized void store(OutputStream out, String header)
throws IOException
{
OutputStreamWriter osw = new OutputStreamWriter(out, "UTF-8");
PrintWriter writer = new PrintWriter(osw);
// Maintain the JAD file in sorted by keys order
List keys = new ArrayList(keySet());
Collections.sort(keys);
Iterator iter = keys.iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
String value = getProperty(key);
writer.println(key + ": " + value);
}
writer.flush();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -