This repository has been archived on 2018-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
url-shortener/src/main/kotlin/net/cismon/urlshortener/helper/UuidGenerator.kt

18 lines
515 B
Kotlin

package net.cismon.urlshortener.helper
import org.springframework.stereotype.Component
import org.springframework.util.Base64Utils
import java.nio.ByteBuffer
import java.util.*
@Component
class UuidGenerator {
fun generate() : String {
val uuid = UUID.randomUUID()
return Base64Utils.encodeToUrlSafeString(ByteBuffer
.allocate(16)
.putLong(uuid.mostSignificantBits)
.putLong(uuid.leastSignificantBits)
.array()).trim('=')
}
}