Class BEncoder

java.lang.Object
com.biglybt.core.util.BEncoder

public class BEncoder extends Object
A set of utility methods to encode a Map into a bencoded array of byte. integer are represented as Long, String as byte[], dictionaries as Map, and list as List.
  • Field Details

    • BUFFER_DOUBLE_LIMIT

      private static final int BUFFER_DOUBLE_LIMIT
      See Also:
    • MINUS_1_BYTES

      private static final byte[] MINUS_1_BYTES
    • non_ascii_logs

      private static volatile int non_ascii_logs
    • current_buffer

      private byte[] current_buffer
    • current_buffer_pos

      private int current_buffer_pos
    • old_buffers

      private byte[][] old_buffers
    • current_os

      private OutputStream current_os
    • int_buffer

      private final byte[] int_buffer
    • digits

      static final byte[] digits
    • DigitTens

      static final byte[] DigitTens
    • DigitOnes

      static final byte[] DigitOnes
  • Constructor Details

    • BEncoder

      public BEncoder()
  • Method Details

    • encode

      public static byte[] encode(Map object) throws IOException
      Throws:
      IOException
    • encodeToStream

      public static void encodeToStream(Map object, OutputStream os) throws IOException
      Throws:
      IOException
    • encodeObject

      private void encodeObject(Object object, OutputStream os, boolean utf_key_expected) throws IOException
      Throws:
      IOException
    • encodeObject

      private boolean encodeObject(Object object, boolean utf_key_expected) throws IOException
      Throws:
      IOException
    • writeChar

      private void writeChar(char c) throws IOException
      Throws:
      IOException
    • writeInt

      private void writeInt(int i) throws IOException
      Throws:
      IOException
    • writeLong

      private void writeLong(long l) throws IOException
      Throws:
      IOException
    • writeBytes

      private void writeBytes(byte[] bytes) throws IOException
      Throws:
      IOException
    • writeBytes

      private void writeBytes(byte[] bytes, int offset, int length) throws IOException
      Throws:
      IOException
    • writeByteBuffer

      private void writeByteBuffer(ByteBuffer bb) throws IOException
      Throws:
      IOException
    • getEncodedSoFar

      private String getEncodedSoFar()
    • toByteArray

      private byte[] toByteArray()
    • normaliseObject

      private static Object normaliseObject(Object o)
    • isEncodable

      public static boolean isEncodable(Object toCheck)
    • objectsAreIdentical

      public static boolean objectsAreIdentical(Object o1, Object o2)
    • listsAreIdentical

      public static boolean listsAreIdentical(List list1, List list2)
    • mapsAreIdentical

      public static boolean mapsAreIdentical(Map map1, Map map2)
    • cloneMap

      public static Map cloneMap(Map map)
    • cloneList

      public static List cloneList(List list)
    • clone

      public static Object clone(Object obj)
    • encodeToXML

      public static StringBuffer encodeToXML(Map map, boolean simple)
    • encodeToJSONGeneric

      private static Object encodeToJSONGeneric(Object obj)
    • encodeToJSONArray

      public static JSONArray encodeToJSONArray(List b_list)
    • encodeToJSONObject

      public static JSONObject encodeToJSONObject(Map<Object,Object> b_map)
    • encodeToJSON

      public static String encodeToJSON(Map b_map)
    • intToBytes

      private int intToBytes(int i)
      writes to int_buffer and returns start position in buffer (always runs to end of buffer)
      Parameters:
      i -
      Returns:
    • main

      public static void main(String[] args)