Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.4 KiB
87 lines
2.4 KiB
3 years ago
|
package org.openrs2.cache
|
||
|
|
||
|
import io.netty.buffer.ByteBuf
|
||
3 years ago
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry
|
||
|
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
|
||
3 years ago
|
import java.time.Instant
|
||
3 years ago
|
import java.util.Date
|
||
3 years ago
|
|
||
|
/**
|
||
|
* A specialised [Store] implementation that writes a cache in the
|
||
3 years ago
|
* [FlatFileStore] format to a [TarArchiveOutputStream].
|
||
3 years ago
|
*
|
||
|
* The cache is not buffered to disk.
|
||
|
*
|
||
|
* This implementation only supports the [create] and [write] methods. All
|
||
|
* other methods throw [UnsupportedOperationException].
|
||
|
*
|
||
|
* It is only intended for use by the cache archiving service's web interface.
|
||
|
*/
|
||
3 years ago
|
public class FlatFileStoreTarWriter(
|
||
|
private val out: TarArchiveOutputStream,
|
||
3 years ago
|
private val prefix: String = "cache/",
|
||
|
timestamp: Instant = Instant.EPOCH
|
||
|
) : Store {
|
||
3 years ago
|
private val timestamp = Date.from(timestamp)
|
||
3 years ago
|
|
||
3 years ago
|
private fun createTarEntry(name: String, size: Int): TarArchiveEntry {
|
||
|
val entry = TarArchiveEntry(prefix + name)
|
||
|
entry.modTime = timestamp
|
||
|
entry.size = size.toLong()
|
||
3 years ago
|
return entry
|
||
|
}
|
||
|
|
||
|
override fun exists(archive: Int): Boolean {
|
||
|
throw UnsupportedOperationException()
|
||
|
}
|
||
|
|
||
|
override fun exists(archive: Int, group: Int): Boolean {
|
||
|
throw UnsupportedOperationException()
|
||
|
}
|
||
|
|
||
|
override fun list(): List<Int> {
|
||
|
throw UnsupportedOperationException()
|
||
|
}
|
||
|
|
||
|
override fun list(archive: Int): List<Int> {
|
||
|
throw UnsupportedOperationException()
|
||
|
}
|
||
|
|
||
|
override fun create(archive: Int) {
|
||
|
require(archive in 0..Store.MAX_ARCHIVE)
|
||
|
|
||
3 years ago
|
out.putArchiveEntry(createTarEntry("$archive/", size = 0))
|
||
|
out.closeArchiveEntry()
|
||
3 years ago
|
}
|
||
|
|
||
|
override fun read(archive: Int, group: Int): ByteBuf {
|
||
|
throw UnsupportedOperationException()
|
||
|
}
|
||
|
|
||
|
override fun write(archive: Int, group: Int, buf: ByteBuf) {
|
||
|
require(archive in 0..Store.MAX_ARCHIVE)
|
||
|
require(group >= 0)
|
||
|
require(buf.readableBytes() <= Store.MAX_GROUP_SIZE)
|
||
|
|
||
3 years ago
|
out.putArchiveEntry(createTarEntry("$archive/$group.dat", buf.readableBytes()))
|
||
3 years ago
|
buf.readBytes(out, buf.readableBytes())
|
||
3 years ago
|
out.closeArchiveEntry()
|
||
3 years ago
|
}
|
||
|
|
||
|
override fun remove(archive: Int) {
|
||
|
throw UnsupportedOperationException()
|
||
|
}
|
||
|
|
||
|
override fun remove(archive: Int, group: Int) {
|
||
|
throw UnsupportedOperationException()
|
||
|
}
|
||
|
|
||
|
override fun flush() {
|
||
|
out.flush()
|
||
|
}
|
||
|
|
||
|
override fun close() {
|
||
|
out.close()
|
||
|
}
|
||
|
}
|