Repository: incubator-nifi Updated Branches: refs/heads/NIFI-353 36f11c3d9 -> 7fc79a34b
NIFI-353: - Only showing up to 1.5kb of the content in the hex view. Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/7fc79a34 Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/7fc79a34 Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/7fc79a34 Branch: refs/heads/NIFI-353 Commit: 7fc79a34b7bee4b92988a36c64f8585b7fec8d33 Parents: 36f11c3 Author: Matt Gilman <[email protected]> Authored: Sun Mar 22 22:40:51 2015 -0400 Committer: Matt Gilman <[email protected]> Committed: Sun Mar 22 22:40:51 2015 -0400 ---------------------------------------------------------------------- .../nifi-web/nifi-web-content-viewer/pom.xml | 5 +++++ .../apache/nifi/web/ContentViewerController.java | 17 +++++++++++++++-- .../src/main/webapp/WEB-INF/jsp/hexview.jsp | 3 ++- .../src/main/webapp/css/main.css | 9 +++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/7fc79a34/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml index cfce60a..75464c2 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/pom.xml @@ -33,6 +33,11 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-utils</artifactId> + <scope>provided</scope> + </dependency> + <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <scope>provided</scope> http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/7fc79a34/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java index 09d620c..d9b082d 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/java/org/apache/nifi/web/ContentViewerController.java @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.stream.io.StreamUtils; import org.apache.nifi.web.ViewableContent.DisplayMode; import org.apache.tika.detect.DefaultDetector; import org.apache.tika.io.TikaInputStream; @@ -50,6 +51,9 @@ public class ContentViewerController extends HttpServlet { private static final Logger logger = LoggerFactory.getLogger(ContentViewerController.class); + // 1.5kb - multiple of 12 (3 bytes = 4 base 64 encoded chars) + private final static int BUFFER_LENGTH = 1536; + /** * Gets the content and defers to registered viewers to generate the markup. * @@ -151,8 +155,17 @@ public class ContentViewerController extends HttpServlet { // generate the markup for the content based on the display mode if (DisplayMode.Hex.equals(displayMode)) { - // convert stream into the base 64 bytes - final byte[] bytes = IOUtils.toByteArray(bis); + final byte[] buffer = new byte[BUFFER_LENGTH]; + final int read = StreamUtils.fillBuffer(bis, buffer, false); + + // trim the byte array if necessary + byte[] bytes = buffer; + if (read != buffer.length) { + bytes = new byte[read]; + System.arraycopy(buffer, 0, bytes, 0, read); + } + + // convert bytes into the base 64 bytes final String base64 = Base64.encodeBase64String(bytes); // defer to the jsp http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/7fc79a34/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp index 872d8ea..c6e7f38 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/WEB-INF/jsp/hexview.jsp @@ -28,4 +28,5 @@ <input type="hidden" name="hide_0x" value="1" /> <input type="hidden" name="caption" value="" /> </form> -</div> \ No newline at end of file +</div> +<div id="trancation-message">Showing up to 1.5kb</div> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/7fc79a34/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/css/main.css ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/css/main.css b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/css/main.css index 124f69d..a66198d 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/css/main.css +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-content-viewer/src/main/webapp/css/main.css @@ -87,6 +87,15 @@ padding: 2px; } +#trancation-message { + position: absolute; + left: 100px; + bottom: 35px; + color: #666; + font-style: italic; + font-size: 11px; +} + /* no viewer */ #no-viewer {
