Skip to content

Commit 5495ed4

Browse files
committed
Fixed string conversion
1 parent 8348427 commit 5495ed4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.robothaver.torrentfileparser.domain.Torrent;
44
import com.robothaver.torrentfileparser.exception.MalformedTorrentFileException;
55

6+
import java.nio.charset.StandardCharsets;
67
import java.util.*;
78

89
public class TorrentFileParser {
@@ -98,12 +99,12 @@ private String parseString() throws MalformedTorrentFileException {
9899
}
99100
int length;
100101
try {
101-
length = Integer.parseInt(new String(Arrays.copyOfRange(bytes, startIndex, colonIndex)));
102+
length = Integer.parseInt(new String(Arrays.copyOfRange(bytes, startIndex, colonIndex), StandardCharsets.UTF_8));
102103
} catch (NumberFormatException e) {
103104
throw new MalformedTorrentFileException();
104105
}
105106

106-
String value = new String(Arrays.copyOfRange(bytes, colonIndex + 1, colonIndex + length + 1));
107+
String value = new String(Arrays.copyOfRange(bytes, colonIndex + 1, colonIndex + length + 1), StandardCharsets.UTF_8);
107108
iterator += length + 1;
108109
return value;
109110
}
@@ -115,6 +116,6 @@ private Long parseInt() {
115116
}
116117
byte[] valueBytes = Arrays.copyOfRange(bytes, startIndex, iterator);
117118
iterator++; // Skipping closing e
118-
return Long.parseLong(new String(valueBytes));
119+
return Long.parseLong(new String(valueBytes, StandardCharsets.UTF_8));
119120
}
120121
}

0 commit comments

Comments
 (0)