protected InputStream loadPath(final org.uberfire.java.nio.file.Path _path) { final byte[] bytes = getIoService().readAllBytes(_path); return new ByteArrayInputStream(bytes); }
protected InputStream loadPath(final org.uberfire.backend.vfs.Path _path) { org.uberfire.java.nio.file.Path path = Paths.convert(_path); final byte[] bytes = getIoService().readAllBytes(path); return new ByteArrayInputStream(bytes); }
@Override public byte[] readAllBytes(Path path) throws IOException, OutOfMemoryError, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } return service.readAllBytes(path); }
@Override public byte[] readAllBytes(Path path) throws IOException, OutOfMemoryError, SecurityException { if (!authManager.authorize(toResource(path), getUser())) { throw new SecurityException(); } return service.readAllBytes(path); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { final URI uri = makeURI(request.getParameter("path")); if (!validateAccess(uri, response)) { return; } final Path path = ioService.get(uri); byte[] bytes = ioService.readAllBytes(path); response.setHeader("Content-Disposition", format("attachment; filename=\"%s\";", path.getFileName().toString())); response.setContentType("application/octet-stream"); response.getOutputStream().write( bytes, 0, bytes.length); } catch (final Exception e) { logger.error("Failed to download a file.", e); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { final URI uri = makeURI(request.getParameter("path")); if (!validateAccess(uri, response)) { return; } final Path path = ioService.get(uri); byte[] bytes = ioService.readAllBytes(path); response.setHeader("Content-Disposition", format("attachment; filename=\"%s\";", path.getFileName().toString())); response.setContentType("application/octet-stream"); response.getOutputStream().write( bytes, 0, bytes.length); } catch (final Exception e) { logger.error("Failed to download a file.", e); } }
@Override public byte[] loadFile( final Path file ) throws FileException { if (!isActive()) { return new byte[0]; } checkNotNull( "file", file ); try { return getIOService().readAllBytes( file ); } catch ( IOException ex ) { throw new FileException( ex.getMessage(), ex ); } }
when(ioService.readAllBytes(path)).thenReturn(fileContent.getBytes()); times(1)).get(eq(expectedURI)); verify(ioService, times(1)).readAllBytes(eq(path));
when(ioService.readAllBytes(path)).thenReturn(fileContent.getBytes()); times(1)).get(eq(expectedURI)); verify(ioService, times(1)).readAllBytes(eq(path));
@Override public byte[] loadFile(Path file) throws FileException { checkNotNull( "file", file ); try { return ioService.readAllBytes( file ); } catch ( IOException ex ) { throw new FileException( ex.getMessage(), ex ); } }
protected Path mockGetDiagramByPathObjects() { final Path path = mock(Path.class); final String fileName = FILE_NAME + "." + RESOURCE_TYPE_SUFFIX; when(path.toURI()).thenReturn(FILE_URI); when(path.getFileName()).thenReturn(fileName); final org.uberfire.java.nio.file.Path expectedNioPath = Paths.convert(path); final byte[] content = DIAGRAM_MARSHALLED.getBytes(); when(resourceType.accept(path)).thenReturn(true); when(ioService.readAllBytes(expectedNioPath)).thenReturn(content); return path; }