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

Method write

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

Writes the options to disk.

()

Source from the content-addressed store, hash-verified

117 * Writes the options to disk.
118 */
119 public final synchronized void write() {
120 final StringList lines = new StringList();
121 try {
122 for(final Option<?> option : options(getClass())) {
123 final String name = option.name();
124 if(option instanceof Comment) {
125 if(!lines.isEmpty()) lines.add("");
126 lines.add("# " + name);
127 } else if(option instanceof final NumbersOption no) {
128 final int[] ints = get(no);
129 final int is = ints == null ? 0 : ints.length;
130 for(int i = 0; i < is; i++) lines.add(name + i + " = " + ints[i]);
131 } else if(option instanceof final StringsOption so) {
132 final String[] strings = get(so);
133 final int ss = strings == null ? 0 : strings.length;
134 lines.add(name + " = " + ss);
135 for(int s = 0; s < ss; s++) lines.add(name + (s + 1) + " = " + strings[s]);
136 } else {
137 lines.add(name + " = " + get(option));
138 }
139 }
140 lines.add("").add(PROPUSER).add(user);
141
142 // only write file if contents have changed
143 final TokenBuilder tb = new TokenBuilder();
144 for(final String line : lines) tb.add(line).add(NL);
145 final byte[] contents = tb.finish();
146
147 boolean skip = file.exists();
148 if(skip) {
149 final TokenBuilder tmp = new TokenBuilder(contents.length);
150 try(NewlineInput nli = new NewlineInput(file)) {
151 for(String line; (line = nli.readLine()) != null;) tmp.add(line).add(NL);
152 }
153 skip = eq(contents, tmp.finish());
154 }
155 if(!skip) {
156 file.parent().md();
157 file.write(contents);
158 }
159 } catch(final Exception ex) {
160 Util.errln("% could not be written.", file);
161 Util.debug(ex);
162 }
163 }
164
165 /**
166 * Returns the option with the specified name.

Callers 1

readMethod · 0.95

Calls 15

optionsMethod · 0.95
addMethod · 0.95
getMethod · 0.95
addMethod · 0.95
finishMethod · 0.95
errlnMethod · 0.95
debugMethod · 0.95
mdMethod · 0.80
nameMethod · 0.65
addMethod · 0.65
eqMethod · 0.65
isEmptyMethod · 0.45

Tested by

no test coverage detected