/** * Load the INI from an InputStream using the given encoding. * * @param is the InputStream to read from * @param encoding the encoding of the file * @throws IOException */ public void load(InputStream is, String encoding) throws IOException { load(is, encoding, null); }
/** * Load the conf from a buffer. This is used to load conf entries from the * mods.d.tar.gz file. * * @param buffer the buffer to load * @param encoding the character encoding of this INI * @throws IOException */ public void load(byte[] buffer, String encoding) throws IOException { load(buffer, encoding, null); }
/** * Load the INI from a file using the given encoding. * * @param file the file to load * @param encoding the encoding of the file * @throws IOException */ public void load(File file, String encoding) throws IOException { load(file, encoding, null); }
/** * Load the INI from a file using the given encoding. Filter keys as specified. * * @param file the file to load * @param encoding the encoding of the file * @param filter the filter, possibly null, for the desired keys * @throws IOException */ public void load(File file, String encoding, Filter<String> filter) throws IOException { this.configFile = file; this.charset = encoding; InputStream in = null; try { in = new FileInputStream(file); load(in, encoding, filter); } finally { if (in != null) { in.close(); in = null; } } }
/** * Load the conf from a buffer. Filter keys as specified. * This is used to load conf entries from the mods.d.tar.gz file. * * @param buffer the buffer to load * @param encoding the character encoding of this INI * @param filter the filter, possibly null, for the desired keys * @throws IOException */ public void load(byte[] buffer, String encoding, Filter<String> filter) throws IOException { InputStream in = null; try { in = new ByteArrayInputStream(buffer); load(in, encoding, filter); } finally { if (in != null) { in.close(); in = null; } } }
/** * Load the conf from a file. * * @param keepers * the keys to keep. When null keep all * @throws IOException */ private void loadFile(Filter<String> keepers) throws IOException { filtered = keepers != null; configAll.clear(); configAll.load(configFile, ENCODING_UTF8, keepers); String encoding = configAll.get(KEY_ENCODING); if (!ENCODING_UTF8.equalsIgnoreCase(encoding)) { configAll.clear(); configAll.load(configFile, ENCODING_LATIN1, keepers); } }
/** * Load the conf from a buffer. This is used to load conf entries from the cached mods.d.tar.gz or mods.d.zip file. * * @param buffer * the buffer to load * @throws IOException */ private void loadBuffer(byte[] buffer, Filter<String> keepers) throws IOException { filtered = keepers != null; configAll.clear(); configAll.load(buffer, ENCODING_UTF8, keepers); String encoding = configAll.get(KEY_ENCODING); if (!ENCODING_UTF8.equalsIgnoreCase(encoding)) { configAll.clear(); configAll.load(buffer, ENCODING_LATIN1, keepers); } }
public void parse() throws IOException { File confFile = new File(conf); if (!confFile.exists()) { System.err.println("File does not exist: " + conf); return; } IniSection config = new IniSection(); // So called Latin-1 is the default, but most are UTF-8 config.load(confFile, "UTF-8"); String encoding = config.get("Encoding"); if (encoding == null || "Latin-1".equalsIgnoreCase(encoding)) { config.clear(); config.load(confFile, "WINDOWS-1252"); } SwordBookMetaData.report(config); SwordBookMetaData.normalize(new PrintWriter(System.out), config, CANONICAL_ORDER); }
private IniSection addConfig(MetaDataLocator locator) { // The write location supersedes the read location File conf = new File(locator.getWriteLocation(), bookConf); if (!conf.exists()) { conf = new File(locator.getReadLocation(), bookConf); } if (conf.exists()) { // The additional confs have the same encoding as the SWORD conf. String encoding = getProperty(KEY_ENCODING); try { IniSection config = new IniSection(); config.load(conf, encoding); mergeConfig(config); return config; } catch (IOException e) { LOGGER.error("Unable to load conf {}:{}", conf, e); } } return null; }