Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 134ba158fb4a585930e09225ac07a9315e67e02a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2000, 2009 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     QNX Software Systems - Initial API and implementation
 *******************************************************************************/

package org.eclipse.cdt.core;

import java.io.IOException;
import java.io.OutputStream;


/**
 * Output stream which storing the console output
 * 
 * @noinstantiate This class is not intended to be instantiated by clients.
 */
public class ConsoleOutputStream extends OutputStream {
	
	protected StringBuffer fBuffer;
		
	public ConsoleOutputStream() {
		fBuffer= new StringBuffer();
	}

	public synchronized String readBuffer() {
		String buf = fBuffer.toString();
		fBuffer.setLength(0);
		return buf;
	}

	@Override
	public synchronized void write(int c) throws IOException {
		byte ascii[] = new byte[1];
		ascii[0] = (byte) c;
		fBuffer.append(new String(ascii));
	}
	    
    @Override
	public synchronized void write(byte[] b, int off, int len) throws IOException {
        fBuffer.append(new String(b, off, len));
    }
    
    /**
	 * @since 6.0
	 */
    public synchronized void write(String msg) throws IOException {
    	fBuffer.append(msg);
    }

}

Back to the top