1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.geronimo.javamail.util; 21 22 import java.io.FilterOutputStream; 23 import java.io.IOException; 24 import java.io.OutputStream; 25 26 import org.apache.geronimo.mail.util.QuotedPrintableEncoderStream; 27 28 /** 29 * @version $Rev: 668615 $ $Date: 2008-06-17 07:06:18 -0400 (Tue, 17 Jun 2008) $ 30 */ 31 public class TraceOutputStream extends FilterOutputStream { 32 // the current debug setting 33 protected boolean debug = false; 34 35 // the target trace output stream. 36 protected OutputStream traceStream; 37 38 /** 39 * Construct a debug trace stream. 40 * 41 * @param out 42 * The target out put stream. 43 * @param traceStream 44 * The side trace stream to which trace data gets written. 45 * @param encode 46 * Indicates whether we wish the Trace data to be Q-P encoded. 47 */ 48 public TraceOutputStream(OutputStream out, OutputStream traceStream, boolean debug, boolean encode) { 49 super(out); 50 this.debug = debug; 51 if (encode) { 52 this.traceStream = new QuotedPrintableEncoderStream(traceStream); 53 } else { 54 this.traceStream = traceStream; 55 } 56 } 57 58 /** 59 * Set the current setting of the debug trace stream debug flag. 60 * 61 * @param d 62 * The new debug flag settings. 63 */ 64 public void setDebug(boolean d) { 65 debug = d; 66 } 67 68 69 /** 70 * Write a single byte to the output stream. 71 * 72 * @param b The byte to be written. 73 * 74 * @exception IOException 75 * thrown for any I/O errors. 76 */ 77 public void write(int b) throws IOException { 78 if (debug) { 79 traceStream.write(b); 80 } 81 super.write(b); 82 } 83 }