When db4o stores and loads strings it has to convert them to and from bytes. Until recently db4o only used to supply 2 encodings to do this work:
One for 16-bit Unicode, the other for ISO 8859-1. To decide for one or the other you would call Configuration#unicode() and pass true for Unicode and false for ISO 8859-1.
To supply more encodings and to allow the creation of own string encodings we deprecated the old configuration interface and supply a new one. Now you can either use one of the built-in encodings from the StringEncodings class or pass your own encoding. Examples:
Configuration config = Db4o.newConfiguration();
config.stringEncoding(StringEncodings.utf8());
Db4o.openFile(config, "myDB.db4o");
or
Configuration config = Db4o.newConfiguration();
config.stringEncoding(new StringEncoding() {
public byte[] encode(String str) {
// TODO: implement
return null;
}
public String decode(byte[] bytes, int start, int length) {
// TODO: implement
return null;
}
});
Db4o.openFile(config, "myDB.db4o");
Please note that you should configure the string encoding before you create the database file, in the first call to #openFile() or #openServer(). If you use one of the built-in encodings, db4o will remember the encoding for all subsequent open calls. If you use a StringEncoding class that you have written yourself, you have to supply the same StringEncoding and configure it for all subsequent open calls, otherwise db4o will not be able to read and write strings correctly. Since db4o also uses the string encodings for metadata like classnames and fieldnames, you are likely to notice any misconfiguration very quickly by not being able to read any objects at all.
The StringEncoding used has to stay the same for the lifetime of a database.
Although we keep the Unicode string encoding as the standard setting, we encourage the use of the new built-in UTF-8 string encoding for smaller and faster database files.
We also hope that the pluggable interface will be useful for you, especially if you want db4o to work with Chinese or Japanese character sets.
Enjoy!