Add encryption option
This commit is contained in:
@@ -2,9 +2,11 @@ package nl.astraeus.persistence
|
||||
|
||||
import java.io.File
|
||||
import java.io.ObjectInputStream
|
||||
import java.util.*
|
||||
|
||||
class TransactionLog(
|
||||
directory: File,
|
||||
val decryptionKey: String? = null,
|
||||
) {
|
||||
val fileManager = FileManager(directory)
|
||||
|
||||
@@ -14,14 +16,15 @@ class TransactionLog(
|
||||
|
||||
printer("Snapshot:")
|
||||
snapshot?.inputStream()?.use { input ->
|
||||
ObjectInputStream(input).use { ois ->
|
||||
ObjectInputStream(DecryptingInputStream(input, decryptionKey)).use { ois ->
|
||||
val versionNumber = ois.readInt()
|
||||
check(versionNumber == 1) {
|
||||
"Unsupported version number: $versionNumber"
|
||||
}
|
||||
val transactionNumber = ois.readLong()
|
||||
printer("[$versionNumber] $transactionNumber")
|
||||
val data = ois.readObject() as MutableMap<Class<*>, TypeData>
|
||||
val dataObj = ois.readObject()
|
||||
val data = dataObj as MutableMap<Class<*>, TypeData>
|
||||
printer("Data:")
|
||||
printer("\tClasses:")
|
||||
for ((cls, entries) in data.entries) {
|
||||
@@ -35,15 +38,26 @@ class TransactionLog(
|
||||
printer("Transactions:")
|
||||
transactions?.forEach { transaction ->
|
||||
transaction.inputStream().use { input ->
|
||||
ObjectInputStream(input).use { ois ->
|
||||
ObjectInputStream(DecryptingInputStream(input, decryptionKey)).use { ois ->
|
||||
val versionNumber = ois.readInt()
|
||||
check(versionNumber == 1) {
|
||||
"Unsupported version number: $versionNumber"
|
||||
}
|
||||
val transactionNumber = ois.readLong()
|
||||
val actions = ois.readObject() as Set<Action>
|
||||
val actions = ois.readObject()
|
||||
val actionList = when(actions) {
|
||||
is Set<*> -> {
|
||||
LinkedList(actions as Set<Action>)
|
||||
}
|
||||
is List<*> -> {
|
||||
actions as List<Action>
|
||||
}
|
||||
else -> {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
printer("\t[$transactionNumber]")
|
||||
for (action in actions) {
|
||||
for (action in actionList) {
|
||||
printer("\t\t- $action")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user