i2psnark: Remove unused bencode() methods

This commit is contained in:
zzz
2020-11-02 11:39:40 +00:00
parent 751af5bcd8
commit a21a64e0c6

View File

@ -37,20 +37,6 @@ import net.i2p.data.DataHelper;
public class BEncoder
{
public static byte[] bencode(Object o) throws IllegalArgumentException
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bencode(o, baos);
return baos.toByteArray();
}
catch (IOException ioe)
{
throw new InternalError(ioe.toString());
}
}
public static void bencode(Object o, OutputStream out)
throws IOException, IllegalArgumentException
{
@ -72,40 +58,12 @@ public class BEncoder
throw new IllegalArgumentException("Cannot bencode: " + o.getClass());
}
public static byte[] bencode(String s)
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bencode(s, baos);
return baos.toByteArray();
}
catch (IOException ioe)
{
throw new InternalError(ioe.toString());
}
}
public static void bencode(String s, OutputStream out) throws IOException
{
byte[] bs = s.getBytes("UTF-8");
bencode(bs, out);
}
public static byte[] bencode(Number n)
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bencode(n, baos);
return baos.toByteArray();
}
catch (IOException ioe)
{
throw new InternalError(ioe.toString());
}
}
public static void bencode(Number n, OutputStream out) throws IOException
{
out.write('i');
@ -114,20 +72,6 @@ public class BEncoder
out.write('e');
}
public static byte[] bencode(List<?> l)
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bencode(l, baos);
return baos.toByteArray();
}
catch (IOException ioe)
{
throw new InternalError(ioe.toString());
}
}
public static void bencode(List<?> l, OutputStream out) throws IOException
{
out.write('l');
@ -137,20 +81,6 @@ public class BEncoder
out.write('e');
}
public static byte[] bencode(byte[] bs)
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bencode(bs, baos);
return baos.toByteArray();
}
catch (IOException ioe)
{
throw new InternalError(ioe.toString());
}
}
public static void bencode(byte[] bs, OutputStream out) throws IOException
{
String l = Integer.toString(bs.length);
@ -216,7 +146,8 @@ public class BEncoder
if (l != null) {
// Keys must be sorted. XXX - This is not the correct order.
// Spec says to sort by bytes, not lexically
Collections.sort(l);
if (l.size() > 1)
Collections.sort(l);
for (String key : l) {
bencode(key, out);
bencode(m.get(key), out);
@ -224,7 +155,8 @@ public class BEncoder
} else if (b != null) {
// Works for arrays of equal lengths, otherwise is probably not
// what the bittorrent spec intends.
Collections.sort(b, new BAComparator());
if (b.size() > 1)
Collections.sort(b, new BAComparator());
for (byte[] key : b) {
bencode(key, out);
bencode(m.get(key), out);