欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Java 装载类使用示例 - 例 1:getMounts

最编程 2024-03-16 14:27:06
...
import com.stericson.RootTools.containers.Mount; //导入依赖的package包/类
/**
 * This will return an ArrayList of the class Mount. The class mount contains the following
 * property's: device mountPoint type flags
 * <p/>
 * These will provide you with any information you need to work with the mount points.
 *
 * @return <code>ArrayList<Mount></code> an ArrayList of the class Mount.
 * @throws Exception if we cannot return the mount points.
 */
public ArrayList<Mount> getMounts() throws Exception {

    InternalVariables.mounts = new ArrayList<>();

    if (null == InternalVariables.mounts || InternalVariables.mounts.isEmpty()) {
        Shell shell = RootTools.getShell(true);

        Command cmd = new Command(Constants.GET_MOUNTS,
                false,
                "cat /proc/mounts") {

            @Override
            public void commandOutput(int id, String line) {
                if (id == Constants.GET_MOUNTS) {
                    RootTools.log(line);

                    String[] fields = line.split(" ");
                    InternalVariables.mounts.add(new Mount(new File(fields[0]), // device
                            new File(fields[1]), // mountPoint
                            fields[2], // fstype
                            fields[3] // flags
                    ));
                }

                super.commandOutput(id, line);
            }
        };
        shell.add(cmd);
        this.commandWait(shell, cmd);
    }

    return InternalVariables.mounts;
}
 

推荐阅读