diff --git a/build.gradle.kts b/build.gradle.kts index 320d2c8..8bdd691 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils * CurrentFile build.gradle.kts - * LastUpdate 2026-10-28 21:50:32 + * LastUpdate 2026-11-17 09:21:51 * UpdateUser MingLiPro */ @@ -24,16 +24,16 @@ import java.time.LocalDateTime import java.time.format.DateTimeFormatter plugins { - idea - java - signing - `java-library` - `maven-publish` - kotlin("jvm") version "2.2.20" - kotlin("kapt") version "2.2.20" - id("org.jetbrains.dokka") version "2.1.0" - id("org.jetbrains.dokka-javadoc") version "2.1.0" - kotlin("plugin.spring") version "2.1.0" + idea + java + signing + `java-library` + `maven-publish` + kotlin("jvm") version "2.2.20" + kotlin("kapt") version "2.2.20" + id("org.jetbrains.dokka") version "2.1.0" + id("org.jetbrains.dokka-javadoc") version "2.1.0" + kotlin("plugin.spring") version "2.1.0" } val GROUPSID = project.properties["GROUPSID"] as String val VERSIONS = project.properties["VERSIONS"] as String @@ -45,205 +45,204 @@ group = GROUPSID version = VERSIONS base { - archivesName.set(ARTIFACTID) + archivesName.set(ARTIFACTID) } val buildDir: java.nio.file.Path = File("build").toPath() java { - toolchain.languageVersion.set(JavaLanguageVersion.of(JDKVERSIONS)) - withSourcesJar() + toolchain.languageVersion.set(JavaLanguageVersion.of(JDKVERSIONS)) + withSourcesJar() } kotlin { - jvmToolchain(JDKVERSIONS) + jvmToolchain(JDKVERSIONS) } repositories { - mavenLocal() - maven { - url = uri("https://maven.mingliqiye.com/") - } - mavenCentral() + mavenLocal() + maven { + url = uri("https://maven.mingliqiye.com/") + } + mavenCentral() } dependencies { - implementation("org.slf4j:slf4j-api:2.0.17") - implementation(kotlin("reflect")) - api("com.mingliqiye.utils.aliasfor:alias-for:1.0.1") - compileOnly("org.mindrot:jbcrypt:0.4") - compileOnly("com.squareup.okhttp3:okhttp:5.3.2") - compileOnly("com.fasterxml.jackson.core:jackson-databind:2.21.0") - compileOnly("com.fasterxml.jackson.module:jackson-module-kotlin:2.21.0") - compileOnly("org.springframework:spring-context:5.3.0") - compileOnly("org.springframework.boot:spring-boot-autoconfigure:2.7.16") - compileOnly("tools.jackson.core:jackson-databind:3.1.0") - compileOnly(fileTree("libs")) - compileOnly("com.google.code.gson:gson:2.13.2") - compileOnly("org.mybatis:mybatis:3.5.19") - compileOnly("io.netty:netty-all:4.2.15.Final") - compileOnly("com.baomidou:mybatis-plus-core:3.5.15") - compileOnly("net.java.dev.jna:jna:5.17.0") - compileOnly("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8") - compileOnly("com.baomidou:mybatis-plus-extension:3.5.15") - compileOnly("com.baomidou:mybatis-plus-jsqlparser:3.5.15") - compileOnly("com.baomidou:mybatis-plus-spring:3.5.9") - testImplementation("org.junit.jupiter:junit-jupiter:5.7.1") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") - testImplementation("com.mingliqiye.logger:logger-log4j2:1.0.9") - testImplementation("com.google.code.gson:gson:2.13.2") + implementation("org.slf4j:slf4j-api:2.0.17") + implementation(kotlin("reflect")) + api("com.mingliqiye.utils.aliasfor:alias-for:1.0.1") + compileOnly("org.mindrot:jbcrypt:0.4") + compileOnly("com.squareup.okhttp3:okhttp:5.3.2") + compileOnly("com.fasterxml.jackson.core:jackson-databind:2.21.0") + compileOnly("com.fasterxml.jackson.module:jackson-module-kotlin:2.21.0") + compileOnly("org.springframework:spring-context:5.3.0") + compileOnly("org.springframework.boot:spring-boot-autoconfigure:2.7.16") + compileOnly("tools.jackson.core:jackson-databind:3.1.0") + compileOnly(fileTree("libs")) + compileOnly("com.google.code.gson:gson:2.13.2") + compileOnly("org.mybatis:mybatis:3.5.19") + compileOnly("io.netty:netty-all:4.2.15.Final") + compileOnly("com.baomidou:mybatis-plus-core:3.5.15") + compileOnly("net.java.dev.jna:jna:5.17.0") + compileOnly("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8") + compileOnly("com.baomidou:mybatis-plus-extension:3.5.15") + compileOnly("com.baomidou:mybatis-plus-jsqlparser:3.5.15") + compileOnly("com.baomidou:mybatis-plus-spring:3.5.9") + testImplementation("org.junit.jupiter:junit-jupiter:5.7.1") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") + testImplementation("com.mingliqiye.logger:logger-log4j2:1.0.9") + testImplementation("com.google.code.gson:gson:2.13.2") - testImplementation("com.fasterxml.jackson.core:jackson-databind:2.21.0") - testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.21.0") + testImplementation("com.fasterxml.jackson.core:jackson-databind:2.21.0") + testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.21.0") - testImplementation("tools.jackson.module:jackson-module-kotlin:3.1.0") - testImplementation("tools.jackson.core:jackson-databind:3.1.0") - testImplementation(kotlin("test")) + testImplementation("tools.jackson.module:jackson-module-kotlin:3.1.0") + testImplementation("tools.jackson.core:jackson-databind:3.1.0") + testImplementation(kotlin("test")) } repositories { - mavenLocal() + mavenLocal() } tasks.withType().configureEach { - options.encoding = "UTF-8" + options.encoding = "UTF-8" } tasks.named("test") { - useJUnitPlatform() + useJUnitPlatform() } tasks.withType { - jvmArgs( - "-Dfile.encoding=UTF-8", "-Dsun.stdout.encoding=UTF-8", "-Dsun.stderr.encoding=UTF-8" - ) + jvmArgs( + "-Dfile.encoding=UTF-8", "-Dsun.stdout.encoding=UTF-8", "-Dsun.stderr.encoding=UTF-8" + ) } kapt { - arguments { - arg( - "kapt.kotlin.generated", - project.layout.buildDirectory.dir("generated/source/kapt/main").get().asFile.absolutePath - ) - } + arguments { + arg( + "kapt.kotlin.generated", + project.layout.buildDirectory.dir("generated/source/kapt/main").get().asFile.absolutePath + ) + } } tasks.withType { - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - from("LICENSE") { into("META-INF") } - from("NOTICE") { into("META-INF") } - manifest { - attributes( - mapOf( - "Main-Class" to "com.mingliqiye.utils.main.Main", - "Specification-Title" to ARTIFACTID, - "Specification-Version" to VERSIONS, - "Specification-Vendor" to "minglipro", - "Specification-Build-Time" to LocalDateTime.now() - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSS")), - "Specification-Package" to GROUPSID, - "Specification-Build-Number" to "1", - "Specification-Build-OS" to System.getProperty("os.name"), - "Specification-Build-Java" to System.getProperty("java.version"), - "Specification-Build-Java-Vendor" to System.getProperty("java.vendor"), - "Specification-Build-Java-Vendor-URL" to System.getProperty("java.vendor.url"), - "Implementation-Title" to ARTIFACTID, - "Implementation-Version" to VERSIONS, - "Implementation-Package" to GROUPSID, - "Implementation-Vendor" to "minglipro", - "Implementation-Build-Time" to LocalDateTime.now() - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSS")) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + from("LICENSE") { into("META-INF") } + from("NOTICE") { into("META-INF") } + manifest { + attributes( + mapOf( + "Main-Class" to "com.mingliqiye.utils.main.Main", + "Specification-Title" to ARTIFACTID, + "Specification-Version" to VERSIONS, + "Specification-Vendor" to "minglipro", + "Specification-Build-Time" to LocalDateTime.now() + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSS")), + "Specification-Package" to GROUPSID, + "Specification-Build-Number" to "1", + "Specification-Build-OS" to System.getProperty("os.name"), + "Specification-Build-Java" to System.getProperty("java.version"), + "Specification-Build-Java-Vendor" to System.getProperty("java.vendor"), + "Specification-Build-Java-Vendor-URL" to System.getProperty("java.vendor.url"), + "Implementation-Title" to ARTIFACTID, + "Implementation-Version" to VERSIONS, + "Implementation-Package" to GROUPSID, + "Implementation-Vendor" to "minglipro", + "Implementation-Build-Time" to LocalDateTime.now() + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSS")) - ) - ) - } + ) + ) + } } val isJdk8Build = project.findProperty("buildForJdk8") == "true" -tasks.register("javaDocJar") { - group = "build" - archiveClassifier.set("javadoc-dec") - dependsOn("dokkaGeneratePublicationJavadoc") - from(buildDir.resolve("dokka/javadoc")) + +dokka { + pluginsConfiguration.html { + customAssets.from("logo.png") + } } + +tasks.register("javaDocJar") { + group = "build" + archiveClassifier.set("javadoc") + dependsOn("dokkaGenerateJavadoc") + from(buildDir.resolve("dokka/javadoc")) +} + tasks.register("kotlinDocJar") { - group = "build" - archiveClassifier.set("javadoc") - dependsOn("dokkaGeneratePublicationHtml") - from(buildDir.resolve("dokka/html")) + group = "build" + archiveClassifier.set("kotlindoc") + dependsOn("dokkaGeneratePublicationHtml") + from(buildDir.resolve("dokka/html")) } publishing { - repositories { - maven { - name = "mingliqiye" - url = uri("https://repository.mingliqiye.com/repository/maven") - credentials { - username = System.getenv("mingliqiye.username") - password = System.getenv("mingliqiye.password") - } - } - } - publications { - create("mavenJava") { - from(components["java"]) - artifact(tasks.named("kotlinDocJar")) - artifactId = ARTIFACTID - pom { - name = "mingli-utils" - url = "https://mingli-utils.mingliqiye.com" - description = "A Java/kotlin Utils" - licenses { - license { - name = "The Apache License, Version 2.0" - url = "http://www.apache.org/licenses/LICENSE-2.0.txt" - } - } - developers { - developer { - id = "minglipro" - name = "mingli" - email = "minglipro@163.com" - } - } - scm { - connection = "scm:git:https://git.mingliqiye.com/minglipro/mingli-utils.git" - developerConnection = "scm:git:https://git.mingliqiye.com:minglipro/mingli-utils.git" - url = "https://git.mingliqiye.com/minglipro/mingli-utils" - } - } - } - } - signing { - sign(publishing.publications) - } + publications { + create("mavenJava") { + from(components["java"]) + artifact(tasks.named("javaDocJar")) + artifact(tasks.named("kotlinDocJar")) + artifactId = ARTIFACTID + pom { + name = "mingli-utils" + url = "https://mingli-utils.mingliqiye.com" + description = "A Java/kotlin Utils" + licenses { + license { + name = "The Apache License, Version 2.0" + url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + } + } + developers { + developer { + id = "minglipro" + name = "mingli" + email = "minglipro@163.com" + } + } + scm { + connection = "scm:git:https://git.mingliqiye.com/minglipro/mingli-utils.git" + developerConnection = "scm:git:https://git.mingliqiye.com:minglipro/mingli-utils.git" + url = "https://git.mingliqiye.com/minglipro/mingli-utils" + } + } + } + } + signing { + sign(publishing.publications) + } } tasks.build { - dependsOn("javaDocJar", "kotlinDocJar") + dependsOn("javaDocJar", "kotlinDocJar") } tasks.processResources { - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - outputs.upToDateWhen { false } - filesMatching(listOf("META-INF/meta-data", "fabric.mod.json")) { - expand( - project.properties + mapOf( - "buildTime" to LocalDateTime.now().format( - DateTimeFormatter.ofPattern( - "yyyy-MM-dd HH:mm:ss.SSSSSSS" - ) - ) - ) - ) - } + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + outputs.upToDateWhen { false } + filesMatching(listOf("META-INF/meta-data", "fabric.mod.json")) { + expand( + project.properties + mapOf( + "buildTime" to LocalDateTime.now().format( + DateTimeFormatter.ofPattern( + "yyyy-MM-dd HH:mm:ss.SSSSSSS" + ) + ) + ) + ) + } } signing { - val secretKeyRingFile = System.getenv("SIGNING_SECRET_KEY_RING_FILE") - val keyId = System.getenv("SIGNING_KEY_ID") - useGpgCmd() - project.ext.set("signing.secretKeyRingFile", secretKeyRingFile) - project.ext.set("signing.keyId", keyId) - project.ext.set("signing.password", "") + val secretKeyRingFile = System.getenv("SIGNING_SECRET_KEY_RING_FILE") + val keyId = System.getenv("SIGNING_KEY_ID") + useGpgCmd() + project.ext.set("signing.secretKeyRingFile", secretKeyRingFile) + project.ext.set("signing.keyId", keyId) + project.ext.set("signing.password", "") } diff --git a/gradle.properties b/gradle.properties index 4f2bef2..a6e567d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,10 +16,10 @@ # ProjectName mingli-utils # ModuleName mingli-utils # CurrentFile gradle.properties -# LastUpdate 2026-11-09 19:49:52 +# LastUpdate 2026-11-17 09:07:20 # UpdateUser MingLiPro # JDKVERSIONS=17 GROUPSID=com.mingliqiye.utils ARTIFACTID=mingli-utils -VERSIONS=5.4.3 +VERSIONS=5.4.4 diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..af567d4 Binary files /dev/null and b/logo.png differ diff --git a/src/main/kotlin/com/mingliqiye/utils/base/Base64NoPaddingCodec.kt b/src/main/kotlin/com/mingliqiye/utils/base/Base64NoPaddingCodec.kt new file mode 100644 index 0000000..17d586f --- /dev/null +++ b/src/main/kotlin/com/mingliqiye/utils/base/Base64NoPaddingCodec.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2026 mingliqiye + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ProjectName mingli-utils + * ModuleName mingli-utils.main + * CurrentFile Base64NoPaddingCodec.kt + * LastUpdate 2026-11-16 14:24:59 + * UpdateUser MingLiPro + */ + +package com.mingliqiye.utils.base + +import java.util.* + +internal class Base64NoPaddingCodec : BaseCodec { + + /* + * Base64编码器实例 + * 用于执行字节数组到Base64字符串的编码操作 + */ + val encoder: Base64.Encoder = Base64.getUrlEncoder().withoutPadding() + + /* + * Base64解码器实例 + * 用于执行Base64字符串到字节数组的解码操作 + */ + val decoder: Base64.Decoder = Base64.getUrlDecoder() + + /* + * 将字节数组编码为Base64字符串 + * + * @param bytes 待编码的字节数组 + * @return 编码后的Base64字符串 + */ + override fun encode(bytes: ByteArray): String { + return encoder.encodeToString(bytes) + } + + /* + * 将Base64字符串解码为字节数组 + * + * @param string 待解码的Base64字符串 + * @return 解码后的字节数组 + */ + override fun decode(string: String): ByteArray { + return decoder.decode(string) + } +} diff --git a/src/main/kotlin/com/mingliqiye/utils/base/Base64UrlCodec.kt b/src/main/kotlin/com/mingliqiye/utils/base/Base64UrlCodec.kt index 63dbc82..b5bd899 100644 --- a/src/main/kotlin/com/mingliqiye/utils/base/Base64UrlCodec.kt +++ b/src/main/kotlin/com/mingliqiye/utils/base/Base64UrlCodec.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile Base64UrlCodec.kt - * LastUpdate 2026-03-12 10:34:36 + * LastUpdate 2026-11-16 14:24:59 * UpdateUser MingLiPro */ diff --git a/src/main/kotlin/com/mingliqiye/utils/base/BaseType.kt b/src/main/kotlin/com/mingliqiye/utils/base/BaseType.kt index 06e71be..573f14a 100644 --- a/src/main/kotlin/com/mingliqiye/utils/base/BaseType.kt +++ b/src/main/kotlin/com/mingliqiye/utils/base/BaseType.kt @@ -16,23 +16,36 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile BaseType.kt - * LastUpdate 2026-03-12 10:08:42 + * LastUpdate 2026-11-16 14:21:51 * UpdateUser MingLiPro */ package com.mingliqiye.utils.base -enum class BaseType(val baseCodec: BaseCodec) : BaseCodec { +import com.mingliqiye.utils.base.code.BASE10 as CODE_BASE10 +import com.mingliqiye.utils.base.code.BASE16 as CODE_BASE16 +import com.mingliqiye.utils.base.code.BASE2 as CODE_BASE2 +import com.mingliqiye.utils.base.code.BASE256 as CODE_BASE256 +import com.mingliqiye.utils.base.code.BASE64 as CODE_BASE64 +import com.mingliqiye.utils.base.code.BASE64_NO_PADDING as CODE_BASE64_NO_PADDING +import com.mingliqiye.utils.base.code.BASE64_URL as CODE_BASE64_URL +import com.mingliqiye.utils.base.code.BASE91 as CODE_BASE91 - BASE2(com.mingliqiye.utils.base.code.BASE2), - BASE10(com.mingliqiye.utils.base.code.BASE10), - BASE16(com.mingliqiye.utils.base.code.BASE16), - BASE64(com.mingliqiye.utils.base.code.BASE64), - BASE64URL(com.mingliqiye.utils.base.code.BASE64URL), - BASE91(com.mingliqiye.utils.base.code.BASE91), - BASE256(com.mingliqiye.utils.base.code.BASE256); +enum class BaseType(private val baseCodec: () -> BaseCodec) : BaseCodec { - override fun encode(bytes: ByteArray) = baseCodec.encode(bytes) - override fun decode(string: String) = baseCodec.decode(string) + BASE2(::CODE_BASE2), + BASE10(::CODE_BASE10), + BASE16(::CODE_BASE16), + BASE64(::CODE_BASE64), + BASE64_URL(::CODE_BASE64_URL), + BASE64_NO_PADDING(::CODE_BASE64_NO_PADDING), + BASE91(::CODE_BASE91), + BASE256(::CODE_BASE256); + + val codec + get() = baseCodec() + + override fun encode(bytes: ByteArray) = codec.encode(bytes) + override fun decode(string: String) = codec.decode(string) } diff --git a/src/main/kotlin/com/mingliqiye/utils/base/code/BaseCodes.kt b/src/main/kotlin/com/mingliqiye/utils/base/code/BaseCodes.kt index e3b8923..74f1ec5 100644 --- a/src/main/kotlin/com/mingliqiye/utils/base/code/BaseCodes.kt +++ b/src/main/kotlin/com/mingliqiye/utils/base/code/BaseCodes.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile BaseCodes.kt - * LastUpdate 2026-03-12 10:03:32 + * LastUpdate 2026-11-16 14:10:57 * UpdateUser MingLiPro */ @@ -63,10 +63,16 @@ val BASE64: BaseCodec by lazy { } @get:JvmName("base64Url") -val BASE64URL: BaseCodec by lazy { +val BASE64_URL: BaseCodec by lazy { Base64UrlCodec() } +@get:JvmName("base64NoPadding") +val BASE64_NO_PADDING: BaseCodec by lazy { + Base64NoPaddingCodec() +} + + /** * 提供Base91编码器的懒加载实例。 * 该编码器用于将数据编码为Base91格式,具有较高的压缩效率。 diff --git a/src/main/kotlin/com/mingliqiye/utils/bytes/ByteFlags.kt b/src/main/kotlin/com/mingliqiye/utils/bytes/ByteFlags.kt index 1c2aa26..825dc10 100644 --- a/src/main/kotlin/com/mingliqiye/utils/bytes/ByteFlags.kt +++ b/src/main/kotlin/com/mingliqiye/utils/bytes/ByteFlags.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile ByteFlags.kt - * LastUpdate 2026-06-21 10:40:58 + * LastUpdate 2026-11-16 21:35:04 * UpdateUser MingLiPro */ @@ -64,7 +64,7 @@ data class ByteFlags( * * @param byte 要解析的字节 */ - fun fromByte(byte: Byte) { + fun fromByte(byte: Byte): ByteFlags { val value = byte.toInt() and 0xFF b0 = (value and 0x01) != 0 b1 = (value and 0x02) != 0 @@ -74,6 +74,7 @@ data class ByteFlags( b5 = (value and 0x20) != 0 b6 = (value and 0x40) != 0 b7 = (value and 0x80) != 0 + return this } /** @@ -122,7 +123,7 @@ data class ByteFlags( * @param value 要设置的布尔值 * @throws IndexOutOfBoundsException 如果索引不在 0~7 范围内 */ - operator fun set(index: Int, value: Boolean) { + operator fun set(index: Int, value: Boolean): ByteFlags { when (index) { 0 -> b0 = value 1 -> b1 = value @@ -134,12 +135,13 @@ data class ByteFlags( 7 -> b7 = value else -> throw IndexOutOfBoundsException("索引必须在0-7之间") } + return this } /** * 将所有 8 个位设置为 `true`。 */ - fun setAll() { + fun setAll(): ByteFlags { b0 = true b1 = true b2 = true @@ -148,12 +150,14 @@ data class ByteFlags( b5 = true b6 = true b7 = true + + return this } /** * 将所有 8 个位设置为 `false`。 */ - fun clearAll() { + fun clearAll(): ByteFlags { b0 = false b1 = false b2 = false @@ -162,12 +166,14 @@ data class ByteFlags( b5 = false b6 = false b7 = false + + return this } /** * 对所有位执行逻辑取反(true ↔ false)。 */ - fun toggleAll() { + fun toggleAll(): ByteFlags { b0 = !b0 b1 = !b1 b2 = !b2 @@ -176,6 +182,8 @@ data class ByteFlags( b5 = !b5 b6 = !b6 b7 = !b7 + + return this } /** @@ -184,8 +192,9 @@ data class ByteFlags( * @param index 要切换的位索引(0~7) * @throws IndexOutOfBoundsException 如果索引无效 */ - fun toggle(index: Int) { + fun toggle(index: Int): ByteFlags { this[index] = !this[index] + return this } /** @@ -304,7 +313,7 @@ data class ByteFlags( * @param array 布尔数组(长度至少为 8) * @throws IllegalArgumentException 如果数组长度不足 8 */ - fun fromBooleanArray(array: BooleanArray) { + fun fromBooleanArray(array: BooleanArray): ByteFlags { require(array.size >= 8) { "数组长度至少为8" } b0 = array[0] b1 = array[1] @@ -314,6 +323,7 @@ data class ByteFlags( b5 = array[5] b6 = array[6] b7 = array[7] + return this } /** @@ -434,7 +444,6 @@ data class ByteFlags( fun fromBinaryString(binary: String): ByteFlags { require(binary.length == 8) { "二进制字符串长度必须为8" } require(binary.all { it == '0' || it == '1' }) { "二进制字符串只能包含0和1" } - return ByteFlags( binary[7] == '1', // b0 是最低位(对应字符串最后一位) binary[6] == '1', @@ -447,6 +456,10 @@ data class ByteFlags( ) } + fun fromBooleanArray(booleanArray: BooleanArray): ByteFlags { + return ByteFlags().fromBooleanArray(booleanArray) + } + /** * 从整数创建 [ByteFlags] 实例(仅使用低 8 位)。 * diff --git a/src/main/kotlin/com/mingliqiye/utils/logger/MingLiLogger.kt b/src/main/kotlin/com/mingliqiye/utils/logger/MingLiLogger.kt index 9391a37..af52f5e 100644 --- a/src/main/kotlin/com/mingliqiye/utils/logger/MingLiLogger.kt +++ b/src/main/kotlin/com/mingliqiye/utils/logger/MingLiLogger.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile MingLiLogger.kt - * LastUpdate 2026-02-06 08:27:44 + * LastUpdate 2026-11-16 11:35:40 * UpdateUser MingLiPro */ @@ -24,6 +24,7 @@ package com.mingliqiye.utils.logger import org.slf4j.Logger import org.slf4j.Marker +import org.slf4j.helpers.MessageFormatter class MingLiLogger(private val name: String) : Logger { override fun getName(): String { @@ -40,14 +41,14 @@ class MingLiLogger(private val name: String) : Logger { override fun trace(format: String?, arg: Any?) { format?.let { - val message = format1(it, arg) + val message = format(it, arg) toPrintln(message, MingLiLoggerLevel.TRACE) } } override fun trace(format: String?, arg1: Any?, arg2: Any?) { format?.let { - val message = format2(it, arg1, arg2) + val message = format(it, arg1, arg2) toPrintln(message, MingLiLoggerLevel.TRACE) } } @@ -100,14 +101,14 @@ class MingLiLogger(private val name: String) : Logger { override fun debug(format: String?, arg: Any?) { format?.let { - val message = format1(it, arg) + val message = format(it, arg) toPrintln(message, MingLiLoggerLevel.DEBUG) } } override fun debug(format: String?, arg1: Any?, arg2: Any?) { format?.let { - val message = format2(it, arg1, arg2) + val message = format(it, arg1, arg2) toPrintln(message, MingLiLoggerLevel.DEBUG) } } @@ -160,14 +161,14 @@ class MingLiLogger(private val name: String) : Logger { override fun info(format: String?, arg: Any?) { format?.let { - val message = format1(it, arg) + val message = format(it, arg) toPrintln(message, MingLiLoggerLevel.INFO) } } override fun info(format: String?, arg1: Any?, arg2: Any?) { format?.let { - val message = format2(it, arg1, arg2) + val message = format(it, arg1, arg2) toPrintln(message, MingLiLoggerLevel.INFO) } } @@ -220,7 +221,7 @@ class MingLiLogger(private val name: String) : Logger { override fun warn(format: String?, arg: Any?) { format?.let { - val message = format1(it, arg) + val message = format(it, arg) toPrintln(message, MingLiLoggerLevel.WARN) } } @@ -234,7 +235,7 @@ class MingLiLogger(private val name: String) : Logger { override fun warn(format: String?, arg1: Any?, arg2: Any?) { format?.let { - val message = format2(it, arg1, arg2) + val message = format(it, arg1, arg2) toPrintln(message, MingLiLoggerLevel.WARN) } } @@ -280,14 +281,14 @@ class MingLiLogger(private val name: String) : Logger { override fun error(format: String?, arg: Any?) { format?.let { - val message = format1(it, arg) + val message = format(it, arg) toPrintln(message, MingLiLoggerLevel.ERROR) } } override fun error(format: String?, arg1: Any?, arg2: Any?) { format?.let { - val message = format2(it, arg1, arg2) + val message = format(it, arg1, arg2) toPrintln(message, MingLiLoggerLevel.ERROR) } } @@ -343,24 +344,14 @@ class MingLiLogger(private val name: String) : Logger { System.out.write(string.toByteArray()) } - private fun format1(format: String, arg: Any?): String { - return if (format.contains("{}")) { - format.replaceFirst("{}", arg?.toString() ?: "null") - } else { - "$format $arg" - } - } - - private fun format2(format: String, arg1: Any?, arg2: Any?): String { - return format.replaceFirst("{}", arg1?.toString() ?: "null") - .replaceFirst("{}", arg2?.toString() ?: "null") + private fun format(format: String, vararg args: Any?): String { + return formatArray(format, args) } private fun formatArray(format: String, arguments: Array): String { - var result = format - for (arg in arguments) { - result = result.replaceFirst("{}", arg?.toString() ?: "null") - } - return result + return MessageFormatter.arrayFormat( + format, + arguments + ).message } } diff --git a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JSONAAutoConfiguration.kt b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JSONAAutoConfiguration.kt index f3e710a..7322403 100644 --- a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JSONAAutoConfiguration.kt +++ b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JSONAAutoConfiguration.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile JSONAAutoConfiguration.kt - * LastUpdate 2026-11-09 14:59:49 + * LastUpdate 2026-11-16 11:28:52 * UpdateUser MingLiPro */ @@ -41,9 +41,7 @@ open class JSONAAutoConfiguration( init { JSONA.setJsonApi(jsonApi) log.info( - "JSONA use ${ - jsonApi.javaClass - }" + "JSONA use {}", jsonApi.javaClass ) } } diff --git a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Jackson3AutoConfiguration.kt b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Jackson3AutoConfiguration.kt index c73e8d4..35c50e0 100644 --- a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Jackson3AutoConfiguration.kt +++ b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Jackson3AutoConfiguration.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile Jackson3AutoConfiguration.kt - * LastUpdate 2026-11-09 14:18:45 + * LastUpdate 2026-11-17 10:16:38 * UpdateUser MingLiPro */ @@ -39,8 +39,8 @@ open class Jackson3AutoConfiguration { private val log = MingLiLoggerFactory.getLogger() - @Bean("UUIDJsonConverterJsonMapperCustomizer") - @ConditionalOnMissingBean(name = ["UUIDJsonConverterJsonMapperCustomizer"]) + @Bean("jackson3MapperBuilderCustomizer") + @ConditionalOnMissingBean(name = ["jackson3MapperBuilderCustomizer"]) fun jsonMapperBuilderCustomizer(builders: ObjectProvider): JsonMapperBuilderCustomizer { val builderList = builders.orderedStream().toList() var jacksonJsonBuilderImpl = JacksonJsonBuilderImpl() @@ -52,7 +52,7 @@ open class Jackson3AutoConfiguration { it.addModules( *jacksonJsonBuilderImpl.getData().map { converter -> converter.getJackson3Module().also { module -> - log.info("Jackson3 Module Install ${module.moduleName}") + log.debug("Jackson3 Module Install {}", module.moduleName) } }.toTypedArray() ) diff --git a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JacksonJsonAutoConfiguration.kt b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JacksonJsonAutoConfiguration.kt index f58d007..f90642e 100644 --- a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JacksonJsonAutoConfiguration.kt +++ b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/JacksonJsonAutoConfiguration.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile JacksonJsonAutoConfiguration.kt - * LastUpdate 2026-11-09 14:19:05 + * LastUpdate 2026-11-16 23:32:09 * UpdateUser MingLiPro */ @@ -29,6 +29,7 @@ import com.mingliqiye.utils.springboot.autoconfigure.builder.JacksonJsonBuilderI import org.springframework.beans.factory.ObjectProvider import org.springframework.boot.autoconfigure.AutoConfigureAfter import org.springframework.boot.autoconfigure.condition.ConditionalOnClass +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer import org.springframework.context.annotation.Bean @@ -67,7 +68,8 @@ open class JacksonJsonAutoConfiguration { private val log = MingLiLoggerFactory.getLogger() } - @Bean("mingliUtilsJacksonObjectMapperBuilderCustomizer") + @Bean("jacksonMapperBuilderCustomizer") + @ConditionalOnMissingBean(name = ["jacksonMapperBuilderCustomizer"]) fun jackson2ObjectMapperBuilderCustomizer(builders: ObjectProvider): Jackson2ObjectMapperBuilderCustomizer { val builderList = builders.orderedStream().toList() var jacksonJsonBuilderImpl = JacksonJsonBuilderImpl() @@ -78,7 +80,7 @@ open class JacksonJsonAutoConfiguration { builder.modulesToInstall( *jacksonJsonBuilderImpl.getData().map { converter -> converter.getJacksonModule().also { module -> - log.info("Jackson Module Install ${module.moduleName}") + log.debug("Jackson Module Install {}", module.moduleName) } }.toTypedArray() ) diff --git a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Okhttp3AutoConfiguration.kt b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Okhttp3AutoConfiguration.kt index 20467d8..5bd7755 100644 --- a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Okhttp3AutoConfiguration.kt +++ b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/Okhttp3AutoConfiguration.kt @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * ProjectName FastBaseMapper.kt + * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile Okhttp3AutoConfiguration.kt - * LastUpdate 2026-10-26 23:22:18 + * LastUpdate 2026-11-16 11:29:35 * UpdateUser MingLiPro */ @@ -98,7 +98,7 @@ open class Okhttp3AutoConfiguration { b.build() }.also { okhttp = it - log.info("load $connt OkhttpBuilder initialized OkHttpClient successfully") + log.info("load {} OkhttpBuilder initialized OkHttpClient successfully", connt) } } diff --git a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonBuilder.kt b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonBuilder.kt index bfc700c..c9172e8 100644 --- a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonBuilder.kt +++ b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonBuilder.kt @@ -16,38 +16,12 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile JacksonBuilder.kt - * LastUpdate 2026-11-09 14:39:28 + * LastUpdate 2026-11-16 11:36:46 * UpdateUser MingLiPro */ package com.mingliqiye.utils.springboot.autoconfigure.builder -import com.mingliqiye.utils.json.converters.base.JsonConverter - -sealed class JacksonJsonBuilder { - abstract fun addJsonConverter(jsonConverter: JsonConverter<*, *>): JacksonJsonBuilder - abstract fun addJsonConverters(vararg jsonConverters: JsonConverter<*, *>): JacksonJsonBuilder -} - -open class JacksonJsonBuilderImpl : JacksonJsonBuilder() { - override fun addJsonConverter(jsonConverter: JsonConverter<*, *>): JacksonJsonBuilderImpl { - data.add(jsonConverter) - return this - } - - override fun addJsonConverters(vararg jsonConverters: JsonConverter<*, *>): JacksonJsonBuilder { - data.addAll(jsonConverters) - return this - } - - private val data = mutableListOf>() - - fun getData(): List> { - return data.toList() - } - -} - @FunctionalInterface fun interface JacksonBuilder { fun customize(builder: JacksonJsonBuilder): JacksonJsonBuilder diff --git a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonJsonBuilder.kt b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonJsonBuilder.kt new file mode 100644 index 0000000..ba6a102 --- /dev/null +++ b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonJsonBuilder.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2026 mingliqiye + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ProjectName mingli-utils + * ModuleName mingli-utils.main + * CurrentFile JacksonJsonBuilder.kt + * LastUpdate 2026-11-16 11:36:46 + * UpdateUser MingLiPro + */ + +package com.mingliqiye.utils.springboot.autoconfigure.builder + +import com.mingliqiye.utils.json.converters.base.JsonConverter + +sealed class JacksonJsonBuilder { + abstract fun addJsonConverter(jsonConverter: JsonConverter<*, *>): JacksonJsonBuilder + abstract fun addJsonConverters(vararg jsonConverters: JsonConverter<*, *>): JacksonJsonBuilder +} diff --git a/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonJsonBuilderImpl.kt b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonJsonBuilderImpl.kt new file mode 100644 index 0000000..71bf6b6 --- /dev/null +++ b/src/main/kotlin/com/mingliqiye/utils/springboot/autoconfigure/builder/JacksonJsonBuilderImpl.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2026 mingliqiye + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ProjectName mingli-utils + * ModuleName mingli-utils.main + * CurrentFile JacksonJsonBuilderImpl.kt + * LastUpdate 2026-11-16 11:36:46 + * UpdateUser MingLiPro + */ + +package com.mingliqiye.utils.springboot.autoconfigure.builder + +import com.mingliqiye.utils.json.converters.base.JsonConverter + +open class JacksonJsonBuilderImpl : JacksonJsonBuilder() { + override fun addJsonConverter(jsonConverter: JsonConverter<*, *>): JacksonJsonBuilderImpl { + data.add(jsonConverter) + return this + } + + override fun addJsonConverters(vararg jsonConverters: JsonConverter<*, *>): JacksonJsonBuilder { + data.addAll(jsonConverters) + return this + } + + private val data = mutableListOf>() + + fun getData(): List> { + return data.toList() + } + +} diff --git a/src/main/kotlin/com/mingliqiye/utils/time/DateTime.kt b/src/main/kotlin/com/mingliqiye/utils/time/DateTime.kt index 163e23c..27ee885 100644 --- a/src/main/kotlin/com/mingliqiye/utils/time/DateTime.kt +++ b/src/main/kotlin/com/mingliqiye/utils/time/DateTime.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile DateTime.kt - * LastUpdate 2026-03-14 16:12:08 + * LastUpdate 2026-11-17 10:16:38 * UpdateUser MingLiPro */ @@ -543,4 +543,9 @@ class DateTime private constructor( (it.epochSecond * 1000L) + (it.nano / 1_000_000L) } } + + val epochSecond: Long + get() { + return toInstant().epochSecond + } } diff --git a/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt b/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt index 3159cff..77ebfe0 100644 --- a/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt +++ b/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile UUID.kt - * LastUpdate 2026-06-21 10:40:58 + * LastUpdate 2026-11-16 14:29:35 * UpdateUser MingLiPro */ @@ -422,7 +422,7 @@ class UUID : Serializable { } fun of(str: String, base: BaseType): UUID { - return UUID(base.baseCodec.decode(str)) + return UUID(base.codec.decode(str)) } } @@ -552,7 +552,7 @@ class UUID : Serializable { } fun getString(baseType: BaseType): String { - return getString(baseType.baseCodec) + return getString(baseType.codec) } fun getString(baseCodec: BaseCodec): String { diff --git a/src/test/resources/log4j2.xml b/src/test/resources/log4j2.xml new file mode 100644 index 0000000..f7254fa --- /dev/null +++ b/src/test/resources/log4j2.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + +