org.gudy.azureus2.core3.util
Class BDecoder

java.lang.Object
  extended by org.gudy.azureus2.core3.util.BDecoder

public class BDecoder
extends Object

A set of utility methods to decode a bencoded array of byte into a Map. integer are represented as Long, String as byte[], dictionnaries as Map, and list as List.

Author:
TdC_VgA

Field Summary
static int MAX_BYTE_ARRAY_SIZE
           
 
Constructor Summary
BDecoder()
           
 
Method Summary
static Map<String,Object> decode(BufferedInputStream is)
           
static Map<String,Object> decode(byte[] data)
           
static Map<String,Object> decode(byte[] data, int offset, int length)
           
 Map<String,Object> decodeByteArray(byte[] data)
           
 Map<String,Object> decodeByteArray(byte[] data, int offset, int length)
           
 Map<String,Object> decodeByteArray(byte[] data, int offset, int length, boolean internKeys)
           
 Map<String,Object> decodeByteBuffer(ByteBuffer buffer, boolean internKeys)
           
static Map decodeFromJSON(String json)
           
static List decodeFromJSONArray(List j_list)
           
static Map decodeFromJSONObject(Map<Object,Object> j_map)
           
 Map<String,Object> decodeStream(BufferedInputStream data)
           
 Map<String,Object> decodeStream(BufferedInputStream data, boolean internKeys)
           
static List decodeStrings(List list)
          Decodes byte arrays into strings.
static Map decodeStrings(Map map)
          Converts any byte[] entries into UTF-8 strings.
static void main(String[] args)
           
static long parseLong(char[] chars, int start, int length)
           
static void print(Object obj)
           
static void print(PrintWriter writer, Object obj)
           
 void setRecoveryMode(boolean r)
           
 void setVerifyMapOrder(boolean b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_BYTE_ARRAY_SIZE

public static final int MAX_BYTE_ARRAY_SIZE
See Also:
Constant Field Values
Constructor Detail

BDecoder

public BDecoder()
Method Detail

decode

public static Map<String,Object> decode(byte[] data)
                                 throws IOException
Throws:
IOException

decode

public static Map<String,Object> decode(byte[] data,
                                        int offset,
                                        int length)
                                 throws IOException
Throws:
IOException

decode

public static Map<String,Object> decode(BufferedInputStream is)
                                 throws IOException
Throws:
IOException

decodeByteArray

public Map<String,Object> decodeByteArray(byte[] data)
                                   throws IOException
Throws:
IOException

decodeByteArray

public Map<String,Object> decodeByteArray(byte[] data,
                                          int offset,
                                          int length)
                                   throws IOException
Throws:
IOException

decodeByteArray

public Map<String,Object> decodeByteArray(byte[] data,
                                          int offset,
                                          int length,
                                          boolean internKeys)
                                   throws IOException
Throws:
IOException

decodeByteBuffer

public Map<String,Object> decodeByteBuffer(ByteBuffer buffer,
                                           boolean internKeys)
                                    throws IOException
Throws:
IOException

decodeStream

public Map<String,Object> decodeStream(BufferedInputStream data)
                                throws IOException
Throws:
IOException

decodeStream

public Map<String,Object> decodeStream(BufferedInputStream data,
                                       boolean internKeys)
                                throws IOException
Throws:
IOException

parseLong

public static long parseLong(char[] chars,
                             int start,
                             int length)

setVerifyMapOrder

public void setVerifyMapOrder(boolean b)

setRecoveryMode

public void setRecoveryMode(boolean r)

print

public static void print(Object obj)

print

public static void print(PrintWriter writer,
                         Object obj)

decodeStrings

public static Map decodeStrings(Map map)
Converts any byte[] entries into UTF-8 strings. REPLACES EXISTING MAP VALUES

Parameters:
map -
Returns:

decodeStrings

public static List decodeStrings(List list)
Decodes byte arrays into strings. REPLACES EXISTING LIST VALUES

Parameters:
list -
Returns:
the same list passed in

decodeFromJSONArray

public static List decodeFromJSONArray(List j_list)

decodeFromJSONObject

public static Map decodeFromJSONObject(Map<Object,Object> j_map)

decodeFromJSON

public static Map decodeFromJSON(String json)

main

public static void main(String[] args)