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)
| 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. |