forked from j62/ctbrec
1
0
Fork 0

If a recording does not exist, show n/a for its size

This commit is contained in:
0xboobface 2019-12-28 16:56:18 +01:00
parent 738aca8a06
commit a165a83dca
2 changed files with 26 additions and 13 deletions

View File

@ -1,6 +1,7 @@
package ctbrec; package ctbrec;
import java.io.File; import java.io.File;
import java.io.Serializable;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -12,7 +13,7 @@ import ctbrec.event.EventBusHolder;
import ctbrec.event.RecordingStateChangedEvent; import ctbrec.event.RecordingStateChangedEvent;
import ctbrec.recorder.download.Download; import ctbrec.recorder.download.Download;
public class Recording { public class Recording implements Serializable {
private Model model; private Model model;
private transient Download download; private transient Download download;
private Instant startDate; private Instant startDate;
@ -195,7 +196,11 @@ public class Recording {
return getDirectorySize(rec); return getDirectorySize(rec);
} else { } else {
if (!rec.exists()) { if (!rec.exists()) {
if (rec.getName().endsWith(".m3u8")) {
return getDirectorySize(rec.getParentFile()); return getDirectorySize(rec.getParentFile());
} else {
return -1;
}
} else { } else {
return rec.length(); return rec.length();
} }
@ -204,6 +209,7 @@ public class Recording {
private long getDirectorySize(File dir) { private long getDirectorySize(File dir) {
long size = 0; long size = 0;
if (dir.exists()) {
File[] files = dir.listFiles(); File[] files = dir.listFiles();
if (files == null) { if (files == null) {
return 0; return 0;
@ -211,6 +217,7 @@ public class Recording {
for (File file : files) { for (File file : files) {
size += file.length(); size += file.length();
} }
}
return size; return size;
} }

View File

@ -3,6 +3,8 @@ package ctbrec;
import java.text.DecimalFormat; import java.text.DecimalFormat;
public class StringUtil { public class StringUtil {
private StringUtil() {}
public static boolean isBlank(String s) { public static boolean isBlank(String s) {
return s == null || s.trim().isEmpty(); return s == null || s.trim().isEmpty();
} }
@ -12,6 +14,10 @@ public class StringUtil {
} }
public static String formatSize(Number sizeInByte) { public static String formatSize(Number sizeInByte) {
if (sizeInByte.longValue() < 0) {
return "n/a";
}
DecimalFormat df = new DecimalFormat("0.00"); DecimalFormat df = new DecimalFormat("0.00");
String unit = "Bytes"; String unit = "Bytes";
double size = sizeInByte.doubleValue(); double size = sizeInByte.doubleValue();