forked from I2P_Developers/i2p.i2p
i2psnark: Remove unused bencode() methods
This commit is contained in:
@ -37,20 +37,6 @@ import net.i2p.data.DataHelper;
|
|||||||
public class BEncoder
|
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)
|
public static void bencode(Object o, OutputStream out)
|
||||||
throws IOException, IllegalArgumentException
|
throws IOException, IllegalArgumentException
|
||||||
{
|
{
|
||||||
@ -72,40 +58,12 @@ public class BEncoder
|
|||||||
throw new IllegalArgumentException("Cannot bencode: " + o.getClass());
|
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
|
public static void bencode(String s, OutputStream out) throws IOException
|
||||||
{
|
{
|
||||||
byte[] bs = s.getBytes("UTF-8");
|
byte[] bs = s.getBytes("UTF-8");
|
||||||
bencode(bs, out);
|
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
|
public static void bencode(Number n, OutputStream out) throws IOException
|
||||||
{
|
{
|
||||||
out.write('i');
|
out.write('i');
|
||||||
@ -114,20 +72,6 @@ public class BEncoder
|
|||||||
out.write('e');
|
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
|
public static void bencode(List<?> l, OutputStream out) throws IOException
|
||||||
{
|
{
|
||||||
out.write('l');
|
out.write('l');
|
||||||
@ -137,20 +81,6 @@ public class BEncoder
|
|||||||
out.write('e');
|
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
|
public static void bencode(byte[] bs, OutputStream out) throws IOException
|
||||||
{
|
{
|
||||||
String l = Integer.toString(bs.length);
|
String l = Integer.toString(bs.length);
|
||||||
@ -216,6 +146,7 @@ public class BEncoder
|
|||||||
if (l != null) {
|
if (l != null) {
|
||||||
// Keys must be sorted. XXX - This is not the correct order.
|
// Keys must be sorted. XXX - This is not the correct order.
|
||||||
// Spec says to sort by bytes, not lexically
|
// Spec says to sort by bytes, not lexically
|
||||||
|
if (l.size() > 1)
|
||||||
Collections.sort(l);
|
Collections.sort(l);
|
||||||
for (String key : l) {
|
for (String key : l) {
|
||||||
bencode(key, out);
|
bencode(key, out);
|
||||||
@ -224,6 +155,7 @@ public class BEncoder
|
|||||||
} else if (b != null) {
|
} else if (b != null) {
|
||||||
// Works for arrays of equal lengths, otherwise is probably not
|
// Works for arrays of equal lengths, otherwise is probably not
|
||||||
// what the bittorrent spec intends.
|
// what the bittorrent spec intends.
|
||||||
|
if (b.size() > 1)
|
||||||
Collections.sort(b, new BAComparator());
|
Collections.sort(b, new BAComparator());
|
||||||
for (byte[] key : b) {
|
for (byte[] key : b) {
|
||||||
bencode(key, out);
|
bencode(key, out);
|
||||||
|
Reference in New Issue
Block a user