Skip to content

Commit 8348427

Browse files
committed
Refactored
1 parent ac77a0f commit 8348427

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/main/java/com/robothaver/torrentfileparser/parser/TorrentBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public void processKeyValue(String key, Object value) {
3030
case "pieces" -> torrent.setPieces(String.valueOf(value));
3131
case "comment" -> torrent.setComment(String.valueOf(value));
3232
case "private" -> torrent.setPrivate((long) value == 1);
33-
default -> throw new IllegalStateException("Unknown key!");
3433
}
3534
}
3635

src/main/java/com/robothaver/torrentfileparser/parser/TorrentFileParser.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ public TorrentFileParser(byte[] bytes, boolean computeInfoHash) {
1717
this.computeInfoHash = computeInfoHash;
1818
}
1919

20+
public Torrent parseToTorrent() throws MalformedTorrentFileException {
21+
torrentBuilder = new TorrentBuilder();
22+
parse();
23+
iterator = 0;
24+
return torrentBuilder.getTorrent();
25+
}
26+
27+
public Map<String, Object> parseToMap() throws MalformedTorrentFileException {
28+
Object parse = parse();
29+
iterator = 0;
30+
return (Map<String, Object>) parse;
31+
}
32+
2033
private Object parse() throws MalformedTorrentFileException {
2134
return switch (bytes[iterator]) {
2235
case 'i' -> parseInt();
@@ -32,19 +45,6 @@ private Object parse() throws MalformedTorrentFileException {
3245
};
3346
}
3447

35-
public Torrent parseToTorrent() throws MalformedTorrentFileException {
36-
torrentBuilder = new TorrentBuilder();
37-
parse();
38-
iterator = 0;
39-
return torrentBuilder.getTorrent();
40-
}
41-
42-
public Map<String, Object> parseToMap() throws MalformedTorrentFileException {
43-
Object parse = parse();
44-
iterator = 0;
45-
return (Map<String, Object>) parse;
46-
}
47-
4848
private boolean isInt(byte currentByte) {
4949
return (byte) '0' <= currentByte && currentByte <= (byte) '9';
5050
}

0 commit comments

Comments
 (0)