MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / RemoteTexture

Class RemoteTexture

src/main/java/trace/graphics/remote/RemoteTexture.kt:9–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import java.nio.ByteBuffer
8import java.nio.ByteOrder
9import java.nio.file.Files
10
11class RemoteTexture(val websocket: NewNanoHTTPD, var channel_name: String) {
12
13 fun sendFile(fn: String) {
14
15 if (channel_name.length > 30) {
16 channel_name = channel_name.substring(0, 15) + channel_name.hashCode() + channel_name.substring(channel_name.length-2)
17 }
18
19 val bytes = Files.readAllBytes(File(fn).toPath())
20 val buffer = ByteBuffer.allocate(bytes.size + 2 * 64).order(ByteOrder.nativeOrder());
21 buffer.rewind()
22 buffer.putInt(bytes.size)
23 buffer.putChar('x')
24 buffer.put(channel_name.length.toByte())
25 buffer.putInt(0)
26 for (i in 0 until channel_name.length)
27 buffer.putChar(channel_name.get(i))
28 buffer.position(2 * 64).put(bytes);
29 buffer.rewind()
30 buffer.order(ByteOrder.BIG_ENDIAN)
31 websocket.openWebsockets.forEach {
32 it.send(buffer.array())
33 }
34 buffer.order(ByteOrder.LITTLE_ENDIAN)
35 }
36}

Callers 1

updateMethod · 0.85

Calls

no outgoing calls

Tested by 1

updateMethod · 0.68