From ade0b033e372b018de5ed333904223d4a8e0ef80 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 19 Nov 2008 08:38:51 +0000 Subject: [PATCH] appending may be a bad thing to do for compressed outputs and other subclasses git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@718904 13f79535-47bb-0310-9956-ffa450edef68 --- .../ContentTransformingResource.java | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java b/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java index 2b9d412be..d41a1d5b2 100644 --- a/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java +++ b/src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java @@ -115,19 +115,21 @@ public abstract class ContentTransformingResource extends ResourceDecorator { */ public Object as(Class clazz) { if (Appendable.class.isAssignableFrom(clazz)) { - final Appendable a = - (Appendable) getResource().as(Appendable.class); - if (a != null) { - return new Appendable() { - public OutputStream getAppendOutputStream() - throws IOException { - OutputStream out = a.getAppendOutputStream(); - if (out != null) { - out = wrapStream(out); + if (isAppendSupported()) { + final Appendable a = + (Appendable) getResource().as(Appendable.class); + if (a != null) { + return new Appendable() { + public OutputStream getAppendOutputStream() + throws IOException { + OutputStream out = a.getAppendOutputStream(); + if (out != null) { + out = wrapStream(out); + } + return out; } - return out; - } - }; + }; + } } return null; } @@ -136,6 +138,18 @@ public abstract class ContentTransformingResource extends ResourceDecorator { ? null : getResource().as(clazz); } + /** + * whether the transformation performed allows appends. + * + *

In general compressed outputs will become invalid if they + * are appended to, for example.

+ * + *

This implementations returns false.

+ */ + protected boolean isAppendSupported() { + return false; + } + /** * Is supposed to wrap the stream. *