Conversation
sproshev
left a comment
There was a problem hiding this comment.
очень хорошо, подвела работа с ресурсами( в основном либо потенциально незакрытые, либо всегда незакрытые потоки
| } catch (IOException e) { | ||
| throw new TorrentException("cannot close tracker properly", e); | ||
| } | ||
| state.storeToFile(); |
There was a problem hiding this comment.
почему состояние не сохраняется, если не удалось закрыть сокет?
| public GetResponse(InputStream in, int size) throws IOException { | ||
| this.size = size; | ||
| this.content = new byte[size]; | ||
| in.read(content); |
| downloader.close(); | ||
| sourcesUpdater.close(); | ||
| seeder.close(); | ||
| } |
There was a problem hiding this comment.
тут тоже надо быть аккуратным с тем, что исключение в первой строке приведет к неисполнению оставшихся закрытий
| throw new TorrentException("file '" + file + "' does not exists"); | ||
| } | ||
| UploadRequest request = new UploadRequest(file); | ||
| UploadResponse response = (UploadResponse) sendRequest(request); |
There was a problem hiding this comment.
кстати, можно Request сделать дженерик-классом, где E будет тип возвращаемого Response. Тогда здесь не придется выполнять приведение типов. Если не очень понятна мысль, могу поподробнее расписать
| public boolean downloadFile(int fileId) throws IOException, TorrentException { | ||
| if (localFilesManager.getPartsManager().fileIsPresent(fileId)) { | ||
| System.err.println("file with id " + fileId + " already added as local file"); | ||
| return false; |
There was a problem hiding this comment.
можно IllegalArgumentException бросать в таком случае (и ниже)
| } | ||
|
|
||
| public void storeSplitted(LocalFileReference reference, Path targetFile) throws IOException { | ||
| InputStream is = Files.newInputStream(targetFile); |
| InputStream is = Files.newInputStream(targetFile); | ||
| for (int i = 0; i < reference.getNumberOfParts(); i++) { | ||
| byte[] buf = new byte[reference.getBlockSizeForPart(i)]; | ||
| int readed = is.read(buf); |
There was a problem hiding this comment.
тот же коммент про возвращаемое значение
No description provided.