Skip to content

Instantly share code, notes, and snippets.

@halfninja
Created November 9, 2023 10:08
Show Gist options
  • Save halfninja/da639a180d8cfd83062e027724016bea to your computer and use it in GitHub Desktop.
Save halfninja/da639a180d8cfd83062e027724016bea to your computer and use it in GitHub Desktop.
Read a 16-byte file and print as a UUID
import java.io.File
import java.util.UUID
import java.nio.ByteBuffer
fun main(vararg args: String) {
val filename = args.firstOrNull()
if (filename == null) {
System.err.println("Usage: kotlin UuidKt <filename>")
System.exit(1)
}
val file = File(filename)
if (!file.isFile()) {
System.err.println("File does not exist")
System.exit(1)
}
val bytes = ByteBuffer.wrap(file.readBytes())
val uuid = UUID(bytes.getLong(), bytes.getLong())
println(uuid.toString())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment