-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from fleeksoft/develop
fix build configurations
- Loading branch information
Showing
23 changed files
with
475 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
#Gradle | ||
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" | ||
org.gradle.caching=true | ||
|
||
#Kotlin | ||
kotlin.code.style=official | ||
|
||
#Android | ||
android.useAndroidX=true | ||
android.nonTransitiveRClass=true | ||
kotlin.native.ignoreIncorrectDependencies=true | ||
|
||
isKorlibs = false | ||
# dev, kotlinx, korlibs, okio | ||
# dev will include all modules in project | ||
libBuildType=korlibs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
ksoup-engine-korlibs/src/com/fleeksoft/ksoup/io/SourceReaderAsyncImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package com.fleeksoft.ksoup.io | ||
|
||
import korlibs.io.stream.MarkableSyncInputStream | ||
import korlibs.io.stream.SyncInputStream | ||
import korlibs.io.stream.markable | ||
import korlibs.io.stream.openSync | ||
import korlibs.memory.buildByteArray | ||
import kotlin.math.min | ||
|
||
|
||
class SourceReaderAsyncImpl : SourceReader { | ||
private val stream: MarkableSyncInputStream | ||
private val buffer: KByteBuffer = KByteBuffer(8192) | ||
private var markBuffer: KByteBuffer? = null | ||
private var sourceEmpty = false | ||
|
||
constructor(stream: SyncInputStream) { | ||
this.stream = stream.markable() | ||
} | ||
|
||
constructor(bytes: ByteArray) : this(bytes.openSync()) | ||
|
||
override fun skip(count: Long) { | ||
var skippedBuffer = 0 | ||
if (buffer().available() > 0) { | ||
skippedBuffer = min(buffer().available(), count.toInt()) | ||
buffer().skip(skippedBuffer) | ||
} | ||
if (skippedBuffer < count) { | ||
stream.skip(count.toInt() - skippedBuffer) | ||
} | ||
} | ||
|
||
override fun mark(readLimit: Long) { | ||
markBuffer = buffer.clone() | ||
stream.mark(readLimit.toInt()) | ||
} | ||
|
||
override fun reset() { | ||
markBuffer = null | ||
stream.reset() | ||
} | ||
|
||
private fun MarkableSyncInputStream.safeReadBytes(len: Int): ByteArray { | ||
var i = 0 | ||
return buildByteArray { | ||
while (i < len) { | ||
var byte = this@safeReadBytes.read() | ||
if (byte == -1) byte = this@safeReadBytes.read() | ||
if (byte == -1) { | ||
break | ||
} else { | ||
this.append(byte) | ||
} | ||
i++ | ||
} | ||
} | ||
} | ||
|
||
override fun readBytes(count: Int): ByteArray { | ||
return buildByteArray { | ||
if (buffer().available() > 0) { | ||
append(buffer().readBytes(count)) | ||
buffer().compact() | ||
} | ||
if (!sourceEmpty && this.size < count) { | ||
append(stream.safeReadBytes(count - this.size)) | ||
} | ||
} | ||
} | ||
|
||
override fun read(bytes: ByteArray, offset: Int, length: Int): Int { | ||
val byteArray = readBytes(length) | ||
if (byteArray.isNotEmpty()) { | ||
byteArray.copyInto(bytes, offset, 0, offset + length) | ||
} | ||
return byteArray.size | ||
} | ||
|
||
private fun buffer() = markBuffer ?: buffer | ||
|
||
override fun readAllBytes(): ByteArray { | ||
return buildByteArray { | ||
if (buffer().available() > 0) { | ||
append(buffer().readAll()) | ||
buffer().compact() | ||
} | ||
while (true) { | ||
val byte = stream.read() | ||
if (byte != -1) { | ||
this.append(byte.toByte()) | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun exhausted(): Boolean { | ||
if (buffer().available() > 0) return false | ||
if (sourceEmpty) return true | ||
val len = buffer().size | ||
val bytes = stream.safeReadBytes(len) | ||
if (bytes.size < len) { | ||
sourceEmpty = true | ||
} | ||
buffer().writeBytes(bytes, bytes.size) | ||
return (buffer().available() > 0).not() | ||
} | ||
|
||
override fun close() { | ||
stream.close() | ||
} | ||
|
||
override fun readAtMostTo(sink: KByteBuffer, byteCount: Int): Int { | ||
val bytes = this.readBytes(byteCount) | ||
sink.writeBytes(bytes, bytes.size) | ||
return bytes.size | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
ksoup-engine-korlibs/src@jvmAndAndroid/com/fleeksoft/ksoup/FileSourceJvmHelper.kt
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
ksoup-engine-korlibs/src@jvmAndAndroid/com/fleeksoft/ksoup/JvmKotlinxMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.fleeksoft.ksoup | ||
|
||
import com.fleeksoft.ksoup.io.* | ||
import korlibs.io.file.std.toVfs | ||
import korlibs.io.stream.SyncInputStream | ||
import korlibs.io.stream.toAsync | ||
import korlibs.io.stream.toAsyncStream | ||
import korlibs.io.stream.toSyncInputStream | ||
import java.io.File | ||
import java.io.InputStream | ||
|
||
object JvmKotlinxMapper { | ||
fun jvmFileToFileSource(file: File): FileSource { | ||
return FileSourceImpl(file.toVfs()) | ||
} | ||
|
||
fun jvmInputStreamToSourceReader(inputStream: InputStream): SourceReader { | ||
return SourceReaderImpl(inputStream.readAllBytes()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
ksoup-engine-kotlinx/src@jvmAndAndroid/com/fleeksoft/ksoup/FileSourceJvmHelper.kt
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
ksoup-engine-kotlinx/src@jvmAndAndroid/com/fleeksoft/ksoup/JvmKotlinxMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.fleeksoft.ksoup | ||
|
||
import com.fleeksoft.ksoup.io.FileSource | ||
import com.fleeksoft.ksoup.io.FileSourceImpl | ||
import com.fleeksoft.ksoup.io.SourceReader | ||
import com.fleeksoft.ksoup.io.SourceReaderImpl | ||
import kotlinx.io.asSource | ||
import kotlinx.io.buffered | ||
import java.io.File | ||
import java.io.InputStream | ||
|
||
object JvmKotlinxMapper { | ||
fun jvmFileToFileSource(file: File): FileSource { | ||
return FileSourceImpl(file.absolutePath) | ||
} | ||
fun jvmInputStreamToSourceReader(inputStream: InputStream): SourceReader { | ||
return SourceReaderImpl(inputStream.asSource().buffered()) | ||
} | ||
} |
Oops, something went wrong.