diff --git a/src/main/kotlin/com/mingliqiye/utils/Main.kt b/src/main/kotlin/com/mingliqiye/utils/Main.kt index d03155b..a3a47cc 100644 --- a/src/main/kotlin/com/mingliqiye/utils/Main.kt +++ b/src/main/kotlin/com/mingliqiye/utils/Main.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile Main.kt - * LastUpdate 2025-09-17 19:07:01 + * LastUpdate 2025-09-18 14:39:24 * UpdateUser MingLiPro */ @file:JvmName("Main") @@ -24,8 +24,10 @@ package com.mingliqiye.utils import com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration +import com.mingliqiye.utils.uuid.UUID fun main() { AutoConfiguration.printBanner() + println(UUID.getV7().getBase256ShortString()) } diff --git a/src/main/kotlin/com/mingliqiye/utils/base/Base256.kt b/src/main/kotlin/com/mingliqiye/utils/base/Base256.kt new file mode 100644 index 0000000..d9a356f --- /dev/null +++ b/src/main/kotlin/com/mingliqiye/utils/base/Base256.kt @@ -0,0 +1,317 @@ +/* + * Copyright 2025 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 Base256.kt + * LastUpdate 2025-09-18 14:36:40 + * UpdateUser MingLiPro + */ + +package com.mingliqiye.utils.base + +/** + * Base256 字符集 256个 + * + * 256个字符 要字符集的下面复制 + * + * !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~§±×÷←↑→↓⇒⇔∀∃∅∆∇∈∉∋∌∏∑−∓∕∗∘∙√∛∜∞∟∠∣∥∧∨∩∪∫∬∭∮∯∰∱∲∳∴∵∶∷≈≠≡≤≥≦≧≪≫≺≻⊂⊃⊆⊇⊈⊉⊊⊋⊕⊖⊗⊘⊙⊚⊛⊜⊝⊞⊟⊠⊡⊢⊣⊤⊥⊦⊧⊨⊩⊪⊫⊬⊭⊮⊯⋀⋁⋂⋃⋄⋅⋆⋇⋈⋉⋊⋋⋌⋍⋎⋏⋐⋑⋒⋓⋔⋕⋖⋗⋘⋙⋚⋛⋜⋝⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▐░▒▓▔▕▖▗▘▙ + * + */ +class Base256 : BaseCodec { + + companion object { + val code = arrayOf( + '!', + '#', + '$', + '%', + '&', + '(', + ')', + '*', + '+', + ',', + '-', + '.', + '/', + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + ':', + ';', + '<', + '=', + '>', + '?', + '@', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + '[', + ']', + '^', + '_', + '`', + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + 'y', + 'z', + '{', + '|', + '}', + '~', + '§', + '±', + '×', + '÷', + '←', + '↑', + '→', + '↓', + '⇒', + '⇔', + '∀', + '∃', + '∅', + '∆', + '∇', + '∈', + '∉', + '∋', + '∌', + '∏', + '∑', + '−', + '∓', + '∕', + '∗', + '∘', + '∙', + '√', + '∛', + '∜', + '∞', + '∟', + '∠', + '∣', + '∥', + '∧', + '∨', + '∩', + '∪', + '∫', + '∬', + '∭', + '∮', + '∯', + '∰', + '∱', + '∲', + '∳', + '∴', + '∵', + '∶', + '∷', + '≈', + '≠', + '≡', + '≤', + '≥', + '≦', + '≧', + '≪', + '≫', + '≺', + '≻', + '⊂', + '⊃', + '⊆', + '⊇', + '⊈', + '⊉', + '⊊', + '⊋', + '⊕', + '⊖', + '⊗', + '⊘', + '⊙', + '⊚', + '⊛', + '⊜', + '⊝', + '⊞', + '⊟', + '⊠', + '⊡', + '⊢', + '⊣', + '⊤', + '⊥', + '⊦', + '⊧', + '⊨', + '⊩', + '⊪', + '⊫', + '⊬', + '⊭', + '⊮', + '⊯', + '⋀', + '⋁', + '⋂', + '⋃', + '⋄', + '⋅', + '⋆', + '⋇', + '⋈', + '⋉', + '⋊', + '⋋', + '⋌', + '⋍', + '⋎', + '⋏', + '⋐', + '⋑', + '⋒', + '⋓', + '⋔', + '⋕', + '⋖', + '⋗', + '⋘', + '⋙', + '⋚', + '⋛', + '⋜', + '⋝', + '⋞', + '⋟', + '⋠', + '⋡', + '⋢', + '⋣', + '⋤', + '⋥', + '⋦', + '⋧', + '⋨', + '⋩', + '▁', + '▂', + '▃', + '▄', + '▅', + '▆', + '▇', + '█', + '▉', + '▊', + '▋', + '▌', + '▍', + '▎', + '▏', + '▐', + '░', + '▒', + '▓', + '▔', + '▕', + '▖', + '▗', + '▘', + '▙' + ) + val codeMap = code.mapIndexed { index, c -> c to index }.toMap() + } + + override fun encode(bytes: ByteArray): String { + val result = CharArray(bytes.size) + for (i in bytes.indices) { + val unsignedByte = bytes[i].toInt() and 0xFF + result[i] = code[unsignedByte] + } + return String(result) + } + + override fun decode(string: String): ByteArray { + val result = ByteArray(string.length) + for (i in string.indices) { + result[i] = codeMap[string[i]]!!.toByte() + } + return result + } +} + +fun main() { + +} diff --git a/src/main/kotlin/com/mingliqiye/utils/base/Base91.kt b/src/main/kotlin/com/mingliqiye/utils/base/Base91.kt index 4a88e09..342b0cf 100644 --- a/src/main/kotlin/com/mingliqiye/utils/base/Base91.kt +++ b/src/main/kotlin/com/mingliqiye/utils/base/Base91.kt @@ -16,14 +16,12 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile Base91.kt - * LastUpdate 2025-09-17 10:57:36 + * LastUpdate 2025-09-18 14:42:59 * UpdateUser MingLiPro */ package com.mingliqiye.utils.base -import java.util.* - /** * Base91 编解码工具类,用于将字节数组编码为 Base91 字符串,或将 Base91 字符串解码为原始字节数组。 * @@ -49,16 +47,264 @@ class Base91 : BaseCodec { * Base91 解码表,大小为 256,用于快速查找字符对应的数值。 * 初始化时将所有元素设为 -1,表示无效字符;然后根据 ENCODING_TABLE 填充有效字符的索引。 */ - val DECODING_TABLE: IntArray = IntArray(256) - - init { - // 初始化解码表,默认值为 -1 表示该字符不在编码表中 - Arrays.fill(DECODING_TABLE, -1); - // 构建解码映射表 - for (i in 0.. = arrayOf( + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + 62, + 90, + 63, + 64, + 65, + 66, + -1, + 67, + 68, + 69, + 70, + 71, + -1, + 72, + 73, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 81, + -1, + 82, + 83, + 84, + 85, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 86, + 87, + 88, + 89, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + ) } /** @@ -156,3 +402,10 @@ class Base91 : BaseCodec { return buffer.copyOf(index) } } + +fun main() { + val base91 = Base91() + val bytes = "Hello, World!".toByteArray() + val encoded = base91.encode(bytes) + println(encoded) +} diff --git a/src/main/kotlin/com/mingliqiye/utils/base/BaseCodec.kt b/src/main/kotlin/com/mingliqiye/utils/base/BaseCodec.kt index 802be9f..5ef033e 100644 --- a/src/main/kotlin/com/mingliqiye/utils/base/BaseCodec.kt +++ b/src/main/kotlin/com/mingliqiye/utils/base/BaseCodec.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile BaseCodec.kt - * LastUpdate 2025-09-17 10:35:23 + * LastUpdate 2025-09-18 14:07:35 * UpdateUser MingLiPro */ @@ -150,4 +150,24 @@ interface BaseCodec { false } } + + /** + * 将字符串编码为Base64字符串 + * + * @param string 需要编码的字符串 + * @return 编码后的Base64字符串 + */ + fun encode(string: String): String { + return encode(string.toByteArray()) + } + + /** + * 将Base64字符串解码为字符串 + * + * @param string 需要解码的Base64字符串 + * @return 解码后的字符串 + */ + fun decodetoString(string: String): String { + return decode(string).toString(Charsets.UTF_8) + } } diff --git a/src/main/kotlin/com/mingliqiye/utils/base/BaseUtils.kt b/src/main/kotlin/com/mingliqiye/utils/base/BaseUtils.kt index 22c3c0e..5d7a3c3 100644 --- a/src/main/kotlin/com/mingliqiye/utils/base/BaseUtils.kt +++ b/src/main/kotlin/com/mingliqiye/utils/base/BaseUtils.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile BaseUtils.kt - * LastUpdate 2025-09-17 10:54:46 + * LastUpdate 2025-09-18 14:36:40 * UpdateUser MingLiPro */ @@ -51,4 +51,12 @@ val BASE16: BaseCodec by lazy { Base16() } +/** + * Base256编解码器实例 + * 使用懒加载方式初始化Base256编解码器对象 + * 保证线程安全且只在首次访问时创建实例 + */ +val BASE256: BaseCodec by lazy { + Base256() +} diff --git a/src/main/kotlin/com/mingliqiye/utils/bcrypt/BCrypt.kt b/src/main/kotlin/com/mingliqiye/utils/bcrypt/BCrypt.kt index 4a1b559..65e982e 100644 --- a/src/main/kotlin/com/mingliqiye/utils/bcrypt/BCrypt.kt +++ b/src/main/kotlin/com/mingliqiye/utils/bcrypt/BCrypt.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile BCrypt.kt - * LastUpdate 2025-09-17 16:20:30 + * LastUpdate 2025-09-18 09:46:16 * UpdateUser MingLiPro */ diff --git a/src/main/kotlin/com/mingliqiye/utils/logger/Loggers.kt b/src/main/kotlin/com/mingliqiye/utils/logger/Loggers.kt index 4b8cfc6..e75b366 100644 --- a/src/main/kotlin/com/mingliqiye/utils/logger/Loggers.kt +++ b/src/main/kotlin/com/mingliqiye/utils/logger/Loggers.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile Loggers.kt - * LastUpdate 2025-09-15 22:32:50 + * LastUpdate 2025-09-18 09:30:48 * UpdateUser MingLiPro */ @@ -416,6 +416,6 @@ class MingLiLoggerFactory { } } -val mingLiLoggerFactory = MingLiLoggerFactory() +val mingLiLoggerFactory: MingLiLoggerFactory by lazy { MingLiLoggerFactory() } diff --git a/src/main/kotlin/com/mingliqiye/utils/path/OsPath.kt b/src/main/kotlin/com/mingliqiye/utils/path/OsPath.kt index 6140b83..f88d949 100644 --- a/src/main/kotlin/com/mingliqiye/utils/path/OsPath.kt +++ b/src/main/kotlin/com/mingliqiye/utils/path/OsPath.kt @@ -16,7 +16,7 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile OsPath.kt - * LastUpdate 2025-09-15 08:59:15 + * LastUpdate 2025-09-18 09:47:43 * UpdateUser MingLiPro */ @@ -26,9 +26,8 @@ package com.mingliqiye.utils.path import java.io.File import java.net.URI -import java.nio.file.* -import java.util.* -import java.util.function.Consumer +import java.nio.file.Path +import java.nio.file.Paths class OsPath private constructor(private val path: Path) : Path by path { @@ -58,48 +57,4 @@ class OsPath private constructor(private val path: Path) : Path by path { return OsPath(Paths.get("")) } } - - override fun getParent(): Path? { - var parent = path.parent - if (parent == null) { - parent = path.toAbsolutePath().parent - } - return parent - } - - override fun toRealPath(vararg options: LinkOption): Path { - return OsPath(path.toRealPath(*options)) - } - - override fun register(watcher: WatchService, vararg events: WatchEvent.Kind<*>): WatchKey { - return path.register(watcher, *events) - } - - override fun register( - watcher: WatchService, - events: Array>, - vararg modifiers: WatchEvent.Modifier - ): WatchKey { - return path.register(watcher, events, *modifiers) - } - - override fun iterator(): MutableIterator { - return path.iterator() - } - - override fun compareTo(other: Path): Int { - return path.compareTo(other) - } - - override fun toString(): String { - return path.toString() - } - - override fun forEach(action: Consumer) { - path.forEach(action) - } - - override fun spliterator(): Spliterator { - return path.spliterator() - } } diff --git a/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt b/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt index d518f7f..088f5a0 100644 --- a/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt +++ b/src/main/kotlin/com/mingliqiye/utils/uuid/UUID.kt @@ -16,12 +16,13 @@ * ProjectName mingli-utils * ModuleName mingli-utils.main * CurrentFile UUID.kt - * LastUpdate 2025-09-17 16:27:32 + * LastUpdate 2025-09-18 14:39:00 * UpdateUser MingLiPro */ package com.mingliqiye.utils.uuid +import com.mingliqiye.utils.base.BASE256 import com.mingliqiye.utils.base.BASE64 import com.mingliqiye.utils.base.BASE91 import com.mingliqiye.utils.random.randomByteSecure @@ -66,6 +67,11 @@ class UUID : Serializable { return UUID(BASE64.decode(baseShortString)) } + @JvmStatic + fun ofBase256ShortString(baseShortString: String): UUID { + return UUID(BASE256.decode(baseShortString)) + } + @JvmStatic fun ofBase91ShortString(baseShortString: String): UUID { return UUID(BASE91.decode(baseShortString)) @@ -656,6 +662,10 @@ class UUID : Serializable { return BASE91.encode(data) } + fun getBase256ShortString(): String { + return BASE256.encode(data) + } + /** * 提取 UUID V1 中的 MAC 地址。 *