Merge branch 'dev' of https://github.com/hyb1996/NoRootScriptDroid into dev
# Conflicts: # .idea/caches/build_file_checksums.ser
This commit is contained in:
13
common/src/main/java/com/stardust/ext/Common.kt
Normal file
13
common/src/main/java/com/stardust/ext/Common.kt
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.stardust.ext
|
||||
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
|
||||
fun <R, T : KMutableProperty0<R?>> T.ifNull(provider: () -> R): R {
|
||||
val value = this.get()
|
||||
if (value != null) {
|
||||
return value
|
||||
}
|
||||
val newValue = provider()
|
||||
set(newValue)
|
||||
return newValue
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.stardust.io
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class ByteBufferBackedInputStream(private var buf: ByteBuffer) : InputStream() {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun read(): Int {
|
||||
return if (!buf.hasRemaining()) {
|
||||
-1
|
||||
} else buf.get().toInt() and 0xFF
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun read(bytes: ByteArray, off: Int, len: Int): Int {
|
||||
if (!buf.hasRemaining()) {
|
||||
return -1
|
||||
}
|
||||
val read = Math.min(len, available())
|
||||
buf.get(bytes, off, read)
|
||||
buf.position(buf.position() - read)
|
||||
return read
|
||||
}
|
||||
|
||||
override fun available(): Int {
|
||||
return buf.position()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.stardust.io
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
class ByteBufferBackedOutputStream(private var buf: ByteBuffer) : OutputStream() {
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun write(b: Int) {
|
||||
buf.put(b.toByte())
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun write(bytes: ByteArray, off: Int, len: Int) {
|
||||
buf.put(bytes, off, len)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user