@Test public void testWriteResourceFileShouldSetHeaders() throws IOException { given(fileReader.readFile(FILE_NAME, path)).willReturn(inputStream); given(response.getOutputStream()).willReturn(outputStream); given(inputStream.read(Mockito.any(byte[].class))).willReturn(1, -1); underTest.writeResourceFile(response, PATH_INFO, path); verify(response).setContentType(TEXT); verify(response).setHeader(CONTENT_DISPOSITION, "attachment;filename=" + FILE_NAME); }
public void writeResourceFile(final HttpServletResponse resp, final String path, final Path filePath) throws IOException { String requestedFilename = path.substring(1); InputStream messageFileInputStream = fileReader.readFile(requestedFilename, filePath); if (messageFileExists(messageFileInputStream)) { writeResourceFileInResponse(resp, requestedFilename, messageFileInputStream); } else { writeErrorToResponse(resp); } }
ResourceFileNameHandler { public void writeResourceFile(final HttpServletResponse resp, final String path, final Path filePath) throws IOException { String requestedFilename = path.substring(1); InputStream messageFileInputStream = fileReader.readFile(requestedFilename, filePath); if (messageFileExists(messageFileInputStream)) { writeResourceFileInResponse(resp, requestedFilename, messageFileInputStream); } else { writeErrorToResponse(resp); } } }
ResourceFileNameHandler { public void writeResourceFile(final HttpServletResponse resp, final String path, final Path filePath) throws IOException { String requestedFilename = path.substring(1); InputStream messageFileInputStream = fileReader.readFile(requestedFilename, filePath); if (messageFileExists(messageFileInputStream)) { writeResourceFileInResponse(resp, requestedFilename, messageFileInputStream); } else { writeErrorToResponse(resp); } }  }
ResourceFileNameHandler { public void writeResourceFile(final HttpServletResponse resp, final String path, final Path filePath) throws IOException { String requestedFilename = path.substring(1); InputStream messageFileInputStream = fileReader.readFile(requestedFilename, filePath); if (messageFileExists(messageFileInputStream)) { writeResourceFileInResponse(resp, requestedFilename, messageFileInputStream); } else { writeErrorToResponse(resp); } }  void writeResourceFile(final HttpServletResponse resp, final String path, final Path filePath); }
ResourceFileNameHandler { public void writeResourceFile(final HttpServletResponse resp, final String path, final Path filePath) throws IOException { String requestedFilename = path.substring(1); InputStream messageFileInputStream = fileReader.readFile(requestedFilename, filePath); if (messageFileExists(messageFileInputStream)) { writeResourceFileInResponse(resp, requestedFilename, messageFileInputStream); } else { writeErrorToResponse(resp); } }  void writeResourceFile(final HttpServletResponse resp, final String path, final Path filePath);  }