Class DiskPartitionService

java.lang.Object
io.github.eggy03.ferrumx.windows.service.storage.DiskPartitionService
All Implemented Interfaces:
CommonServiceInterface<DiskPartition>

public class DiskPartitionService extends Object implements CommonServiceInterface<DiskPartition>
Service class for fetching information about disk partitions.

This class executes the CimQuery.DISK_PARTITION_QUERY PowerShell command and maps the resulting JSON into a list of DiskPartition objects.

Thread safety

Methods of class are not thread safe.

Usage examples


 // Convenience API (creates its own short-lived session)
 DiskPartitionService partitionService = new DiskPartitionService();
 List<DiskPartition> partitions = partitionService.get();

 // API with re-usable session (caller manages session lifecycle)
 try (PowerShell session = PowerShell.openSession()) {
     DiskPartitionService partitionService = new DiskPartitionService();
     List<DiskPartition> partitions = partitionService.get(session);
 }
 
Since:
2.0.0
Author:
Egg-03
  • Constructor Details

    • DiskPartitionService

      public DiskPartitionService()
  • Method Details

    • get

      @NotNull public @NotNull List<DiskPartition> get()
      Retrieves a non-null list of disk partitions present in the system.

      Each invocation creates and uses a short-lived PowerShell session internally.

      Specified by:
      get in interface CommonServiceInterface<DiskPartition>
      Returns:
      a list of DiskPartition objects representing the disk partitions. Returns an empty list if no partitions are detected.
    • get

      @NotNull public @NotNull List<DiskPartition> get(com.profesorfalken.jpowershell.PowerShell powerShell)
      Retrieves a non-null list of disk partitions using the caller's PowerShell session.
      Specified by:
      get in interface CommonServiceInterface<DiskPartition>
      Parameters:
      powerShell - an existing PowerShell session managed by the caller
      Returns:
      a list of DiskPartition objects representing the disk partitions. Returns an empty list if no partitions are detected.