in src/main/java/org/apache/sling/installer/core/impl/InternalResource.java [227:296]
private static Dictionary<String, Object> readDictionary(
final InputStream is, final String scheme, final String id)
throws IOException {
if ( id.endsWith(".cfg.json") ) {
String configId;
int pos = id.lastIndexOf('/');
if ( pos == -1 ) {
configId = id;
} else {
configId = id.substring(pos + 1);
}
pos = configId.indexOf('-');
if ( pos != -1 ) {
configId = configId.substring(0, pos).concat("~").concat(configId.substring(pos+1));
}
configId = removeConfigExtension(configId);
// read from input stream
try(final Reader reader = new InputStreamReader(is, "UTF-8")) {
return Configurations.buildReader()
.withIdentifier(configId).build(reader).readConfiguration();
}
} else {
final Hashtable<String, Object> ht = new Hashtable<>();
try (final BufferedInputStream in = new BufferedInputStream(is)) {
if (id.endsWith(".config") ) {
// check for initial comment line
in.mark(256);
final int firstChar = in.read();
if ( firstChar == '#' ) {
int b;
while ((b = in.read()) != '\n' ) {
if ( b == -1 ) {
throw new IOException("Unable to read configuration.");
}
}
} else {
in.reset();
}
@SuppressWarnings("unchecked")
final Dictionary<String, Object> config = ConfigurationHandler.read(in);
final Enumeration<String> i = config.keys();
while ( i.hasMoreElements() ) {
final String key = i.nextElement();
ht.put(key, config.get(key));
}
} else {
final Properties p = new Properties();
in.mark(1);
boolean isXml = in.read() == '<';
in.reset();
if (isXml) {
p.loadFromXML(in);
} else {
p.load(in);
}
final Enumeration<Object> i = p.keys();
while ( i.hasMoreElements() ) {
final Object key = i.nextElement();
ht.put(key.toString(), p.get(key));
}
}
}
return ht;
}
}