From 48d594c8454b3ef0cf7cb0ed21d0cc1b5184e5a7 Mon Sep 17 00:00:00 2001 From: Antonio Goncalves Date: Wed, 21 Jun 2023 17:59:12 +0200 Subject: [PATCH] Adds Commons IO rule (#994) --- .../cloud-readiness/local-storage.windup.xml | 38 +++++++++++++++++++ .../cloud-readiness/tests/data/CommonIO.java | 17 +++++++++ .../tests/local-storage.windup.test.xml | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 rules/rules-reviewed/cloud-readiness/tests/data/CommonIO.java diff --git a/rules/rules-reviewed/cloud-readiness/local-storage.windup.xml b/rules/rules-reviewed/cloud-readiness/local-storage.windup.xml index 1ba74c628..fc7416317 100644 --- a/rules/rules-reviewed/cloud-readiness/local-storage.windup.xml +++ b/rules/rules-reviewed/cloud-readiness/local-storage.windup.xml @@ -213,5 +213,43 @@ + + + + + IMPORT + + + IMPORT + + + + + + + + An application running inside a container could lose access to a file in local storage. + + Recommendations + + The following recommendations depend on the function of the file in local storage: + + * Logging: Log to standard output and use a centralized log collector to analyze the logs. + * Caching: Use a cache backing service. + * Configuration: Store configuration settings in environment variables so that they can be updated without code changes. + * Data storage: Use a database backing service for relational data or use a persistent data storage system. + * Temporary data storage: Use the file system of a running container as a brief, single-transaction cache. + + + + + + + + storage + + + + diff --git a/rules/rules-reviewed/cloud-readiness/tests/data/CommonIO.java b/rules/rules-reviewed/cloud-readiness/tests/data/CommonIO.java new file mode 100644 index 000000000..d588c4fc3 --- /dev/null +++ b/rules/rules-reviewed/cloud-readiness/tests/data/CommonIO.java @@ -0,0 +1,17 @@ +import org.apache.commons.io.input.TeeInputStream; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.commons.io.output.TeeOutputStream; + +public class CommonsIO { + + public static void main(String[] args) throws IOException { + String str = "Hello World."; + ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes()); + ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); + ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream(); + + FilterOutputStream teeOutputStream + = new TeeOutputStream(outputStream1, outputStream2); + new TeeInputStream(inputStream, teeOutputStream, true).read(new byte[str.length()]); + } +} diff --git a/rules/rules-reviewed/cloud-readiness/tests/local-storage.windup.test.xml b/rules/rules-reviewed/cloud-readiness/tests/local-storage.windup.test.xml index 55344ada1..8c86ad9e9 100644 --- a/rules/rules-reviewed/cloud-readiness/tests/local-storage.windup.test.xml +++ b/rules/rules-reviewed/cloud-readiness/tests/local-storage.windup.test.xml @@ -8,7 +8,7 @@ - +