Home | History | Annotate | Download | only in conn
      1 /*
      2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java $
      3  * $Revision: 674186 $
      4  * $Date: 2008-07-05 05:18:54 -0700 (Sat, 05 Jul 2008) $
      5  *
      6  * ====================================================================
      7  *
      8  *  Licensed to the Apache Software Foundation (ASF) under one or more
      9  *  contributor license agreements.  See the NOTICE file distributed with
     10  *  this work for additional information regarding copyright ownership.
     11  *  The ASF licenses this file to You under the Apache License, Version 2.0
     12  *  (the "License"); you may not use this file except in compliance with
     13  *  the License.  You may obtain a copy of the License at
     14  *
     15  *      http://www.apache.org/licenses/LICENSE-2.0
     16  *
     17  *  Unless required by applicable law or agreed to in writing, software
     18  *  distributed under the License is distributed on an "AS IS" BASIS,
     19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20  *  See the License for the specific language governing permissions and
     21  *  limitations under the License.
     22  * ====================================================================
     23  *
     24  * This software consists of voluntary contributions made by many
     25  * individuals on behalf of the Apache Software Foundation.  For more
     26  * information on the Apache Software Foundation, please see
     27  * <http://www.apache.org/>.
     28  *
     29  */
     30 
     31 package org.apache.http.impl.conn;
     32 
     33 import java.io.IOException;
     34 
     35 import org.apache.http.io.HttpTransportMetrics;
     36 import org.apache.http.io.SessionOutputBuffer;
     37 import org.apache.http.util.CharArrayBuffer;
     38 
     39 /**
     40  * Logs all data written to the wire LOG.
     41  *
     42  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
     43  *
     44  * @since 4.0
     45  *
     46  * @deprecated Please use {@link java.net.URL#openConnection} instead.
     47  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
     48  *     for further details.
     49  */
     50 @Deprecated
     51 public class LoggingSessionOutputBuffer implements SessionOutputBuffer {
     52 
     53     /** Original data transmitter. */
     54     private final SessionOutputBuffer out;
     55 
     56     /** The wire log to use. */
     57     private final Wire wire;
     58 
     59     /**
     60      * Create an instance that wraps the specified session output buffer.
     61      * @param out The session output buffer.
     62      * @param wire The Wire log to use.
     63      */
     64     public LoggingSessionOutputBuffer(final SessionOutputBuffer out, final Wire wire) {
     65         super();
     66         this.out = out;
     67         this.wire = wire;
     68     }
     69 
     70     public void write(byte[] b, int off, int len) throws IOException {
     71         this.out.write(b,  off,  len);
     72         if (this.wire.enabled()) {
     73             this.wire.output(b, off, len);
     74         }
     75     }
     76 
     77     public void write(int b) throws IOException {
     78         this.out.write(b);
     79         if (this.wire.enabled()) {
     80             this.wire.output(b);
     81         }
     82     }
     83 
     84     public void write(byte[] b) throws IOException {
     85         this.out.write(b);
     86         if (this.wire.enabled()) {
     87             this.wire.output(b);
     88         }
     89     }
     90 
     91     public void flush() throws IOException {
     92         this.out.flush();
     93     }
     94 
     95     public void writeLine(final CharArrayBuffer buffer) throws IOException {
     96         this.out.writeLine(buffer);
     97         if (this.wire.enabled()) {
     98             String s = new String(buffer.buffer(), 0, buffer.length());
     99             this.wire.output(s + "[EOL]");
    100         }
    101     }
    102 
    103     public void writeLine(final String s) throws IOException {
    104         this.out.writeLine(s);
    105         if (this.wire.enabled()) {
    106             this.wire.output(s + "[EOL]");
    107         }
    108     }
    109 
    110     public HttpTransportMetrics getMetrics() {
    111         return this.out.getMetrics();
    112     }
    113 
    114 }
    115