Conversation
Export functions
| public class CompressFactory { | ||
| public static ICompress getCompressType(CompressType type) { | ||
| ICompress compressor = null; | ||
| if (type.equals(CompressType.ZIP)) { |
There was a problem hiding this comment.
we usually prefer to write it like this CompressType.ZIP.equals( .. to avoid null pointer exception
| 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(); | ||
| } |
There was a problem hiding this comment.
none primitive method, you need to extract it
| try { | ||
| if (!file.delete()) { | ||
| throw new FileDeletionException("File Deletion Failed"); | ||
| } | ||
| } catch (FileDeletionException e) { | ||
| log(Level.SEVERE, e.getMessage(), "CompressZIP", "compress"); | ||
| } |
There was a problem hiding this comment.
useless try-catch and throw
| } catch (FileDeletionException e) { | ||
| log(Level.SEVERE, e.getMessage(), "CompressZIP", "compress"); | ||
| } | ||
| }catch (NullPointerException e){ |
There was a problem hiding this comment.
very bad practice to have an empty catch block
instead, created new custom exception such as CompressZIPExecption as throw it
| 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"); | ||
| } |
| userType = userService.getUser(user).getUserType(); | ||
| transactions = paymentService.getTransactions(user); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
you may exit the application if the logger failed to start
| if (ActivityServiceTypes.ACTIVITY_SERVICE.equals(type)) { | ||
| return new UserActivityService(); | ||
| } | ||
| else { |
There was a problem hiding this comment.
no need for else, you can directly throw the execption
| if (PaymentServiceTypes.PAYMENT_SERVICE.equals(type)) { | ||
| return new PaymentService(); | ||
| } | ||
| else { |
| if (UserServiceTypes.USER_SERVICE_PROXY.equals(type)) { | ||
| return new UserServiceProxy(); | ||
| } | ||
| else { |
No description provided.