-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
251 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/eu/wauz/wazera/controller/docs/FileSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package eu.wauz.wazera.controller.docs; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileStore; | ||
import java.nio.file.FileSystems; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FileSystem { | ||
|
||
public static List<FileSystem> findAll() { | ||
List<FileSystem> fileSystems = new ArrayList<>(); | ||
for(FileStore store : FileSystems.getDefault().getFileStores()) { | ||
try { | ||
if(store.getTotalSpace() > Math.pow(1028, 3) * 16) { | ||
fileSystems.add(new FileSystem(store)); | ||
} | ||
} | ||
catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return fileSystems; | ||
} | ||
|
||
private String name = "Unknown"; | ||
|
||
private String type = "Unknown"; | ||
|
||
private String free = "Unknown"; | ||
|
||
private String total = "Unknown"; | ||
|
||
private int usage = 0; | ||
|
||
private FileSystem(FileStore store) throws IOException { | ||
name = store.name(); | ||
type = store.type(); | ||
long freeSpace = store.getUnallocatedSpace(); | ||
long totalSpace = store.getTotalSpace(); | ||
free = getByteUnit(freeSpace); | ||
total = getByteUnit(totalSpace); | ||
usage = (int) ((float) (totalSpace - freeSpace) / (float) totalSpace * 100.0); | ||
} | ||
|
||
private String getByteUnit(long bytes) { | ||
if (bytes < 1024) { | ||
return bytes + " B"; | ||
} | ||
int exp = (int) (Math.log(bytes) / Math.log(1024)); | ||
return String.format("%.0f %sB", bytes / Math.pow(1024, exp), ("KMGTPE").charAt(exp - 1)); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getFree() { | ||
return free; | ||
} | ||
|
||
public String getTotal() { | ||
return total; | ||
} | ||
|
||
public int getUsage() { | ||
return usage; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.