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

Method sourceToIO

basex-core/src/main/java/org/basex/core/cmd/ACreate.java:52–76  ·  view source on GitHub ↗

Converts the input (second argument of #args, or #in reference) to an IO reference. @param name name of source @return IO reference (can be null) @throws IOException I/O exception

(final String name)

Source from the content-addressed store, hash-verified

50 * @throws IOException I/O exception
51 */
52 final IO sourceToIO(final String name) throws IOException {
53 IO io = null;
54 if(args[1] != null && !args[1].isEmpty()) {
55 io = IO.get(args[1]);
56 } else if(in != null) {
57 if(in.getCharacterStream() != null) {
58 final StringBuilder sb = new StringBuilder();
59 try(Reader r = in.getCharacterStream()) {
60 for(int c; (c = r.read()) != -1;) sb.append((char) c);
61 }
62 io = new IOContent(sb.toString());
63 } else if(in.getByteStream() != null) {
64 io = new IOStream(in.getByteStream());
65 } else if(in.getSystemId() != null) {
66 io = IO.get(in.getSystemId());
67 }
68 }
69
70 // assign (intermediate) name to input reference
71 if(io instanceof IOContent || io instanceof IOStream) {
72 if(Strings.endsWith(name, '/')) throw new BaseXException(NAME_INVALID_X, name);
73 io.name(name.isEmpty() ? "" : name + '.' + options.get(MainOptions.PARSER));
74 }
75 return io;
76 }
77
78 /**
79 * Runs an update operation.

Callers 2

buildMethod · 0.80
runMethod · 0.80

Calls 8

getMethod · 0.95
endsWithMethod · 0.95
nameMethod · 0.95
readMethod · 0.65
appendMethod · 0.65
toStringMethod · 0.65
getMethod · 0.65
isEmptyMethod · 0.45

Tested by

no test coverage detected