Annotate cache methods with default parameters with @JvmOverloads

This allows them to be used from Java.

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

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

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

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

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

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

@ -66,6 +66,7 @@ public data class Js5MasterIndex(
}
}
@JvmOverloads
public fun write(buf: ByteBuf, key: RSAKeyParameters? = null) {
val start = buf.writerIndex()
@ -179,6 +180,7 @@ public data class Js5MasterIndex(
return masterIndex
}
@JvmOverloads
public fun read(buf: ByteBuf, format: MasterIndexFormat, key: RSAKeyParameters? = null): Js5MasterIndex {
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.
* @throws IOException if an underlying I/O error occurs.
*/
@JvmOverloads
public fun open(root: Path, alloc: ByteBufAllocator = ByteBufAllocator.DEFAULT): Store {
val hasDataFile = Files.isRegularFile(DiskStore.dataPath(root))
val hasLegacyDataFile = Files.isRegularFile(DiskStore.legacyDataPath(root))

Loading…
Cancel
Save