Browse Source

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
master
Magesh Umasankar 23 years ago
parent
commit
4a5b5fd1ea
3 changed files with 17 additions and 8 deletions
  1. +13
    -6
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
  2. +2
    -1
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java
  3. +2
    -1
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java

+ 13
- 6
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java View File

@@ -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) { if (primaryReader == null) {
throw new BuildException("primaryReader must not be null."); throw new BuildException("primaryReader must not be null.");
} }


Reader instream = primaryReader; Reader instream = primaryReader;
final char[] buffer = new char[bufferSize];
final int filterReadersCount = filterChains.size(); final int filterReadersCount = filterChains.size();
final Vector finalFilters = new Vector(); 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; int bufferLength = 0;
String text = null; String text = null;
while (bufferLength != -1) { while (bufferLength != -1) {
bufferLength = instream.read(buffer);
bufferLength = rdr.read(buffer);
if (bufferLength != -1) { if (bufferLength != -1) {
if (text == null) { if (text == null) {
text = new String(buffer, 0, bufferLength); text = new String(buffer, 0, bufferLength);


+ 2
- 1
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java View File

@@ -194,8 +194,9 @@ public final class LoadFile extends Task {
crh.setBufferSize(size); crh.setBufferSize(size);
crh.setPrimaryReader(instream); crh.setPrimaryReader(instream);
crh.setFilterChains(filterChains); crh.setFilterChains(filterChains);
instream = crh.getAssembledReader();


String text = crh.processStream();
String text = crh.readFully(instream);


if (text != null) { if (text != null) {
if(evaluateProperties) { if(evaluateProperties) {


+ 2
- 1
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java View File

@@ -128,8 +128,9 @@ public final class LoadProperties extends Task {
crh.setBufferSize(size); crh.setBufferSize(size);
crh.setPrimaryReader(instream); crh.setPrimaryReader(instream);
crh.setFilterChains(filterChains); crh.setFilterChains(filterChains);
instream = crh.getAssembledReader();


String text = crh.processStream();
String text = crh.readFully(instream);


if (text != null) { if (text != null) {
if (!text.endsWith("\n")) { if (!text.endsWith("\n")) {


Loading…
Cancel
Save