Java 类com.facebook.stetho.dumpapp.DumpUsageException 实例源码

项目:GitHub    文件:BaseFrescoStethoPlugin.java   
/**
 * Entry point for the Stetho dumpapp script.
 *
 * {@link #initialize} must have been called in the app before running dumpapp.
 */
@Override
public void dump(DumperContext dumpContext) throws DumpException {
  ensureInitialized();
  List<String> args = dumpContext.getArgsAsList();
  PrintStream writer = dumpContext.getStdout();

  String cmd = args.isEmpty() ? null : args.get(0);
  List<String> rest = args.isEmpty() ? new ArrayList<String>() : args.subList(1, args.size());

  if (cmd != null && cmd.equals("memcache")) {
    memcache(writer, rest);
  } else if (cmd != null && cmd.equals("diskcache")) {
    diskcache(mMainFileCache, "Main", writer, rest);
    diskcache(mSmallFileCache, "Small", writer, rest);
  } else {
    usage(writer);
    if (TextUtils.isEmpty(cmd)) {
      throw new DumpUsageException("Missing command");
    } else {
      throw new DumpUsageException("Unknown command: " + cmd);
    }
  }
}
项目:stetho    文件:CrashDumperPlugin.java   
@Override
public void dump(DumperContext dumpContext) throws DumpException {
  Iterator<String> argsIter = dumpContext.getArgsAsList().iterator();

  String command = ArgsHelper.nextOptionalArg(argsIter, null);
  if ("throw".equals(command)) {
    doUncaughtException(argsIter);
  } else if ("kill".equals(command)) {
    doKill(dumpContext, argsIter);
  } else if ("exit".equals(command)) {
    doSystemExit(argsIter);
  } else {
    doUsage(dumpContext.getStdout());
    if (command != null) {
      throw new DumpUsageException("Unsupported command: " + command);
    }
  }
}
项目:stetho    文件:FilesDumperPlugin.java   
@Override
public void dump(DumperContext dumpContext) throws DumpException {
  Iterator<String> args = dumpContext.getArgsAsList().iterator();

  String command = ArgsHelper.nextOptionalArg(args, "");
  if ("ls".equals(command)) {
    doLs(dumpContext.getStdout());
  } else if ("tree".equals(command)) {
    doTree(dumpContext.getStdout());
  } else if ("download".equals(command)) {
    doDownload(dumpContext.getStdout(), args);
  } else {
    doUsage(dumpContext.getStdout());
    if (!"".equals(command)) {
      throw new DumpUsageException("Unknown command: " + command);
    }
  }
}
项目:stetho    文件:APODDumperPlugin.java   
@Override
public void dump(DumperContext dumpContext) throws DumpException {
  PrintStream writer = dumpContext.getStdout();
  Iterator<String> argsIter = dumpContext.getArgsAsList().iterator();

  String command = ArgsHelper.nextOptionalArg(argsIter, null);

  if (CMD_LIST.equalsIgnoreCase(command)) {
    doList(writer);
  } else if (CMD_DELETE.equalsIgnoreCase(command)) {
    doRemove(writer, argsIter);
  } else if (CMD_CLEAR.equalsIgnoreCase(command)) {
    doClear(writer);
  } else if (CMD_REFRESH.equalsIgnoreCase(command)) {
    doRefresh(writer);
  } else {
    usage(writer);
    if (command != null) {
      throw new DumpUsageException("Unknown command: " + command);
    }
  }
}
项目:asstudydemo    文件:APODDumperPlugin.java   
@Override
public void dump(DumperContext dumpContext) throws DumpException {
    PrintStream writer = dumpContext.getStdout();
    Iterator<String> argsIter = dumpContext.getArgsAsList().iterator();

    String command = ArgsHelper.nextOptionalArg(argsIter, null);

    if (CMD_LIST.equalsIgnoreCase(command)) {
        doList(writer);
    } else if (CMD_DELETE.equalsIgnoreCase(command)) {
        doRemove(writer, argsIter);
    } else if (CMD_CLEAR.equalsIgnoreCase(command)) {
        doClear(writer);
    } else if (CMD_REFRESH.equalsIgnoreCase(command)) {
        doRefresh(writer);
    } else {
        usage(writer);
        if (command != null) {
            throw new DumpUsageException("Unknown command: " + command);
        }
    }
}
项目:fresco    文件:BaseFrescoStethoPlugin.java   
/**
 * Entry point for the Stetho dumpapp script.
 *
 * {@link #initialize} must have been called in the app before running dumpapp.
 */
@Override
public void dump(DumperContext dumpContext) throws DumpException {
  ensureInitialized();
  List<String> args = dumpContext.getArgsAsList();
  PrintStream writer = dumpContext.getStdout();

  String cmd = args.isEmpty() ? null : args.get(0);
  List<String> rest = args.isEmpty() ? new ArrayList<String>() : args.subList(1, args.size());

  if (cmd != null && cmd.equals("memcache")) {
    memcache(writer, rest);
  } else if (cmd != null && cmd.equals("diskcache")) {
    diskcache(mMainFileCache, "Main", writer, rest);
    diskcache(mSmallFileCache, "Small", writer, rest);
  } else {
    usage(writer);
    if (TextUtils.isEmpty(cmd)) {
      throw new DumpUsageException("Missing command");
    } else {
      throw new DumpUsageException("Unknown command: " + cmd);
    }
  }
}
项目:sealtalk-android-master    文件:RongDbFilesDumperPlugin.java   
@Override
public void dump(DumperContext dumpContext) throws DumpException {
    Iterator<String> args = dumpContext.getArgsAsList().iterator();

    String command = ArgsHelper.nextOptionalArg(args, "");
    if ("download".equals(command)) {
        doDownload(dumpContext.getStdout(), args);
    } else {
        doUsage(dumpContext.getStdout());
        if (!"".equals(command)) {
            throw new DumpUsageException("Unknown command: " + command);
        }
    }
}
项目:sealtalk-android    文件:RongDbFilesDumperPlugin.java   
@Override
public void dump(DumperContext dumpContext) throws DumpException {
    Iterator<String> args = dumpContext.getArgsAsList().iterator();

    String command = ArgsHelper.nextOptionalArg(args, "");
    if ("download".equals(command)) {
        doDownload(dumpContext.getStdout(), args);
    } else {
        doUsage(dumpContext.getStdout());
        if (!"".equals(command)) {
            throw new DumpUsageException("Unknown command: " + command);
        }
    }
}
项目:stetho    文件:SharedPreferencesDumperPlugin.java   
@Override
public void dump(DumperContext dumpContext) throws DumpUsageException {
  PrintStream writer = dumpContext.getStdout();
  List<String> args = dumpContext.getArgsAsList();

  String commandName = args.isEmpty() ? "" : args.remove(0);

  if (commandName.equals("print")) {
    doPrint(writer, args);
  } else if (commandName.equals("write")) {
    doWrite(args);
  } else {
    doUsage(writer);
  }
}
项目:stetho    文件:SharedPreferencesDumperPlugin.java   
@Nonnull
private static String nextArg(Iterator<String> iter, String messageIfNotPresent)
    throws DumpUsageException {
  if (!iter.hasNext()) {
    throw new DumpUsageException(messageIfNotPresent);
  }
  return iter.next();
}
项目:stetho    文件:HprofDumperPlugin.java   
private void usage(PrintStream output) throws DumpUsageException {
  output.println("Usage: dumpapp hprof [ path ]");
  output.println("Dump HPROF memory usage data from the running application.");
  output.println();
  output.println("Where path can be any of:");
  output.println("  -           Output directly to stdout");
  output.println("  <path>      Full path to a writable file on the device");
  output.println("  <filename>  Relative filename that will be stored in the app internal storage");
  throw new DumpUsageException("Missing path");
}
项目:stetho    文件:HelloWorldDumperPlugin.java   
private void doHello(InputStream in, PrintStream writer, String name) throws DumpException {
  if (TextUtils.isEmpty(name)) {
    // This will print an error to the dumpapp user and cause a non-zero exit of the
    // script.
    throw new DumpUsageException("Name is empty");
  } else if ("-".equals(name)) {
    try {
      name = new BufferedReader(new InputStreamReader(in)).readLine();
    } catch (IOException e) {
      throw new DumpException(e.toString());
    }
  }

  writer.println("Hello " + name + "!");
}
项目:asstudydemo    文件:HelloWorldDumperPlugin.java   
private void doHello(InputStream in, PrintStream writer, String name) throws DumpException {
    if (TextUtils.isEmpty(name)) {
        // This will print an error to the dumpapp user and cause a non-zero exit of the
        // script.
        throw new DumpUsageException("Name is empty");
    } else if ("-".equals(name)) {
        try {
            name = new BufferedReader(new InputStreamReader(in)).readLine();
        } catch (IOException e) {
            throw new DumpException(e.toString());
        }
    }

    writer.println("Hello " + name + "!");
}
项目:stetho    文件:SharedPreferencesDumperPlugin.java   
/**
 * Executes command to update one value in the shared preferences
 */
// We explicitly want commit() so that the dumper blocks while the write occurs.
@SuppressLint("CommitPrefEdits")
private void doWrite(List<String> args) throws DumpUsageException {
  String usagePrefix = "Usage: prefs write <path> <key> <type> <value>, where type is one of: ";

  Iterator<String> argsIter = args.iterator();
  String path = nextArg(argsIter, "Expected <path>");
  String key = nextArg(argsIter, "Expected <key>");
  String typeName = nextArg(argsIter, "Expected <type>");

  Type type = Type.of(typeName);
  if (type == null) {
    throw new DumpUsageException(
        Type.appendNamesList(new StringBuilder(usagePrefix), ", ").toString());
  }

  SharedPreferences sharedPreferences = getSharedPreferences(path);
  SharedPreferences.Editor editor = sharedPreferences.edit();

  switch (type) {
    case BOOLEAN:
      editor.putBoolean(key, Boolean.valueOf(nextArgValue(argsIter)));
      break;
    case INT:
      editor.putInt(key, Integer.valueOf(nextArgValue(argsIter)));
      break;
    case LONG:
      editor.putLong(key, Long.valueOf(nextArgValue(argsIter)));
      break;
    case FLOAT:
      editor.putFloat(key, Float.valueOf(nextArgValue(argsIter)));
      break;
    case STRING:
      editor.putString(key, nextArgValue(argsIter));
      break;
    case SET:
      putStringSet(editor, key, argsIter);
      break;
  }

  editor.commit();
}
项目:stetho    文件:SharedPreferencesDumperPlugin.java   
@Nonnull
private static String nextArgValue(Iterator<String> iter) throws DumpUsageException {
  return nextArg(iter, "Expected <value>");
}
项目:stetho    文件:FilesDumperPlugin.java   
private void doLs(PrintStream writer) throws DumpUsageException {
  File baseDir = getBaseDir(mContext);
  if (baseDir.isDirectory()) {
    printDirectoryText(baseDir, "", writer);
  }
}
项目:stetho    文件:FilesDumperPlugin.java   
private void doTree(PrintStream writer) throws DumpUsageException {
  File baseDir = getBaseDir(mContext);
  printDirectoryVisual(baseDir, 0, writer);
}
项目:stetho    文件:APODDumperPlugin.java   
private void doRemove(PrintStream writer, Iterator<String> argsIter) throws DumpUsageException {
  String rowId = ArgsHelper.nextArg(argsIter, "Expected rowId");

  delete(writer, APODContract.Columns._ID + "=?", new String[] {rowId});
}
项目:info-dumper    文件:InfoDumperPlugin.java   
@Override
public void dump(DumperContext dumperContext) throws DumpException {
    Iterator<String> argsIterator = dumperContext.getArgsAsList().iterator();

    String command = ArgsHelper.nextOptionalArg(argsIterator, null);

    mIsAll = false;

    if (CMD_BUILD_CONFIG.equalsIgnoreCase(command)) {
        dumpBuildConfig(dumperContext);
    } else if (CMD_PERMISSION.equalsIgnoreCase(command)) {
        dumpPermission(dumperContext);
    } else if (CMD_LAST_UPDATE.equalsIgnoreCase(command)) {
        dumpLastUpdate(dumperContext);
    } else if (CMD_APPLICATION_INFO.equalsIgnoreCase(command)) {
        dumpApplicationInfo(dumperContext);
    } else if (CMD_ID.equalsIgnoreCase(command)) {
        dumpIds(dumperContext);
    } else if (CMD_OS_BUILD.equalsIgnoreCase(command)) {
        dumpOsBuild(dumperContext);
    } else if (CMD_DPI.equalsIgnoreCase(command)) {
        dumpDpi(dumperContext);
    } else if (CMD_MEMORY.equalsIgnoreCase(command)) {
        dumpMemory(dumperContext);
    } else if (CMD_ERROR.equalsIgnoreCase(command)) {
        dumpError(dumperContext);
    } else if (CMD_NETWORK.equalsIgnoreCase(command)) {
        dumpNetwork(dumperContext);
    } else if (CMD_TEL.equalsIgnoreCase(command)) {
        dumpTel(dumperContext);
    } else if (CMD_ALL.equalsIgnoreCase(command)) {
        mIsAll = true;
        dumpBuildConfig(dumperContext);
        dumpPermission(dumperContext);
        dumpLastUpdate(dumperContext);
        dumpApplicationInfo(dumperContext);
        dumpIds(dumperContext);
        dumpOsBuild(dumperContext);
        dumpDpi(dumperContext);
        dumpMemory(dumperContext);
        dumpError(dumperContext);
        dumpNetwork(dumperContext);
        dumpTel(dumperContext);
    } else {
        usage(dumperContext);
        if (command != null) {
            throw new DumpUsageException("Unknown command: " + command);
        }
    }
}
项目:asstudydemo    文件:APODDumperPlugin.java   
private void doRemove(PrintStream writer, Iterator<String> argsIter) throws DumpUsageException {
    String rowId = ArgsHelper.nextArg(argsIter, "Expected rowId");

    delete(writer, APODContract.Columns._ID + "=?", new String[]{rowId});
}