All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.geronimo.javamail.util.TraceOutputStream Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.geronimo.javamail.util;

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

import org.apache.geronimo.mail.util.QuotedPrintableEncoderStream;

/**
 * @version $Rev: 437941 $ $Date: 2006-08-28 23:56:02 -0400 (Mon, 28 Aug 2006) $
 */
public class TraceOutputStream extends FilterOutputStream {
    // the current debug setting
    protected boolean debug = false;

    // the target trace output stream.
    protected OutputStream traceStream;

    /**
     * Construct a debug trace stream.
     *
     * @param out
     *            The target out put stream.
     * @param traceStream
     *            The side trace stream to which trace data gets written.
     * @param encode
     *            Indicates whether we wish the Trace data to be Q-P encoded.
     */
    public TraceOutputStream(OutputStream out, OutputStream traceStream, boolean debug, boolean encode) {
        super(out);
        this.debug = debug;
        if (encode) {
            this.traceStream = new QuotedPrintableEncoderStream(traceStream);
        } else {
            this.traceStream = traceStream;
        }
    }

    /**
     * Set the current setting of the debug trace stream debug flag.
     *
     * @param d
     *            The new debug flag settings.
     */
    public void setDebug(boolean d) {
        debug = d;
    }


    /**
     * Writes the specified byte to this output stream.
     * 

* The write method of FilterOutputStream * calls the write method of its underlying output stream, * that is, it performs out.write(b). *

* Implements the abstract write method of OutputStream. * * @param b * the byte. * @exception IOException * if an I/O error occurs. */ public void write(int b) throws IOException { if (debug) { traceStream.write(b); } super.write(b); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy