Skip to content

Dev#5

Open
osama-sholi wants to merge 23 commits intomainfrom
dev
Open

Dev#5
osama-sholi wants to merge 23 commits intomainfrom
dev

Conversation

@osama-sholi
Copy link
Owner

No description provided.

public class CompressFactory {
public static ICompress getCompressType(CompressType type) {
ICompress compressor = null;
if (type.equals(CompressType.ZIP)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we usually prefer to write it like this CompressType.ZIP.equals( .. to avoid null pointer exception

Comment on lines +22 to +38
File file = new File(f);
ZipEntry entry = new ZipEntry(file.getName());
zipOutputStream.putNextEntry(entry);
if (!file.exists()) {
throw new FileNotFoundException("File not found: " + f);
}
try (FileInputStream fileInputStream = new FileInputStream(file)) {
int len;
byte[] data = new byte[1024];
while ((len = fileInputStream.read(data)) != -1) {
zipOutputStream.write(data, 0, len);
}
} catch (IOException e) {
log(Level.SEVERE, e.getMessage(), "CompressZIP", "compress");
} finally {
zipOutputStream.closeEntry();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

none primitive method, you need to extract it

Comment on lines +39 to +45
try {
if (!file.delete()) {
throw new FileDeletionException("File Deletion Failed");
}
} catch (FileDeletionException e) {
log(Level.SEVERE, e.getMessage(), "CompressZIP", "compress");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

useless try-catch and throw

} catch (FileDeletionException e) {
log(Level.SEVERE, e.getMessage(), "CompressZIP", "compress");
}
}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.

very bad practice to have an empty catch block
instead, created new custom exception such as CompressZIPExecption as throw it

Comment on lines +31 to +38
try {
File file = new File(textFile);
if (!file.delete()) {
throw new FileDeletionException("File Deletion Failed");
}
} catch (FileDeletionException e) {
log(Level.SEVERE, e.getMessage(), "PDFConvertor", "ConvertTOPdf");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

Comment on lines +39 to +40
userType = userService.getUser(user).getUserType();
transactions = paymentService.getTransactions(user);
Copy link
Collaborator

Choose a reason for hiding this comment

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

both these service may throw exceptions so you have to split them into two retry blocks

SimpleFormatter formatter = new SimpleFormatter();
fileHandler.setFormatter(formatter);
} catch (SecurityException | IOException e) {
e.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

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

you may exit the application if the logger failed to start

if (ActivityServiceTypes.ACTIVITY_SERVICE.equals(type)) {
return new UserActivityService();
}
else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need for else, you can directly throw the execption

if (PaymentServiceTypes.PAYMENT_SERVICE.equals(type)) {
return new PaymentService();
}
else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same above

if (UserServiceTypes.USER_SERVICE_PROXY.equals(type)) {
return new UserServiceProxy();
}
else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need for else

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.

4 participants