This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-get.git


The following commit(s) were added to refs/heads/master by this push:
     new 926b016  SLING-7795 wrapped the acquisition of the JsonGenerator
926b016 is described below

commit 926b016df1a9418030fe47916d26161094bcb3a9
Author: JE Bailey <[email protected]>
AuthorDate: Thu Jul 19 11:14:06 2018 -0400

    SLING-7795 wrapped the acquisition of the JsonGenerator
    
    Used a try with resources.
---
 .../sling/servlets/get/impl/SlingInfoServlet.java     |  7 ++-----
 .../sling/servlets/get/impl/helpers/JsonRenderer.java | 19 +++++++++++--------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java 
b/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java
index 9f3e470..b9166db 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java
@@ -110,9 +110,7 @@ public class SlingInfoServlet extends 
SlingSafeMethodsServlet {
         response.setCharacterEncoding("UTF-8");
 
         final Writer out = response.getWriter();
-        final JsonGenerator w = Json.createGenerator(out);
-
-        try {
+        try (JsonGenerator w = Json.createGenerator(out)){
             w.writeStartObject();
             for (final Map.Entry<String, String> e : data.entrySet()) {
                 w.write(e.getKey(), e.getValue());
@@ -120,9 +118,8 @@ public class SlingInfoServlet extends 
SlingSafeMethodsServlet {
             w.writeEnd();
         } catch (JsonException jse) {
             out.write(jse.toString());
-            out.flush();
         } finally {
-            w.flush();
+            out.flush();
         }
     }
 
diff --git 
a/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRenderer.java 
b/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRenderer.java
index dbfbcf2..2fff1b8 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRenderer.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRenderer.java
@@ -115,7 +115,9 @@ public class JsonRenderer implements Renderer {
                     // backwards compatibility. Output might be slightly 
different
                     // with prettyPrint and no options
                     StringWriter writer = new StringWriter();
-                    
Json.createGenerator(writer).write(traversor.getJSONObject()).close();
+                    try (JsonGenerator json = Json.createGenerator(writer)){
+                        json.write(traversor.getJSONObject());
+                    }
                     resp.getWriter().write(writer.toString());
                 }
 
@@ -125,14 +127,15 @@ public class JsonRenderer implements Renderer {
                 String tidyUrl = (tidy) ? "tidy." : "";
                 resp.setStatus(HttpServletResponse.SC_MULTIPLE_CHOICES);
                 StringWriter writer = new StringWriter();
-                JsonGenerator json = Json.createGenerator(writer);
-                json.writeStartArray();
-                while (allowedLevel >= 0) {
-                    json.write(r.getResourceMetadata().getResolutionPath() + 
"." + tidyUrl + allowedLevel + ".json");
-                    allowedLevel--;
+                try (JsonGenerator json = Json.createGenerator(writer)) {
+                    json.writeStartArray();
+                    while (allowedLevel >= 0) {
+                        json.write(
+                                r.getResourceMetadata().getResolutionPath() + 
"." + tidyUrl + allowedLevel + ".json");
+                        allowedLevel--;
+                    }
+                    json.writeEnd();
                 }
-                json.writeEnd();
-                json.close();
                 resp.getWriter().write(writer.toString());
             }
         } catch (Exception je) {

Reply via email to