From d3dac701eba6a44000f5d7fdb697cddebde4fee1 Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Mon, 22 Apr 2024 19:57:42 +0200 Subject: [PATCH] Dependency updates + JAVA NIO API (#94) --- README.md | 2 +- build.gradle.kts | 8 ++-- examples/kim-java-sample/build.gradle | 2 +- .../kim-kotlin-jvm-sample/build.gradle.kts | 2 +- .../{Kim.android.kt => android/KimAndroid.kt} | 40 ++++++++++++++----- .../kim/apple/{Kim.apple.kt => KimApple.kt} | 0 .../kotlin/com/ashampoo/kim/jvm/KimJvm.kt | 20 +++++++++- .../kim/ktor/{Kim.ktor.kt => KimKtor.kt} | 0 8 files changed, 57 insertions(+), 17 deletions(-) rename src/androidMain/kotlin/com/ashampoo/kim/{Kim.android.kt => android/KimAndroid.kt} (53%) rename src/appleMain/kotlin/com/ashampoo/kim/apple/{Kim.apple.kt => KimApple.kt} (100%) rename src/ktorMain/kotlin/com/ashampoo/kim/ktor/{Kim.ktor.kt => KimKtor.kt} (100%) diff --git a/README.md b/README.md index 34dd3c96..dcdbf1ba 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ of Ashampoo Photo Organizer, which, in turn, is driven by user community feedbac ## Installation ``` -implementation("com.ashampoo:kim:0.17.6") +implementation("com.ashampoo:kim:0.17.7") ``` For the targets `wasmJs` & `js` you also need to specify this: diff --git a/build.gradle.kts b/build.gradle.kts index 008bec91..bfdc1259 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,11 +24,11 @@ repositories { val productName = "Ashampoo Kim" -val ktorVersion: String = "2.3.8" +val ktorVersion: String = "2.3.10" val xmpCoreVersion: String = "1.2.2" val dateTimeVersion: String = "0.5.0" val testRessourcesVersion: String = "0.4.0" -val ioCoreVersion: String = "0.3.2" +val kotlinxIoVersion: String = "0.3.3" description = productName group = "com.ashampoo" @@ -203,7 +203,7 @@ kotlin { /* Kotlin Test */ implementation(kotlin("test")) - implementation("org.jetbrains.kotlinx:kotlinx-io-core:$ioCoreVersion") + implementation("org.jetbrains.kotlinx:kotlinx-io-core:$kotlinxIoVersion") } } @@ -256,7 +256,7 @@ kotlin { * * Not available in commonMain due to missing JS browser support. */ - api("org.jetbrains.kotlinx:kotlinx-io-core:$ioCoreVersion") + api("org.jetbrains.kotlinx:kotlinx-io-core:$kotlinxIoVersion") } } diff --git a/examples/kim-java-sample/build.gradle b/examples/kim-java-sample/build.gradle index 410ade11..4dc05d2b 100644 --- a/examples/kim-java-sample/build.gradle +++ b/examples/kim-java-sample/build.gradle @@ -10,7 +10,7 @@ repositories { } dependencies { - implementation 'com.ashampoo:kim:0.17.3' + implementation 'com.ashampoo:kim:0.17.7' } // Needed to make it work for the Gradle java plugin diff --git a/examples/kim-kotlin-jvm-sample/build.gradle.kts b/examples/kim-kotlin-jvm-sample/build.gradle.kts index 8177c2d0..2eedc585 100644 --- a/examples/kim-kotlin-jvm-sample/build.gradle.kts +++ b/examples/kim-kotlin-jvm-sample/build.gradle.kts @@ -10,5 +10,5 @@ repositories { } dependencies { - implementation("com.ashampoo:kim:0.17.3") + implementation("com.ashampoo:kim:0.17.7") } diff --git a/src/androidMain/kotlin/com/ashampoo/kim/Kim.android.kt b/src/androidMain/kotlin/com/ashampoo/kim/android/KimAndroid.kt similarity index 53% rename from src/androidMain/kotlin/com/ashampoo/kim/Kim.android.kt rename to src/androidMain/kotlin/com/ashampoo/kim/android/KimAndroid.kt index 059d3047..605bba68 100644 --- a/src/androidMain/kotlin/com/ashampoo/kim/Kim.android.kt +++ b/src/androidMain/kotlin/com/ashampoo/kim/android/KimAndroid.kt @@ -13,26 +13,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.ashampoo.kim +package com.ashampoo.kim.android +import com.ashampoo.kim.Kim import com.ashampoo.kim.common.ImageReadException import com.ashampoo.kim.format.ImageMetadata import com.ashampoo.kim.input.AndroidInputStreamByteReader import java.io.File import java.io.InputStream +/** + * Extra object to have a nicer API for Java projects + */ +object KimAndroid { + + @JvmStatic + @Throws(ImageReadException::class) + fun readMetadata(inputStream: InputStream, length: Long): ImageMetadata? = + Kim.readMetadata(AndroidInputStreamByteReader(inputStream, length)) + + @JvmStatic + @Throws(ImageReadException::class) + fun readMetadata(path: String): ImageMetadata? = + readMetadata(File(path)) + + @JvmStatic + @Throws(ImageReadException::class) + fun readMetadata(file: File): ImageMetadata? { + + check(file.exists()) { "File does not exist: $file" } + + return readMetadata(file.inputStream().buffered(), file.length()) + } +} + @Throws(ImageReadException::class) fun Kim.readMetadata(inputStream: InputStream, length: Long): ImageMetadata? = - Kim.readMetadata(AndroidInputStreamByteReader(inputStream, length)) + KimAndroid.readMetadata(inputStream, length) @Throws(ImageReadException::class) fun Kim.readMetadata(path: String): ImageMetadata? = - Kim.readMetadata(File(path)) + KimAndroid.readMetadata(path) @Throws(ImageReadException::class) -fun Kim.readMetadata(file: File): ImageMetadata? { - - check(file.exists()) { "File does not exist: $file" } - - return Kim.readMetadata(file.inputStream(), file.length()) -} +fun Kim.readMetadata(file: File): ImageMetadata? = + KimAndroid.readMetadata(file) diff --git a/src/appleMain/kotlin/com/ashampoo/kim/apple/Kim.apple.kt b/src/appleMain/kotlin/com/ashampoo/kim/apple/KimApple.kt similarity index 100% rename from src/appleMain/kotlin/com/ashampoo/kim/apple/Kim.apple.kt rename to src/appleMain/kotlin/com/ashampoo/kim/apple/KimApple.kt diff --git a/src/jvmMain/kotlin/com/ashampoo/kim/jvm/KimJvm.kt b/src/jvmMain/kotlin/com/ashampoo/kim/jvm/KimJvm.kt index b38b91bb..746999ec 100644 --- a/src/jvmMain/kotlin/com/ashampoo/kim/jvm/KimJvm.kt +++ b/src/jvmMain/kotlin/com/ashampoo/kim/jvm/KimJvm.kt @@ -21,6 +21,8 @@ import com.ashampoo.kim.format.ImageMetadata import com.ashampoo.kim.input.JvmInputStreamByteReader import java.io.File import java.io.InputStream +import java.nio.file.Files +import java.nio.file.StandardOpenOption /** * Extra object to have a nicer API for Java projects @@ -43,7 +45,19 @@ object KimJvm { check(file.exists()) { "File does not exist: $file" } - return readMetadata(file.inputStream(), file.length()) + return readMetadata(file.inputStream().buffered(), file.length()) + } + + @JvmStatic + @Throws(ImageReadException::class) + fun readMetadata(path: java.nio.file.Path): ImageMetadata? { + + check(Files.exists(path)) { "File does not exist: $path" } + + return readMetadata( + inputStream = Files.newInputStream(path, StandardOpenOption.READ).buffered(), + length = Files.size(path) + ) } } @@ -58,3 +72,7 @@ fun Kim.readMetadata(path: String): ImageMetadata? = @Throws(ImageReadException::class) fun Kim.readMetadata(file: File): ImageMetadata? = KimJvm.readMetadata(file) + +@Throws(ImageReadException::class) +fun Kim.readMetadata(path: java.nio.file.Path): ImageMetadata? = + KimJvm.readMetadata(path) diff --git a/src/ktorMain/kotlin/com/ashampoo/kim/ktor/Kim.ktor.kt b/src/ktorMain/kotlin/com/ashampoo/kim/ktor/KimKtor.kt similarity index 100% rename from src/ktorMain/kotlin/com/ashampoo/kim/ktor/Kim.ktor.kt rename to src/ktorMain/kotlin/com/ashampoo/kim/ktor/KimKtor.kt