com.pagecrumb.proxy.wrapper.StringOutputStream.java Source code

Java tutorial

Introduction

Here is the source code for com.pagecrumb.proxy.wrapper.StringOutputStream.java

Source

/**
 *    
 * Copyright 2013 Pagecrumb
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *  
 */
package com.pagecrumb.proxy.wrapper;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Utility class to output stream a String.
 * @author kerby
 *
 */
public class StringOutputStream extends OutputStream {

    protected final Log log = LogFactory.getLog(getClass());

    StringBuilder sb = new StringBuilder();

    @Override
    public void write(int b) throws IOException {
        sb.append((char) b);
        Character c = new Character((char) b);
        //log.debug(c.toString());
        //log.debug(sb.toString()); // progressive logging
    }

    @Override
    public void flush() throws IOException {
        super.flush();
        log.debug("flush()");
    }

    @Override
    public void close() throws IOException {
        super.close();
        log.debug("close()");
    }

    @Override
    public String toString() {
        return sb.toString();
    }
}