Skip to content

Commit

Permalink
fix: commonMetadata compilation errors
Browse files Browse the repository at this point in the history
Signed-off-by: Art Shendrik <[email protected]>
  • Loading branch information
amal committed Jun 28, 2024
1 parent d3047f2 commit 7a5ab95
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fluxo.io.rad

import fluxo.io.internal.BasicRad
import fluxo.io.internal.Blocking
import fluxo.io.internal.ThreadSafe
import fluxo.io.util.EMPTY_BYTE_ARRAY
import fluxo.io.util.MAX_BYTE
Expand Down Expand Up @@ -31,7 +32,7 @@ actual constructor(
private val length: Int,
) : BasicRad() {

override val size: Long get() = length.toLong()
actual override val size: Long get() = length.toLong()

init {
checkOffsetAndCount(array.size, offset, length)
Expand All @@ -41,16 +42,19 @@ actual constructor(
override fun asInputStream(): InputStream =
ByteArrayInputStream(array, offset, length)

override fun subsection(position: Long, length: Long): RandomAccessData {
@Blocking
actual override fun subsection(position: Long, length: Long): RandomAccessData {
checkOffsetAndCount(size, position, length)
return ByteArrayRad(array, offset + position.toIntChecked(), length.toInt())
}


override fun readAllBytes(): ByteArray =
@Blocking
actual override fun readAllBytes(): ByteArray =
Arrays.copyOfRange(array, offset, offset + length)

override fun readFrom(position: Long, maxLength: Int): ByteArray {
@Blocking
actual override fun readFrom(position: Long, maxLength: Int): ByteArray {
checkPositionAndMaxLength(size = size, position = position, maxLength = maxLength)
val positionInt = position.toInt()
val len = min(maxLength, length - positionInt)
Expand All @@ -61,7 +65,8 @@ actual constructor(
return Arrays.copyOfRange(array, pos, pos + len)
}

override fun read(buffer: ByteArray, position: Long, offset: Int, maxLength: Int): Int {
@Blocking
actual override fun read(buffer: ByteArray, position: Long, offset: Int, maxLength: Int): Int {
checkPosOffsetAndMaxLength(size, buffer, position, offset, maxLength)
val srcLen = length
if (position >= srcLen) {
Expand All @@ -84,6 +89,7 @@ actual constructor(
array[offset + position.toInt()].toInt() and MAX_BYTE


@Blocking
override fun read(buffer: ByteBuffer, position: Long): Int {
val srcLen = length
if (position < 0L) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fluxo.io.rad

import fluxo.io.internal.BasicRad
import fluxo.io.internal.Blocking
import fluxo.io.internal.ThreadSafe

/**
Expand All @@ -15,4 +16,19 @@ internal expect class ByteArrayRad(
array: ByteArray,
offset: Int,
length: Int,
) : BasicRad
) : BasicRad {

override val size: Long

@Blocking
override fun subsection(position: Long, length: Long): RandomAccessData

@Blocking
override fun readAllBytes(): ByteArray

@Blocking
override fun readFrom(position: Long, maxLength: Int): ByteArray

@Blocking
override fun read(buffer: ByteArray, position: Long, offset: Int, maxLength: Int): Int
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package fluxo.io.rad

import fluxo.io.internal.BasicRad
import fluxo.io.util.EMPTY_BYTE_ARRAY
import fluxo.io.internal.Blocking
import fluxo.io.internal.ThreadSafe
import fluxo.io.util.EMPTY_BYTE_ARRAY
import fluxo.io.util.checkOffsetAndCount
import fluxo.io.util.checkPosOffsetAndMaxLength
import fluxo.io.util.checkPositionAndMaxLength
Expand All @@ -24,23 +25,26 @@ actual constructor(
private val length: Int,
) : BasicRad() {

override val size: Long get() = length.toLong()
actual override val size: Long get() = length.toLong()

init {
checkOffsetAndCount(array.size, offset, length)
}


override fun subsection(position: Long, length: Long): RandomAccessData {
@Blocking
actual override fun subsection(position: Long, length: Long): RandomAccessData {
checkOffsetAndCount(size, position, length)
return ByteArrayRad(array, offset + position.toIntChecked(), length.toInt())
}


override fun readAllBytes(): ByteArray =
@Blocking
actual override fun readAllBytes(): ByteArray =
array.copyOfRange(offset, offset + length)

override fun readFrom(position: Long, maxLength: Int): ByteArray {
@Blocking
actual override fun readFrom(position: Long, maxLength: Int): ByteArray {
checkPositionAndMaxLength(size = size, position = position, maxLength = maxLength)
val positionInt = position.toInt()
val len = min(maxLength, length - positionInt)
Expand All @@ -51,7 +55,8 @@ actual constructor(
return array.copyOfRange(pos, pos + len)
}

override fun read(buffer: ByteArray, position: Long, offset: Int, maxLength: Int): Int {
@Blocking
actual override fun read(buffer: ByteArray, position: Long, offset: Int, maxLength: Int): Int {
checkPosOffsetAndMaxLength(size, buffer, position, offset, maxLength)
val srcLen = length
if (position >= srcLen) {
Expand Down

0 comments on commit 7a5ab95

Please sign in to comment.