From 4a5b5fd1eab32cc1cd411ce8adbe76292040b039 Mon Sep 17 00:00:00 2001 From: Magesh Umasankar Date: Thu, 28 Feb 2002 19:43:01 +0000 Subject: [PATCH] Split processStream into two methods to facilitate streamed reads... Reader getAssembledReader() String readFully(Reader) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271613 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/filters/util/ChainReaderHelper.java | 19 +++++++++++++------ .../apache/tools/ant/taskdefs/LoadFile.java | 3 ++- .../tools/ant/taskdefs/LoadProperties.java | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java index 0a1a7ba38..b3c099adb 100644 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java +++ b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java @@ -114,17 +114,14 @@ public final class ChainReaderHelper { } /** - * Process the reader chain + * Assemble the reader */ - public final String processStream() - throws BuildException, IOException { - + public final Reader getAssembledReader() throws BuildException { if (primaryReader == null) { throw new BuildException("primaryReader must not be null."); } Reader instream = primaryReader; - final char[] buffer = new char[bufferSize]; final int filterReadersCount = filterChains.size(); final Vector finalFilters = new Vector(); @@ -201,11 +198,21 @@ public final class ChainReaderHelper { } } } + return instream; + } + /** + * Read data from the reader and return the + * contents as a string. + */ + public final String readFully(Reader rdr) + throws IOException { + + final char[] buffer = new char[bufferSize]; int bufferLength = 0; String text = null; while (bufferLength != -1) { - bufferLength = instream.read(buffer); + bufferLength = rdr.read(buffer); if (bufferLength != -1) { if (text == null) { text = new String(buffer, 0, bufferLength); diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java index 66f7c3b8c..7f6222440 100644 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java +++ b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java @@ -194,8 +194,9 @@ public final class LoadFile extends Task { crh.setBufferSize(size); crh.setPrimaryReader(instream); crh.setFilterChains(filterChains); + instream = crh.getAssembledReader(); - String text = crh.processStream(); + String text = crh.readFully(instream); if (text != null) { if(evaluateProperties) { diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java index 5e0c4a4ec..ca5b07527 100644 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java +++ b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java @@ -128,8 +128,9 @@ public final class LoadProperties extends Task { crh.setBufferSize(size); crh.setPrimaryReader(instream); crh.setFilterChains(filterChains); + instream = crh.getAssembledReader(); - String text = crh.processStream(); + String text = crh.readFully(instream); if (text != null) { if (!text.endsWith("\n")) {