From a89dedbb23e84e3112f8464a339d6d50fc8f02c6 Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Fri, 11 Mar 2022 17:02:47 +0100 Subject: [PATCH] Add toString #2515 (#2516) Signed-off-by: Arjan Tijms --- .../piranha/resource/impl/AliasedNamedResource.java | 9 +++++++-- .../piranha/resource/impl/ByteArrayResource.java | 13 ++++++++++++- .../cloud/piranha/resource/impl/ClassResource.java | 13 ++++++++++++- .../piranha/resource/impl/DirectoryResource.java | 11 ++++++++--- .../cloud/piranha/resource/impl/JarResource.java | 8 +++++++- .../piranha/resource/impl/MultiReleaseResource.java | 9 +++++++-- .../piranha/resource/impl/PrefixJarResource.java | 10 ++++++++-- 7 files changed, 61 insertions(+), 12 deletions(-) diff --git a/resource/impl/src/main/java/cloud/piranha/resource/impl/AliasedNamedResource.java b/resource/impl/src/main/java/cloud/piranha/resource/impl/AliasedNamedResource.java index 02d700baa2..441b0b1043 100644 --- a/resource/impl/src/main/java/cloud/piranha/resource/impl/AliasedNamedResource.java +++ b/resource/impl/src/main/java/cloud/piranha/resource/impl/AliasedNamedResource.java @@ -27,12 +27,12 @@ */ package cloud.piranha.resource.impl; -import cloud.piranha.resource.api.Resource; - import java.io.InputStream; import java.net.URL; import java.util.stream.Stream; +import cloud.piranha.resource.api.Resource; + /** * A {@link Resource} wrapper with a custom name */ @@ -78,4 +78,9 @@ public String getName() { return resourceName; } + @Override + public String toString() { + return getName() + " " + super.toString(); + } + } diff --git a/resource/impl/src/main/java/cloud/piranha/resource/impl/ByteArrayResource.java b/resource/impl/src/main/java/cloud/piranha/resource/impl/ByteArrayResource.java index 97583e5218..fe13b11d23 100644 --- a/resource/impl/src/main/java/cloud/piranha/resource/impl/ByteArrayResource.java +++ b/resource/impl/src/main/java/cloud/piranha/resource/impl/ByteArrayResource.java @@ -27,13 +27,14 @@ */ package cloud.piranha.resource.impl; -import cloud.piranha.resource.api.Resource; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.stream.Stream; +import cloud.piranha.resource.api.Resource; + /** * The byte-array resource. * @@ -163,4 +164,14 @@ private String getLocationFromUrl(String url) { } + @Override + public String getName() { + return location; + } + + @Override + public String toString() { + return getName() + " " + super.toString(); + } + } diff --git a/resource/impl/src/main/java/cloud/piranha/resource/impl/ClassResource.java b/resource/impl/src/main/java/cloud/piranha/resource/impl/ClassResource.java index d0836cb060..b4b036de10 100644 --- a/resource/impl/src/main/java/cloud/piranha/resource/impl/ClassResource.java +++ b/resource/impl/src/main/java/cloud/piranha/resource/impl/ClassResource.java @@ -27,12 +27,13 @@ */ package cloud.piranha.resource.impl; -import cloud.piranha.resource.api.Resource; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.stream.Stream; +import cloud.piranha.resource.api.Resource; + /** * A resource backed by a class. * @@ -84,4 +85,14 @@ public Stream getAllLocations() { } return result.stream(); } + + @Override + public String getName() { + return location; + } + + @Override + public String toString() { + return getName() + " " + super.toString(); + } } diff --git a/resource/impl/src/main/java/cloud/piranha/resource/impl/DirectoryResource.java b/resource/impl/src/main/java/cloud/piranha/resource/impl/DirectoryResource.java index 4d3d84a122..370d04984f 100644 --- a/resource/impl/src/main/java/cloud/piranha/resource/impl/DirectoryResource.java +++ b/resource/impl/src/main/java/cloud/piranha/resource/impl/DirectoryResource.java @@ -30,8 +30,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; @@ -59,7 +59,7 @@ public class DirectoryResource implements Resource { */ public DirectoryResource() { } - + /** * Constructor. * @@ -115,7 +115,7 @@ public InputStream getResourceAsStream(String location) { return result; } - + @Override public Stream getAllLocations() { try { @@ -152,4 +152,9 @@ public String getName() { return rootDirectory.getName(); } + @Override + public String toString() { + return getName() + " " + super.toString(); + } + } diff --git a/resource/impl/src/main/java/cloud/piranha/resource/impl/JarResource.java b/resource/impl/src/main/java/cloud/piranha/resource/impl/JarResource.java index 82bcf5907a..46bd06efc1 100644 --- a/resource/impl/src/main/java/cloud/piranha/resource/impl/JarResource.java +++ b/resource/impl/src/main/java/cloud/piranha/resource/impl/JarResource.java @@ -27,7 +27,6 @@ */ package cloud.piranha.resource.impl; -import cloud.piranha.resource.api.Resource; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -41,6 +40,8 @@ import java.util.stream.Stream; import java.util.zip.ZipEntry; +import cloud.piranha.resource.api.Resource; + /** * The default JarResource. * @@ -155,4 +156,9 @@ public void setJarFile(File jarFile) { public String getName() { return jarFile.getName(); } + + @Override + public String toString() { + return getName() + " " + super.toString(); + } } diff --git a/resource/impl/src/main/java/cloud/piranha/resource/impl/MultiReleaseResource.java b/resource/impl/src/main/java/cloud/piranha/resource/impl/MultiReleaseResource.java index ec9958142f..b0c8cd204c 100644 --- a/resource/impl/src/main/java/cloud/piranha/resource/impl/MultiReleaseResource.java +++ b/resource/impl/src/main/java/cloud/piranha/resource/impl/MultiReleaseResource.java @@ -27,8 +27,6 @@ */ package cloud.piranha.resource.impl; -import cloud.piranha.resource.api.Resource; - import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -38,6 +36,8 @@ import java.util.stream.IntStream; import java.util.stream.Stream; +import cloud.piranha.resource.api.Resource; + /** * A resource wrapper that loads the versioned entries from META-INF/versions if * the resource contains a main attribute named "Multi-Release" in the META-INF/MANIFEST.MF @@ -148,4 +148,9 @@ public Stream getAllLocations() { public String getName() { return resource.getName(); } + + @Override + public String toString() { + return getName() + " " + super.toString(); + } } diff --git a/resource/impl/src/main/java/cloud/piranha/resource/impl/PrefixJarResource.java b/resource/impl/src/main/java/cloud/piranha/resource/impl/PrefixJarResource.java index c4af5e7485..3532ea01d0 100644 --- a/resource/impl/src/main/java/cloud/piranha/resource/impl/PrefixJarResource.java +++ b/resource/impl/src/main/java/cloud/piranha/resource/impl/PrefixJarResource.java @@ -27,7 +27,6 @@ */ package cloud.piranha.resource.impl; -import cloud.piranha.resource.api.Resource; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -36,6 +35,8 @@ import java.util.jar.JarFile; import java.util.stream.Stream; +import cloud.piranha.resource.api.Resource; + /** * The default PrefixJarResource. * @@ -113,7 +114,7 @@ public InputStream getResourceAsStream(String location) { } return result; } - + @Override public Stream getAllLocations() { return Stream.empty(); @@ -159,4 +160,9 @@ public String getName() { return jarFile.getName(); } + @Override + public String toString() { + return getName() + " " + super.toString(); + } + }