|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.nand.util.i18n.PropsFileWriter
public class PropsFileWriter
Write a properties file out to disk, in the same format used by the jsettlers project:
Valid ISO-8859-1 high-bit characters will be in the file as such, and not as \uXXXX code escapes,
unlike Java's built-in Properties.store(java.io.OutputStream, String) method.
Usage:
PropsFileWriter(File) or PropsFileWriter(PrintWriter);
.write(pairs, filecomment);
writeOne(writer, key, value, paircomment, spacedEquals);
PropsFileParser| Field Summary | |
|---|---|
private java.io.PrintWriter |
pw
An open PrintWriter for the output file; must have encoding ISO-8859-1 |
| Constructor Summary | |
|---|---|
PropsFileWriter(java.io.File pFile)
Create and open a new PropsFileWriter to this file. |
|
PropsFileWriter(java.io.PrintWriter pw)
Create a new PropsFileWriter using this open PrintWriter, which must use the "ISO-8859-1" file encoding. |
|
| Method Summary | |
|---|---|
static void |
appendEsc(java.lang.StringBuilder sb,
char c)
Escape and append 1 special character to a StringBuilder. |
void |
close()
|
static java.lang.String |
escValue(java.lang.String val)
Examine a property value string, and escape any non-ISO-8859-1 unicode characters and leading whitespace. |
void |
flush()
|
static boolean |
isValidHighISO8859_1(char c)
For java properties file encoding, is "high-bit" character c valid in both ISO-8859-1 and ISO-8859-15?
If not, it should be escaped (\uXXXX) in the output file. |
void |
write(java.util.List<PropsFileParser.KeyPairLine> pairs,
java.lang.String fileComment)
Write these key-value pairs through the open writer. |
static void |
writeOne(java.io.PrintWriter pw,
java.lang.String key,
java.lang.String val,
java.util.List<java.lang.String> comments,
boolean spacedEquals)
Write one key-value pair line to the properties file, making sure unicode escapes are re-escaped to \uXXXX
where needed, otherwise keeping val unchanged and keeping high-bit ISO-8859-1 characters for easier viewing. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.io.PrintWriter pw
ISO-8859-1
| Constructor Detail |
|---|
public PropsFileWriter(java.io.PrintWriter pw)
"ISO-8859-1" file encoding.
public PropsFileWriter(java.io.File pFile)
throws java.io.FileNotFoundException,
java.lang.SecurityException,
java.io.UnsupportedEncodingException
pFile - Properties file to write
java.io.FileNotFoundException - if the file can't be created, opened, or written, or is a unix special file
java.lang.SecurityException - if write access is denied
java.io.UnsupportedEncodingException - if the "ISO-8859-1" file encoding is somehow not supported;
this is the encoding used by Java properties files, so it should be available;
this error is not expected to occur.| Method Detail |
|---|
public static final boolean isValidHighISO8859_1(char c)
c valid in both ISO-8859-1 and ISO-8859-15?
If not, it should be escaped (\uXXXX) in the output file.
If a character returns true here, its unicode char can be output as its ISO-8859-1 byte:
"ISO-8859-1 was incorporated as the first 256 code points ... of Unicode" -- Wikipedia ISO-8859-1 article
This function tests only "high-bit" characters (0x80 and above): Any character below 00A0 returns false,
including ascii characters which are valid in ISO-8859-1. Just use an if-statement to test the range
0x20 to 0x7E (' ' to '~') instead.
In case of editing on a computer using the newer ISO-8859-15, the few ISO-8859-1 characters dropped from that encoding return false.
c - A non-ascii "high-bit" character, with unicode code point 0080 or higher
public static final void appendEsc(java.lang.StringBuilder sb,
char c)
sb - StringBuilder to append c ontoc - A character to escape; \t \r \n and ' ' are appended as their 2-character text escapes,
all others will be appended as \uXXXX (4 hex digits).public static final java.lang.String escValue(java.lang.String val)
val - Property value to unicode-escape
val if escapes were needed, otherwise val
public static final void writeOne(java.io.PrintWriter pw,
java.lang.String key,
java.lang.String val,
java.util.List<java.lang.String> comments,
boolean spacedEquals)
\uXXXX
where needed, otherwise keeping val unchanged and keeping high-bit ISO-8859-1 characters for easier viewing.
pw - An open PrintWriter for the output file; must have encoding ISO-8859-1key - Key to write; assumes no special characters to be escapedval - Value to write; leading whitespace and special characters will be escaped;
backslashes will not be doubled, assumes they are part of an escape sequence in valcomments - Comment lines to write above key=value, or null; each one must contain a leading "# "spacedEquals - If true, If true, the key and value are separated by " = " instead of "="public void flush()
public void close()
public void write(java.util.List<PropsFileParser.KeyPairLine> pairs,
java.lang.String fileComment)
pairs - Key-value pairs to write, same format as PropsFileParser.parseOneFile(File)fileComment - Optional single-line comment to place above output keys, or null; will prepend "# "
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||