@Test public void accept_ShouldReturnFalse_IfFileIsSmallerThanMinSize() throws Exception { when(config.max_file_size()).thenReturn(1024L); when(config.min_file_size()).thenReturn(10L); initSubject(); Path file = inputDir.resolve("movie.mp4"); writeBytes(8, file); media.setSourcePath(inputDir.relativize(file)); assertThat(subject.accept(media)).isFalse(); }
@Override public boolean accept(Media candidate) { Path file = config.base_input_dir().resolve(candidate.getSourcePath()); try { long size = Files.size(file); if (minSize > 0 && maxSize > 0) { return logAndReturn(size >= minSize && size <= maxSize, file, size); } else if (minSize <= 0) { return logAndReturn(size <= maxSize, file, size); } else { return logAndReturn(size >= minSize, file, size); } } catch (IOException e) { log.warn("Could not determine file size of {}: {}. Declined file.", file, e.toString()); return false; } }
FileSizeConstraint extends AbstractConstraint { @Override public boolean accept(Media candidate) { Path file = config.base_input_dir().resolve(candidate.getSourcePath()); try { long size = Files.size(file); if (minSize > 0 && maxSize > 0) { return logAndReturn(size >= minSize && size <= maxSize, file, size); } else if (minSize <= 0) { return logAndReturn(size <= maxSize, file, size); } else { return logAndReturn(size >= minSize, file, size); } } catch (IOException e) { log.warn("Could not determine file size of {}: {}. Declined file.", file, e.toString()); return false; } } }
FileSizeConstraint extends AbstractConstraint { @Override public boolean accept(Media candidate) { Path file = config.base_input_dir().resolve(candidate.getSourcePath()); try { long size = Files.size(file); if (minSize > 0 && maxSize > 0) { return logAndReturn(size >= minSize && size <= maxSize, file, size); } else if (minSize <= 0) { return logAndReturn(size <= maxSize, file, size); } else { return logAndReturn(size >= minSize, file, size); } } catch (IOException e) { log.warn("Could not determine file size of {}: {}. Declined file.", file, e.toString()); return false; } } @Inject  FileSizeConstraint(ConstraintConfig config); protected  FileSizeConstraint(ConstraintConfig config,
                                 long factor); }
FileSizeConstraint extends AbstractConstraint { @Override public boolean accept(Media candidate) { Path file = config.base_input_dir().resolve(candidate.getSourcePath()); try { long size = Files.size(file); if (minSize > 0 && maxSize > 0) { return logAndReturn(size >= minSize && size <= maxSize, file, size); } else if (minSize <= 0) { return logAndReturn(size <= maxSize, file, size); } else { return logAndReturn(size >= minSize, file, size); } } catch (IOException e) { log.warn("Could not determine file size of {}: {}. Declined file.", file, e.toString()); return false; } } @Inject  FileSizeConstraint(ConstraintConfig config); protected  FileSizeConstraint(ConstraintConfig config,
                                 long factor); @Override boolean accept(Media candidate); }
FileSizeConstraint extends AbstractConstraint { @Override public boolean accept(Media candidate) { Path file = config.base_input_dir().resolve(candidate.getSourcePath()); try { long size = Files.size(file); if (minSize > 0 && maxSize > 0) { return logAndReturn(size >= minSize && size <= maxSize, file, size); } else if (minSize <= 0) { return logAndReturn(size <= maxSize, file, size); } else { return logAndReturn(size >= minSize, file, size); } } catch (IOException e) { log.warn("Could not determine file size of {}: {}. Declined file.", file, e.toString()); return false; } } @Inject  FileSizeConstraint(ConstraintConfig config); protected  FileSizeConstraint(ConstraintConfig config,
                                 long factor); @Override boolean accept(Media candidate); static long BYTES; static long KIBI_BYTES; static long MEBI_BYTES; }