You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/06/18 14:01:26 UTC

[sling-org-apache-sling-feature-inventoryprinter] 01/01: @trivial do not store the whole 'sling.feature' file in memory, before to transfer it to the PrintWriter

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

simonetripodi pushed a commit to branch optimized_writer
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-inventoryprinter.git

commit 8ad41209c7cdeabe20b7d6bd772acaa2a42c46a9
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Tue Jun 18 16:00:59 2019 +0200

    @trivial do not store the whole 'sling.feature' file in memory, before
    to transfer it to the PrintWriter
---
 .../impl/FeaturesInventoryPrinter.java             | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java b/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java
index ac9710c..5512433 100644
--- a/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java
+++ b/src/main/java/org/apache/sling/feature/inventoryservice/impl/FeaturesInventoryPrinter.java
@@ -18,18 +18,20 @@
  */
 package org.apache.sling.feature.inventoryservice.impl;
 
-import org.apache.felix.inventory.Format;
-import org.apache.felix.inventory.InventoryPrinter;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-
+import java.io.BufferedReader;
 import java.io.PrintWriter;
 import java.net.URI;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 
+import org.apache.felix.inventory.Format;
+import org.apache.felix.inventory.InventoryPrinter;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+
 @Component(
 property = {InventoryPrinter.NAME + "=launch_feature",
         InventoryPrinter.TITLE + "=Launch Feature",
@@ -43,8 +45,12 @@ public class FeaturesInventoryPrinter implements InventoryPrinter
     public void print(PrintWriter printWriter, Format format, boolean isZip) {
         try {
             Path path = Paths.get(new URI(bc.getProperty("sling.feature")));
-            byte[] bytes = Files.readAllBytes(path);
-            printWriter.print(new String(bytes));
+            try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
+                String line = null;
+                while ((line = reader.readLine()) != null) {
+                    printWriter.println(line);
+                }
+            }
         } catch (Exception e) {
             e.printStackTrace(printWriter);
         }