Annotate cache methods with default parameters with @JvmOverloads

This allows them to be used from Java.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 3 years ago
parent aa2784a9e6
commit ba75306169
  1. 9
      cache/src/main/kotlin/org/openrs2/cache/Archive.kt
  2. 11
      cache/src/main/kotlin/org/openrs2/cache/Cache.kt
  3. 1
      cache/src/main/kotlin/org/openrs2/cache/DiskStore.kt
  4. 2
      cache/src/main/kotlin/org/openrs2/cache/FlatFileStore.kt
  5. 2
      cache/src/main/kotlin/org/openrs2/cache/JagArchive.kt
  6. 2
      cache/src/main/kotlin/org/openrs2/cache/Js5Compression.kt
  7. 2
      cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndex.kt
  8. 1
      cache/src/main/kotlin/org/openrs2/cache/Store.kt

@ -181,6 +181,7 @@ public abstract class Archive internal constructor(
return listNamed(group.krHashCode()) return listNamed(group.krHashCode())
} }
@JvmOverloads
public fun read(group: Int, file: Int, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun read(group: Int, file: Int, key: XteaKey = XteaKey.ZERO): ByteBuf {
require(group >= 0 && file >= 0) require(group >= 0 && file >= 0)
@ -189,16 +190,19 @@ public abstract class Archive internal constructor(
return unpacked.read(file) return unpacked.read(file)
} }
@JvmOverloads
public fun readNamed(groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun readNamed(groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO): ByteBuf {
val entry = index.getNamed(groupNameHash) ?: throw FileNotFoundException() val entry = index.getNamed(groupNameHash) ?: throw FileNotFoundException()
val unpacked = getUnpacked(entry, key) val unpacked = getUnpacked(entry, key)
return unpacked.readNamed(fileNameHash) return unpacked.readNamed(fileNameHash)
} }
@JvmOverloads
public fun read(group: String, file: String, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun read(group: String, file: String, key: XteaKey = XteaKey.ZERO): ByteBuf {
return readNamed(group.krHashCode(), file.krHashCode(), key) return readNamed(group.krHashCode(), file.krHashCode(), key)
} }
@JvmOverloads
public fun write(group: Int, file: Int, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) { public fun write(group: Int, file: Int, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) {
require(group >= 0 && file >= 0) require(group >= 0 && file >= 0)
@ -209,6 +213,7 @@ public abstract class Archive internal constructor(
dirty = true dirty = true
} }
@JvmOverloads
public fun writeNamed(groupNameHash: Int, fileNameHash: Int, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) { public fun writeNamed(groupNameHash: Int, fileNameHash: Int, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) {
val entry = index.createOrGetNamed(groupNameHash) val entry = index.createOrGetNamed(groupNameHash)
val unpacked = createOrGetUnpacked(entry, key, isOverwritingNamed(entry, fileNameHash)) val unpacked = createOrGetUnpacked(entry, key, isOverwritingNamed(entry, fileNameHash))
@ -218,6 +223,7 @@ public abstract class Archive internal constructor(
index.hasNames = true index.hasNames = true
} }
@JvmOverloads
public fun write(group: String, file: String, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) { public fun write(group: String, file: String, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) {
return writeNamed(group.krHashCode(), file.krHashCode(), buf, key) return writeNamed(group.krHashCode(), file.krHashCode(), buf, key)
} }
@ -244,6 +250,7 @@ public abstract class Archive internal constructor(
return removeNamed(group.krHashCode()) return removeNamed(group.krHashCode())
} }
@JvmOverloads
public fun remove(group: Int, file: Int, key: XteaKey = XteaKey.ZERO) { public fun remove(group: Int, file: Int, key: XteaKey = XteaKey.ZERO) {
require(group >= 0 && file >= 0) require(group >= 0 && file >= 0)
@ -260,6 +267,7 @@ public abstract class Archive internal constructor(
dirty = true dirty = true
} }
@JvmOverloads
public fun removeNamed(groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO) { public fun removeNamed(groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO) {
val entry = index.getNamed(groupNameHash) ?: return val entry = index.getNamed(groupNameHash) ?: return
@ -274,6 +282,7 @@ public abstract class Archive internal constructor(
dirty = true dirty = true
} }
@JvmOverloads
public fun remove(group: String, file: String, key: XteaKey = XteaKey.ZERO) { public fun remove(group: String, file: String, key: XteaKey = XteaKey.ZERO) {
return removeNamed(group.krHashCode(), file.krHashCode(), key) return removeNamed(group.krHashCode(), file.krHashCode(), key)
} }

@ -132,25 +132,30 @@ public class Cache private constructor(
return listNamed(archive, group.krHashCode()) return listNamed(archive, group.krHashCode())
} }
@JvmOverloads
public fun read(archive: Int, group: Int, file: Int, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun read(archive: Int, group: Int, file: Int, key: XteaKey = XteaKey.ZERO): ByteBuf {
checkArchive(archive) checkArchive(archive)
return archives[archive]?.read(group, file, key) ?: throw FileNotFoundException() return archives[archive]?.read(group, file, key) ?: throw FileNotFoundException()
} }
@JvmOverloads
public fun readNamed(archive: Int, groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun readNamed(archive: Int, groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO): ByteBuf {
checkArchive(archive) checkArchive(archive)
return archives[archive]?.readNamed(groupNameHash, fileNameHash, key) ?: throw FileNotFoundException() return archives[archive]?.readNamed(groupNameHash, fileNameHash, key) ?: throw FileNotFoundException()
} }
@JvmOverloads
public fun read(archive: Int, group: String, file: String, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun read(archive: Int, group: String, file: String, key: XteaKey = XteaKey.ZERO): ByteBuf {
return readNamed(archive, group.krHashCode(), file.krHashCode(), key) return readNamed(archive, group.krHashCode(), file.krHashCode(), key)
} }
@JvmOverloads
public fun write(archive: Int, group: Int, file: Int, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) { public fun write(archive: Int, group: Int, file: Int, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) {
checkArchive(archive) checkArchive(archive)
createOrGetArchive(archive).write(group, file, buf, key) createOrGetArchive(archive).write(group, file, buf, key)
} }
@JvmOverloads
public fun writeNamed( public fun writeNamed(
archive: Int, archive: Int,
groupNameHash: Int, groupNameHash: Int,
@ -162,6 +167,7 @@ public class Cache private constructor(
createOrGetArchive(archive).writeNamed(groupNameHash, fileNameHash, buf, key) createOrGetArchive(archive).writeNamed(groupNameHash, fileNameHash, buf, key)
} }
@JvmOverloads
public fun write(archive: Int, group: String, file: String, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) { public fun write(archive: Int, group: String, file: String, buf: ByteBuf, key: XteaKey = XteaKey.ZERO) {
writeNamed(archive, group.krHashCode(), file.krHashCode(), buf, key) writeNamed(archive, group.krHashCode(), file.krHashCode(), buf, key)
} }
@ -195,16 +201,19 @@ public class Cache private constructor(
return removeNamed(archive, group.krHashCode()) return removeNamed(archive, group.krHashCode())
} }
@JvmOverloads
public fun remove(archive: Int, group: Int, file: Int, key: XteaKey = XteaKey.ZERO) { public fun remove(archive: Int, group: Int, file: Int, key: XteaKey = XteaKey.ZERO) {
checkArchive(archive) checkArchive(archive)
archives[archive]?.remove(group, file, key) archives[archive]?.remove(group, file, key)
} }
@JvmOverloads
public fun removeNamed(archive: Int, groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO) { public fun removeNamed(archive: Int, groupNameHash: Int, fileNameHash: Int, key: XteaKey = XteaKey.ZERO) {
checkArchive(archive) checkArchive(archive)
archives[archive]?.removeNamed(groupNameHash, fileNameHash, key) archives[archive]?.removeNamed(groupNameHash, fileNameHash, key)
} }
@JvmOverloads
public fun remove(archive: Int, group: String, file: String, key: XteaKey = XteaKey.ZERO) { public fun remove(archive: Int, group: String, file: String, key: XteaKey = XteaKey.ZERO) {
return removeNamed(archive, group.krHashCode(), file.krHashCode(), key) return removeNamed(archive, group.krHashCode(), file.krHashCode(), key)
} }
@ -240,6 +249,7 @@ public class Cache private constructor(
public companion object { public companion object {
public const val MAX_ARCHIVE: Int = 254 public const val MAX_ARCHIVE: Int = 254
@JvmOverloads
public fun open( public fun open(
root: Path, root: Path,
alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT,
@ -248,6 +258,7 @@ public class Cache private constructor(
return open(Store.open(root, alloc), alloc, unpackedCacheSize) return open(Store.open(root, alloc), alloc, unpackedCacheSize)
} }
@JvmOverloads
public fun open( public fun open(
store: Store, store: Store,
alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT,

@ -500,6 +500,7 @@ public class DiskStore private constructor(
return root.resolve("main_file_cache.idx$archive") return root.resolve("main_file_cache.idx$archive")
} }
@JvmOverloads
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store { public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
val js5DataPath = dataPath(root) val js5DataPath = dataPath(root)
val legacyDataPath = legacyDataPath(root) val legacyDataPath = legacyDataPath(root)

@ -128,6 +128,7 @@ public class FlatFileStore private constructor(
private val GROUP_NAME = Regex("[0-9]+[.]dat") private val GROUP_NAME = Regex("[0-9]+[.]dat")
private const val GROUP_EXTENSION = ".dat" private const val GROUP_EXTENSION = ".dat"
@JvmOverloads
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store { public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
if (!Files.isDirectory(root)) { if (!Files.isDirectory(root)) {
throw FileNotFoundException() throw FileNotFoundException()
@ -136,6 +137,7 @@ public class FlatFileStore private constructor(
return FlatFileStore(root, alloc) return FlatFileStore(root, alloc)
} }
@JvmOverloads
public fun create(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store { public fun create(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
Files.createDirectories(root) Files.createDirectories(root)
return FlatFileStore(root, alloc) return FlatFileStore(root, alloc)

@ -129,6 +129,7 @@ public class JagArchive : Closeable {
* @param alloc the allocator. * @param alloc the allocator.
* @return the compressed archive. * @return the compressed archive.
*/ */
@JvmOverloads
public fun pack(compressedArchive: Boolean, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): ByteBuf { public fun pack(compressedArchive: Boolean, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): ByteBuf {
alloc.buffer().use { output -> alloc.buffer().use { output ->
alloc.buffer().use { uncompressedArchiveBuf -> alloc.buffer().use { uncompressedArchiveBuf ->
@ -189,6 +190,7 @@ public class JagArchive : Closeable {
* @param alloc the allocator. * @param alloc the allocator.
* @return the compressed archive. * @return the compressed archive.
*/ */
@JvmOverloads
public fun packBest(alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): ByteBuf { public fun packBest(alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): ByteBuf {
pack(true, alloc).use { compressedArchive -> pack(true, alloc).use { compressedArchive ->
pack(false, alloc).use { compressedEntries -> pack(false, alloc).use { compressedEntries ->

@ -18,6 +18,7 @@ public object Js5Compression {
private const val LZMA_PB_MAX = 4 private const val LZMA_PB_MAX = 4
private const val LZMA_PRESET_DICT_SIZE_MAX = 1 shl 26 private const val LZMA_PRESET_DICT_SIZE_MAX = 1 shl 26
@JvmOverloads
public fun compress(input: ByteBuf, type: Js5CompressionType, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun compress(input: ByteBuf, type: Js5CompressionType, key: XteaKey = XteaKey.ZERO): ByteBuf {
input.alloc().buffer().use { output -> input.alloc().buffer().use { output ->
output.writeByte(type.ordinal) output.writeByte(type.ordinal)
@ -107,6 +108,7 @@ public object Js5Compression {
} }
} }
@JvmOverloads
public fun uncompress(input: ByteBuf, key: XteaKey = XteaKey.ZERO): ByteBuf { public fun uncompress(input: ByteBuf, key: XteaKey = XteaKey.ZERO): ByteBuf {
if (input.readableBytes() < 5) { if (input.readableBytes() < 5) {
throw IOException("Missing header") throw IOException("Missing header")

@ -66,6 +66,7 @@ public data class Js5MasterIndex(
} }
} }
@JvmOverloads
public fun write(buf: ByteBuf, key: RSAKeyParameters? = null) { public fun write(buf: ByteBuf, key: RSAKeyParameters? = null) {
val start = buf.writerIndex() val start = buf.writerIndex()
@ -179,6 +180,7 @@ public data class Js5MasterIndex(
return masterIndex return masterIndex
} }
@JvmOverloads
public fun read(buf: ByteBuf, format: MasterIndexFormat, key: RSAKeyParameters? = null): Js5MasterIndex { public fun read(buf: ByteBuf, format: MasterIndexFormat, key: RSAKeyParameters? = null): Js5MasterIndex {
return read(buf, format, key, true) return read(buf, format, key, true)
} }

@ -135,6 +135,7 @@ public interface Store : Flushable, Closeable {
* groups read from the [Store] and for temporary internal use. * groups read from the [Store] and for temporary internal use.
* @throws IOException if an underlying I/O error occurs. * @throws IOException if an underlying I/O error occurs.
*/ */
@JvmOverloads
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store { public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
val hasDataFile = Files.isRegularFile(DiskStore.dataPath(root)) val hasDataFile = Files.isRegularFile(DiskStore.dataPath(root))
val hasLegacyDataFile = Files.isRegularFile(DiskStore.legacyDataPath(root)) val hasLegacyDataFile = Files.isRegularFile(DiskStore.legacyDataPath(root))

Loading…
Cancel
Save