-
Notifications
You must be signed in to change notification settings - Fork 0
Java06. ДЗ 05, Горячева Валерия #5
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
base: master
Are you sure you want to change the base?
Conversation
sproshev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
очень хорошо, подвела работа с ресурсами( в основном либо потенциально незакрытые, либо всегда незакрытые потоки
| } catch (IOException e) { | ||
| throw new TorrentException("cannot close tracker properly", e); | ||
| } | ||
| state.storeToFile(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему состояние не сохраняется, если не удалось закрыть сокет?
| public GetResponse(InputStream in, int size) throws IOException { | ||
| this.size = size; | ||
| this.content = new byte[size]; | ||
| in.read(content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
см доку по возвращаемому значению
| downloader.close(); | ||
| sourcesUpdater.close(); | ||
| seeder.close(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут тоже надо быть аккуратным с тем, что исключение в первой строке приведет к неисполнению оставшихся закрытий
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
кстати, можно 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно IllegalArgumentException бросать в таком случае (и ниже)
| } | ||
|
|
||
| public void storeSplitted(LocalFileReference reference, Path targetFile) throws IOException { | ||
| InputStream is = Files.newInputStream(targetFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а закрыть?
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тот же коммент про возвращаемое значение
No description provided.