mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 11:09:49 +08:00
Added: Support for reading and writing serialized objects to files and deleting files older than x days in FileUtils
This commit is contained in:
@@ -4,6 +4,10 @@ import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class DataUtils {
|
||||
|
||||
public static final int TRANSACTION_SIZE_LIMIT_IN_BYTES = 100 * 1024; // 100KB
|
||||
@@ -172,4 +176,21 @@ public class DataUtils {
|
||||
return string == null || string.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Get size of a serializable object. */
|
||||
public static long getSerializedSize(Serializable object) {
|
||||
if (object == null) return 0;
|
||||
try {
|
||||
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteOutputStream);
|
||||
objectOutputStream.writeObject(object);
|
||||
objectOutputStream.flush();
|
||||
objectOutputStream.close();
|
||||
return byteOutputStream.toByteArray().length;
|
||||
} catch (Exception e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user