1
/* *******************************************************************
2
* Copyright (c) 1999-2001 Xerox Corporation,
3
* 2002 Palo Alto Research Center, Incorporated (PARC).
5
* This program and the accompanying materials are made available
6
* under the terms of the Eclipse Public License v1.0
7
* which accompanies this distribution and is available at
8
* http://www.eclipse.org/legal/epl-v10.html
11
* Xerox/PARC initial implementation
12
* ******************************************************************/
16
* StreamGrabber.java created on May 16, 2002
19
package org.aspectj.testing.util;
21
import java.io.FilterOutputStream;
22
import java.io.IOException;
23
import java.io.OutputStream;
26
* Listen to a stream using StringBuffer.
27
* Clients install and remove buffer to enable/disable listening.
28
* Does not affect data passed to underlying stream
30
public class StreamSniffer extends FilterOutputStream {
32
/** have to use delegate, not super, because super we will double-count input */
33
final OutputStream delegate;
35
public StreamSniffer(OutputStream stream) {
40
/** set to null to stop copying */
41
public void setBuffer(StringBuffer sb) {
45
//---------------- FilterOutputStream
46
public void write(int b) throws IOException {
47
StringBuffer sb = buffer;
49
if ((b > Character.MAX_VALUE)
50
|| (b < Character.MIN_VALUE)) {
51
throw new Error("don't know double-byte"); // XXX
59
public void write(byte[] b) throws IOException {
60
StringBuffer sb = buffer;
62
String s = new String(b);
68
public void write(byte[] b, int offset, int length) throws IOException {
69
StringBuffer sb = buffer;
71
String s = new String(b, offset, length);
74
delegate.write(b, offset, length);