Last active
March 22, 2016 02:59
-
-
Save dgvncsz0f/0afe8a1c6c028ff01727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.nio.ByteBuffer; | |
import java.util.*; | |
public class Test { | |
private static byte[] encode(int c, String path) throws Exception { | |
ByteBuffer buff = ByteBuffer.allocate(Integer.SIZE/8 + Character.SIZE/8 * path.length()); | |
buff | |
.putInt(c) | |
.asCharBuffer() | |
.append(path); | |
return buff.array(); | |
} | |
private static void dump(byte[] bytes) throws Exception { | |
ByteBuffer buff = ByteBuffer.wrap(bytes); | |
int n = buff.getInt(); | |
String p = buff.asCharBuffer().toString(); | |
System.out.format("%d - %s\n", n, p); | |
} | |
public static void main(String args[]) throws Exception { | |
byte[] data = encode(100, "/foo/bar"); | |
dump(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bem da hora 0/