public class BEncoder extends Object
Bencoding is a simple way to structure data used in BitTorrent. This class provides static methods to encode the following Java types:
Example output formats:
| Constructor and Description |
|---|
BEncoder() |
| Modifier and Type | Method and Description |
|---|---|
static void |
bencode(byte[] bs,
OutputStream out)
Bencode a byte array to the given OutputStream.
|
static void |
bencode(List<?> l,
OutputStream out)
Bencode a List to the given OutputStream.
|
static byte[] |
bencode(Map<?,?> m)
Bencode a Map to a byte array.
|
static void |
bencode(Map<?,?> m,
OutputStream out)
Bencode a Map to the given OutputStream.
|
static void |
bencode(Number n,
OutputStream out)
Bencode a Number to the given OutputStream.
|
static void |
bencode(Object o,
OutputStream out)
Bencode an object to the given OutputStream.
|
static void |
bencode(String s,
OutputStream out)
Bencode a String to the given OutputStream.
|
public static void bencode(byte[] bs,
OutputStream out)
throws IOException
bs - the byte array to encodeout - the OutputStream to write the bencoded data toIOException - if an I/O error occurspublic static void bencode(List<?> l, OutputStream out) throws IOException
l - the List to encodeout - the OutputStream to write the bencoded data toIOException - if an I/O error occurspublic static byte[] bencode(Map<?,?> m)
m - the Map to encodeIllegalArgumentException - if keys are not all Strings or all byte[]spublic static void bencode(Map<?,?> m, OutputStream out) throws IOException, IllegalArgumentException
m - the Map to encodeout - the OutputStream to write the bencoded data toIOException - if an I/O error occursIllegalArgumentException - if keys are not all Strings or all byte[]spublic static void bencode(Number n, OutputStream out) throws IOException
n - the Number to encodeout - the OutputStream to write the bencoded data toIOException - if an I/O error occurspublic static void bencode(Object o, OutputStream out) throws IOException, IllegalArgumentException
o - the object to encode (String, byte[], Number, List, Map, or BEValue)out - the OutputStream to write the bencoded data toIOException - if an I/O error occursIllegalArgumentException - if the object type cannot be encodedNullPointerException - if the object is nullpublic static void bencode(String s, OutputStream out) throws IOException
s - the String to encode (will be UTF-8 encoded)out - the OutputStream to write the bencoded data toIOException - if an I/O error occurs