Can't extract length from torrent file

I’m stuck on Stage #OW9

The expected output length is 820892 while the sample.torrent file has length equal to 92063 as described in the stage explanation, so it keeps failing on tests…

Here are my logs:

And here’s a snippet of my code:

        else if ("info".equals(command)){
            byte[] torrentBytes = Files.readAllBytes(Path.of("sample.torrent"));
            Map<String, Object> meta = bencode.decode(torrentBytes, Type.DICTIONARY);
            Map<String, Object> info = (Map<String, Object>) meta.get("info");

            System.out.println("Tracker URL: " + meta.get("announce"));
            System.out.println("Length: " + info.get("length"));
        }

Hey @MaHmoudHaBlaSs, your code should read the torrent file path from args, instead of hardcoding “sample.torrent”.

Let me know if you’d like any further clarification!

1 Like

Thanks, this solved the issue, and sorry for the confusion. :heart:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.