Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with torrent serialization(IE, error when running new Torrent(bytes, seed)) #131

Closed
dessalines opened this issue May 19, 2015 · 2 comments

Comments

@dessalines
Copy link
Contributor

I've been testing out serializing and deserializing torrents with methods I found here, but I keep getting an error upon deserialization(IE, running new Torrent(bytes, seed):

com.turn.ttorrent.bcodec.InvalidBEncodingException: Unknown indicator '99'
    at com.turn.ttorrent.bcodec.BDecoder.bdecode(BDecoder.java:142)
    at com.turn.ttorrent.bcodec.BDecoder.bdecodeMap(BDecoder.java:278)
    at com.turn.ttorrent.bcodec.BDecoder.bdecode(BDecoder.java:140)
    at com.turn.ttorrent.bcodec.BDecoder.bdecodeMap(BDecoder.java:280)
    at com.turn.ttorrent.bcodec.BDecoder.bdecode(BDecoder.java:140)
    at com.turn.ttorrent.bcodec.BDecoder.bdecode(BDecoder.java:88)
    at com.turn.ttorrent.common.Torrent.<init>(Torrent.java:137)

Here's how I'm using it:
Serializing:

public static String serializeTorrentFile(Torrent t) {

        String out = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            t.save(baos);

            out = baos.toString("UTF-8");
            baos.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return out;
    }

Deserializing:

    public static Torrent deserializeTorrentFile(String data) {
        Torrent t = null;
        try {
            byte[] b = data.getBytes("UTF-8");
            t = new Torrent(b, false); // ERROR COMES ON THIS LINE


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return t;
    }
@mpetazzoni
Copy link
Owner

I don't think you can reliably convert and read back the binary torrent data as a UTF-8 encoded String. Does it work when you use byte[] ?

See https://github.com/mpetazzoni/ttorrent/blob/master/core/src/main/java/com/turn/ttorrent/common/Torrent.java#L493

@dessalines
Copy link
Contributor Author

That did it @mpetazzoni, if I keep it as a byte[] , but not as a UTF-8 string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants