If a recording does not exist, show n/a for its size
This commit is contained in:
parent
738aca8a06
commit
a165a83dca
|
@ -1,6 +1,7 @@
|
|||
package ctbrec;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -12,7 +13,7 @@ import ctbrec.event.EventBusHolder;
|
|||
import ctbrec.event.RecordingStateChangedEvent;
|
||||
import ctbrec.recorder.download.Download;
|
||||
|
||||
public class Recording {
|
||||
public class Recording implements Serializable {
|
||||
private Model model;
|
||||
private transient Download download;
|
||||
private Instant startDate;
|
||||
|
@ -195,7 +196,11 @@ public class Recording {
|
|||
return getDirectorySize(rec);
|
||||
} else {
|
||||
if (!rec.exists()) {
|
||||
if (rec.getName().endsWith(".m3u8")) {
|
||||
return getDirectorySize(rec.getParentFile());
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return rec.length();
|
||||
}
|
||||
|
@ -204,6 +209,7 @@ public class Recording {
|
|||
|
||||
private long getDirectorySize(File dir) {
|
||||
long size = 0;
|
||||
if (dir.exists()) {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
return 0;
|
||||
|
@ -211,6 +217,7 @@ public class Recording {
|
|||
for (File file : files) {
|
||||
size += file.length();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package ctbrec;
|
|||
import java.text.DecimalFormat;
|
||||
|
||||
public class StringUtil {
|
||||
private StringUtil() {}
|
||||
|
||||
public static boolean isBlank(String s) {
|
||||
return s == null || s.trim().isEmpty();
|
||||
}
|
||||
|
@ -12,6 +14,10 @@ public class StringUtil {
|
|||
}
|
||||
|
||||
public static String formatSize(Number sizeInByte) {
|
||||
if (sizeInByte.longValue() < 0) {
|
||||
return "n/a";
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
String unit = "Bytes";
|
||||
double size = sizeInByte.doubleValue();
|
||||
|
|
Loading…
Reference in New Issue