MCPcopy Create free account
hub / github.com/BaseXdb/basex / read

Method read

basex-core/src/main/java/org/basex/util/options/Options.java:734–807  ·  view source on GitHub ↗

Reads the configuration file and initializes the options. The file is located in the project home directory. @param io options file

(final IOFile io)

Source from the content-addressed store, hash-verified

732 * @param io options file
733 */
734 private synchronized void read(final IOFile io) {
735 file = io;
736 final StringList read = new StringList(), errs = new StringList();
737 final boolean exists = file.exists();
738 if(exists) {
739 try(NewlineInput ni = new NewlineInput(io)) {
740 boolean local = false;
741 for(String line; (line = ni.readLine()) != null;) {
742 line = line.trim();
743
744 // start of local options
745 if(line.equals(PROPUSER)) {
746 local = true;
747 continue;
748 }
749 if(local) user.add(line);
750
751 if(line.isEmpty() || line.charAt(0) == '#') continue;
752 final int d = line.indexOf('=');
753 if(d < 0) {
754 errs.add("line \"" + line + "\" ignored.");
755 continue;
756 }
757
758 final String val = line.substring(d + 1).trim();
759 String name = line.substring(0, d).trim();
760
761 // extract numeric value in key
762 int num = 0;
763 final int ss = name.length();
764 for(int s = 0; s < ss; ++s) {
765 if(Character.isDigit(name.charAt(s))) {
766 num = Strings.toInt(name.substring(s));
767 name = name.substring(0, s);
768 break;
769 }
770 }
771
772 if(local) {
773 // cache local options as global options
774 Prop.put(DBPREFIX + name.toLowerCase(Locale.ENGLISH), val);
775 } else {
776 try {
777 assign(name, val, num, true);
778 read.add(name);
779 } catch(final BaseXException ex) {
780 errs.add(ex.getMessage());
781 }
782 }
783 }
784 } catch(final IOException ex) {
785 errs.add("file could not be parsed.");
786 Util.errln(ex);
787 }
788 }
789
790 // check if all mandatory files have been read
791 boolean ok = true;

Callers 1

OptionsMethod · 0.95

Calls 15

addMethod · 0.95
toIntMethod · 0.95
putMethod · 0.95
assignMethod · 0.95
errlnMethod · 0.95
optionsMethod · 0.95
notExpectedMethod · 0.95
writeMethod · 0.95
charAtMethod · 0.80
addMethod · 0.65
containsMethod · 0.65
nameMethod · 0.65

Tested by

no test coverage detected