Main method @param args Optional file path @throws URISyntaxException on invalid path
(String[] args)
| 53 | * on invalid path |
| 54 | */ |
| 55 | public static void main(String[] args) throws URISyntaxException { |
| 56 | // Use the arg as a file path or get this class's path |
| 57 | String filePath = args.length > 0 ? args[0] |
| 58 | : new File(DiskStoreForPath.class.getProtectionDomain().getCodeSource().getLocation().toURI()) |
| 59 | .getPath(); |
| 60 | System.out.println("Searching stores for path: " + filePath); |
| 61 | |
| 62 | SystemInfo si = new SystemInfo(); |
| 63 | HardwareAbstractionLayer hal = si.getHardware(); |
| 64 | List<HWDiskStore> diskStores = hal.getDiskStores(); |
| 65 | Pair<Integer, Integer> dsPartIdx = getDiskStoreAndPartitionForPath(filePath, diskStores); |
| 66 | int dsIndex = dsPartIdx.getA(); |
| 67 | int partIndex = dsPartIdx.getB(); |
| 68 | |
| 69 | System.out.println(); |
| 70 | System.out.println("DiskStore index " + dsIndex + " and Partition index " + partIndex); |
| 71 | if (dsIndex >= 0 && partIndex >= 0) { |
| 72 | System.out.println(diskStores.get(dsIndex)); |
| 73 | System.out.println(" |-- " + diskStores.get(dsIndex).getPartitions().get(partIndex)); |
| 74 | } else { |
| 75 | System.out.println("Couldn't find that path on a partition."); |
| 76 | } |
| 77 | |
| 78 | OperatingSystem os = si.getOperatingSystem(); |
| 79 | List<OSFileStore> fileStores = os.getFileSystem().getFileStores(); |
| 80 | int fsIndex = getFileStoreForPath(filePath, fileStores); |
| 81 | |
| 82 | System.out.println(); |
| 83 | System.out.println("FileStore index " + fsIndex); |
| 84 | if (fsIndex >= 0) { |
| 85 | System.out.println(fileStores.get(fsIndex)); |
| 86 | } else { |
| 87 | System.out.println("Couldn't find that path on a filestore."); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | private static Pair<Integer, Integer> getDiskStoreAndPartitionForPath(String path, List<HWDiskStore> diskStores) { |
| 92 | for (int ds = 0; ds < diskStores.size(); ds++) { |
nothing calls this directly
no test coverage detected