Browse Source

Implement array writes for output processing

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274847 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
d91a1b5a98
2 changed files with 60 additions and 2 deletions
  1. +30
    -1
      src/main/org/apache/tools/ant/DemuxOutputStream.java
  2. +30
    -1
      src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java

+ 30
- 1
src/main/org/apache/tools/ant/DemuxOutputStream.java View File

@@ -89,6 +89,9 @@ public class DemuxOutputStream extends OutputStream {
/** Maximum buffer size. */ /** Maximum buffer size. */
private static final int MAX_SIZE = 1024; private static final int MAX_SIZE = 1024;


/** Initial buffer size. */
private static final int INTIAL_SIZE = 132;

/** Mapping from thread to buffer (Thread to BufferInfo). */ /** Mapping from thread to buffer (Thread to BufferInfo). */
private Hashtable buffers = new Hashtable(); private Hashtable buffers = new Hashtable();


@@ -127,7 +130,7 @@ public class DemuxOutputStream extends OutputStream {
BufferInfo bufferInfo = (BufferInfo) buffers.get(current); BufferInfo bufferInfo = (BufferInfo) buffers.get(current);
if (bufferInfo == null) { if (bufferInfo == null) {
bufferInfo = new BufferInfo(); bufferInfo = new BufferInfo();
bufferInfo.buffer = new ByteArrayOutputStream();
bufferInfo.buffer = new ByteArrayOutputStream(INTIAL_SIZE);
bufferInfo.crSeen = false; bufferInfo.crSeen = false;
buffers.put(current, bufferInfo); buffers.put(current, bufferInfo);
} }
@@ -239,4 +242,30 @@ public class DemuxOutputStream extends OutputStream {
processFlush(bufferInfo.buffer); processFlush(bufferInfo.buffer);
} }
} }

public void write(byte b[], int off, int len) throws IOException {
// find the line breaks and pass other chars through in blocks
int offset = off;
int blockStartOffset = offset;
int remaining = len;
BufferInfo bufferInfo = getBufferInfo();
while (remaining > 0) {
while (remaining > 0 && b[offset] != 0x0a && b[offset] != 0x0d) {
offset++;
remaining--;
}
// either end of buffer or a line separator char
int blockLength = offset - blockStartOffset;
if (blockLength > 0) {
project.log("Sending " + blockLength);
bufferInfo.buffer.write(b, blockStartOffset, blockLength);
}
while(remaining > 0 && (b[offset] == 0x0a || b[offset] == 0x0d)) {
write(b[offset]);
offset++;
remaining--;
}
blockStartOffset = offset;
}
}
} }

+ 30
- 1
src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java View File

@@ -73,7 +73,11 @@ import org.apache.tools.ant.Task;
*/ */
public class LogOutputStream extends OutputStream { public class LogOutputStream extends OutputStream {


private ByteArrayOutputStream buffer = new ByteArrayOutputStream();
/** Initial buffer size. */
private static final int INTIAL_SIZE = 132;

private ByteArrayOutputStream buffer
= new ByteArrayOutputStream(INTIAL_SIZE);
private boolean skip = false; private boolean skip = false;


private Task task; private Task task;
@@ -157,4 +161,29 @@ public class LogOutputStream extends OutputStream {
public int getMessageLevel() { public int getMessageLevel() {
return level; return level;
} }

public void write(byte b[], int off, int len) throws IOException {
// find the line breaks and pass other chars through in blocks
int offset = off;
int blockStartOffset = offset;
int remaining = len;
while (remaining > 0) {
while (remaining > 0 && b[offset] != 0x0a && b[offset] != 0x0d) {
offset++;
remaining--;
}
// either end of buffer or a line separator char
int blockLength = offset - blockStartOffset;
if (blockLength > 0) {
buffer.write(b, blockStartOffset, blockLength);
}
while(remaining > 0 && (b[offset] == 0x0a || b[offset] == 0x0d)) {
write(b[offset]);
offset++;
remaining--;
}
blockStartOffset = offset;
}
}

} }

Loading…
Cancel
Save