Skip to content

Instantly share code, notes, and snippets.

@dgvncsz0f
Last active March 22, 2016 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgvncsz0f/0afe8a1c6c028ff01727 to your computer and use it in GitHub Desktop.
Save dgvncsz0f/0afe8a1c6c028ff01727 to your computer and use it in GitHub Desktop.
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);
}
}
@phandja
Copy link

phandja commented Mar 22, 2016

Bem da hora 0/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment