ini4j INI key length > 80 chars

104 Views Asked by At

I need to communicate with a 3th party software through INI files, and I'm using the ini4j library for this.

All was going well, until I need to be able to use a key length of >80 chars.

The library is returning :

Exception in thread "main" java.lang.IllegalArgumentException: Key too long: 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 at java.util.prefs.AbstractPreferences.put(AbstractPreferences.java:243)

The library has set this in Preferences.java:

public static final int MAX_KEY_LENGTH = 80;

Is there any clean way around this?

I found something related here, but I'm not sure how to use it: http://ini4j.sourceforge.net/apidocs/index.html?org/ini4j/addon/StrictPreferences.html

This is the sample code:

try {
    Wini ini = new Wini(new File("test.ini"));
    ini.getConfig().setStrictOperator(true);
    ini.getConfig().setEscape(false);
    java.util.prefs.Preferences prefs = new IniPreferences(ini);
    prefs.node("Section").put("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", "Test");
    ini.store();
} catch (IOException e) {
    e.printStackTrace();
}
1

There are 1 best solutions below

0
On BEST ANSWER

I was able to fix my problem by using the JIniFile library (https://github.com/SubZane/JIniFile) instead of the Ini4j library. All working fine now.