Example #1
0
  @Override
  protected boolean run() throws IOException {
    final String path = MetaData.normPath(args[0]);
    if (path == null) return error(NAME_INVALID_X, args[0]);

    final IOFile bin = context.data().meta.binary(path);
    if (bin == null || !bin.exists() || bin.isDir()) return error(RES_NOT_FOUND_X, path);

    try {
      final BufferInput bi = new BufferInput(bin);
      try {
        for (int b; (b = bi.read()) != -1; ) out.write(b);
      } finally {
        bi.close();
      }
      return info(QUERY_EXECUTED_X, perf);
    } catch (final IOException ex) {
      return error(FILE_NOT_STORED_X, ex);
    }
  }
Example #2
0
  @Override
  protected boolean run() {
    final boolean create = context.user.has(Perm.CREATE);
    String path = MetaData.normPath(args[0]);
    if (path == null || path.endsWith(".")) return error(NAME_INVALID_X, args[0]);

    if (in == null) {
      final IO io = IO.get(args[1]);
      if (!io.exists() || io.isDir()) return error(RES_NOT_FOUND_X, create ? io : args[1]);
      in = io.inputSource();
      // set/add name of document
      if ((path.isEmpty() || path.endsWith("/")) && !(io instanceof IOContent)) path += io.name();
    }

    // ensure that the final name is not empty
    if (path.isEmpty()) return error(NAME_INVALID_X, path);

    // ensure that the name is not empty and contains no trailing dots
    final Data data = context.data();
    if (data.inMemory()) return error(NO_MAINMEM);

    final IOFile file = data.meta.binary(path);
    if (path.isEmpty() || path.endsWith(".") || file == null || file.isDir())
      return error(NAME_INVALID_X, create ? path : args[0]);

    // start update
    if (!data.startUpdate()) return error(DB_PINNED_X, data.meta.name);

    try {
      store(in, file);
      return info(QUERY_EXECUTED_X_X, "", perf);
    } catch (final IOException ex) {
      return error(FILE_NOT_STORED_X, Util.message(ex));
    } finally {
      data.finishUpdate();
    }
  }