@Test(expected = BeanValidationException.class) public void testRead_Validation_IncorrectUserIdentifier() { storage.read(new UserIdentifier(null), String.class); }
public @Valid <T> Optional<T> read(@NotNull UserIdentifier userId, @NotNull Class<T> clazz) throws ServiceException { Path filePath = getPath(userId, clazz); LOG.debug("Reading file {} for {}", filePath, userId); try (FileChannel channel = openForRead(filePath)) { if (channel == null) { LOG.debug("File not found: {}", filePath); return Optional.empty(); } int fileSize = (int) channel.size(); if (fileSize > config.fileStore.maxFileSize) { LOG.info("File: {} too large: {} - skipping it", filePath, fileSize); return Optional.empty(); } ByteBuffer buf = ByteBuffer.allocate(fileSize); channel.read(buf); buf.flip(); String decoded = decoder.get().decode(buf).toString(); decoded = StringUtils.trimToNull(decoded); if(decoded == null) { return Optional.empty(); } T content = jsonMarshaller.unmarshal(clazz, decoded); LOG.debug("File read"); return Optional.ofNullable(content); } catch (IOException | SecurityException | IllegalStateException e) { throw new ServiceException("Error reading filr from:" + filePath + " - " + e.getMessage(), e); } }
FileStorage { public @Valid <T> Optional<T> read(@NotNull UserIdentifier userId, @NotNull Class<T> clazz) throws ServiceException { Path filePath = getPath(userId, clazz); LOG.debug("Reading file {} for {}", filePath, userId); try (FileChannel channel = openForRead(filePath)) { if (channel == null) { LOG.debug("File not found: {}", filePath); return Optional.empty(); } int fileSize = (int) channel.size(); if (fileSize > config.fileStore.maxFileSize) { LOG.info("File: {} too large: {} - skipping it", filePath, fileSize); return Optional.empty(); } ByteBuffer buf = ByteBuffer.allocate(fileSize); channel.read(buf); buf.flip(); String decoded = decoder.get().decode(buf).toString(); decoded = StringUtils.trimToNull(decoded); if(decoded == null) { return Optional.empty(); } T content = jsonMarshaller.unmarshal(clazz, decoded); LOG.debug("File read"); return Optional.ofNullable(content); } catch (IOException | SecurityException | IllegalStateException e) { throw new ServiceException("Error reading filr from:" + filePath + " - " + e.getMessage(), e); } } }
FileStorage { public @Valid <T> Optional<T> read(@NotNull UserIdentifier userId, @NotNull Class<T> clazz) throws ServiceException { Path filePath = getPath(userId, clazz); LOG.debug("Reading file {} for {}", filePath, userId); try (FileChannel channel = openForRead(filePath)) { if (channel == null) { LOG.debug("File not found: {}", filePath); return Optional.empty(); } int fileSize = (int) channel.size(); if (fileSize > config.fileStore.maxFileSize) { LOG.info("File: {} too large: {} - skipping it", filePath, fileSize); return Optional.empty(); } ByteBuffer buf = ByteBuffer.allocate(fileSize); channel.read(buf); buf.flip(); String decoded = decoder.get().decode(buf).toString(); decoded = StringUtils.trimToNull(decoded); if(decoded == null) { return Optional.empty(); } T content = jsonMarshaller.unmarshal(clazz, decoded); LOG.debug("File read"); return Optional.ofNullable(content); } catch (IOException | SecurityException | IllegalStateException e) { throw new ServiceException("Error reading filr from:" + filePath + " - " + e.getMessage(), e); } }  }
FileStorage { public @Valid <T> Optional<T> read(@NotNull UserIdentifier userId, @NotNull Class<T> clazz) throws ServiceException { Path filePath = getPath(userId, clazz); LOG.debug("Reading file {} for {}", filePath, userId); try (FileChannel channel = openForRead(filePath)) { if (channel == null) { LOG.debug("File not found: {}", filePath); return Optional.empty(); } int fileSize = (int) channel.size(); if (fileSize > config.fileStore.maxFileSize) { LOG.info("File: {} too large: {} - skipping it", filePath, fileSize); return Optional.empty(); } ByteBuffer buf = ByteBuffer.allocate(fileSize); channel.read(buf); buf.flip(); String decoded = decoder.get().decode(buf).toString(); decoded = StringUtils.trimToNull(decoded); if(decoded == null) { return Optional.empty(); } T content = jsonMarshaller.unmarshal(clazz, decoded); LOG.debug("File read"); return Optional.ofNullable(content); } catch (IOException | SecurityException | IllegalStateException e) { throw new ServiceException("Error reading filr from:" + filePath + " - " + e.getMessage(), e); } }  boolean supported(); void store(@NotNull UserIdentifier userId, @NotNull Object entity); @Valid Optional<T> read(@NotNull UserIdentifier userId, @NotNull Class<T> clazz); int getLockRetryCount(); }
FileStorage { public @Valid <T> Optional<T> read(@NotNull UserIdentifier userId, @NotNull Class<T> clazz) throws ServiceException { Path filePath = getPath(userId, clazz); LOG.debug("Reading file {} for {}", filePath, userId); try (FileChannel channel = openForRead(filePath)) { if (channel == null) { LOG.debug("File not found: {}", filePath); return Optional.empty(); } int fileSize = (int) channel.size(); if (fileSize > config.fileStore.maxFileSize) { LOG.info("File: {} too large: {} - skipping it", filePath, fileSize); return Optional.empty(); } ByteBuffer buf = ByteBuffer.allocate(fileSize); channel.read(buf); buf.flip(); String decoded = decoder.get().decode(buf).toString(); decoded = StringUtils.trimToNull(decoded); if(decoded == null) { return Optional.empty(); } T content = jsonMarshaller.unmarshal(clazz, decoded); LOG.debug("File read"); return Optional.ofNullable(content); } catch (IOException | SecurityException | IllegalStateException e) { throw new ServiceException("Error reading filr from:" + filePath + " - " + e.getMessage(), e); } }  boolean supported(); void store(@NotNull UserIdentifier userId, @NotNull Object entity); @Valid Optional<T> read(@NotNull UserIdentifier userId, @NotNull Class<T> clazz); int getLockRetryCount();  }