Skip to content

Conversation

@dkaznacheev
Copy link
Owner

No description provided.

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь куча файлов, котоыре не надо выкладывать. Исходники Trie ещё ладно, но бинарники и куча лишних файлов от ZipFile в гите точно не нужны.

Зато нужны юнит-тесты

/**
* Custom exception to throw if folder was not found
*/
class FolderNotFoundException extends Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Его надо сделать public, иначе его будет проблематично ловить вне пакета

/**
* Custom exception to throw in case of zip file problems
*/
class ZipException extends Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже

* scans all archives in directory, unpacks only files that match the regex
* @throws FolderNotFoundException
* @throws FileNotFoundException
* @throws ZipException
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пустые комментарии --- это плохо


BufferedInputStream fileInputStream = new BufferedInputStream(new FileInputStream(fileEntry));

ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стримы надо не забывать закрывать. Причём, для этого есть try-with-resources

zipEntry = zipInputStream.getNextEntry();
}
}
} catch (NullPointerException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NullPointerException ловить нельзя :)

} catch (NullPointerException e) {
throw new FolderNotFoundException();
} catch (IOException e) {
throw new ZipException();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так теряется информация об исключении, которая была в e. Хороший пример антипаттерна Error Hiding (https://en.wikipedia.org/wiki/Error_hiding)

fileOutputStream.write(bytes, 0, length);
}
inputStream.close();
fileOutputStream.close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут тоже лучше try-with-resources, этот код беззащитен перед исключениями


public static void main(String[] args) {
String path = args[0];
String regex = args[1];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо проверять пользовательский ввод, людям свойственно ошибаться

@@ -0,0 +1,124 @@
import java.io.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Класс вне пакета --- это плохо

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну как-то не до конца почищено. .gradle же осталась, и workspace.xml. И всё-таки нужны юнит-тесты

@@ -0,0 +1,128 @@
package ZipFiler;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пакет неканонично назван

/**
* Custom exception to throw if folder was not found
*/
public class FolderNotFoundException extends Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static?

/**
* Custom exception to throw in case of zip file problems
*/
public class ZipException extends Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И тут

private void writeEntry(ZipFile zipFile, ZipEntry zipEntry) {
try (InputStream inputStream = zipFile.getInputStream(zipEntry);
FileOutputStream fileOutputStream = new FileOutputStream(zipEntry.getName());
){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо пробел перед "{"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants