001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v 1.15 2004/06/24 21:39:52 mbecke Exp $
003: * $Revision: 480424 $
004: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005: *
006: * ====================================================================
007: *
008: * Licensed to the Apache Software Foundation (ASF) under one or more
009: * contributor license agreements. See the NOTICE file distributed with
010: * this work for additional information regarding copyright ownership.
011: * The ASF licenses this file to You under the Apache License, Version 2.0
012: * (the "License"); you may not use this file except in compliance with
013: * the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing, software
018: * distributed under the License is distributed on an "AS IS" BASIS,
019: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020: * See the License for the specific language governing permissions and
021: * limitations under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: */
030:
031: package org.apache.commons.httpclient;
032:
033: import java.io.FilterInputStream;
034: import java.io.IOException;
035: import java.io.InputStream;
036:
037: /**
038: * Logs all data read to the wire LOG.
039: *
040: * @author Ortwin Gl�ck
041: * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
042: * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
043: *
044: * @since 2.0
045: */
046: class WireLogInputStream extends FilterInputStream {
047:
048: /** Original input stream. */
049: private InputStream in;
050:
051: /** The wire log to use for writing. */
052: private Wire wire;
053:
054: /**
055: * Create an instance that wraps the specified input stream.
056: * @param in The input stream.
057: * @param wire The wire log to use.
058: */
059: public WireLogInputStream(InputStream in, Wire wire) {
060: super (in);
061: this .in = in;
062: this .wire = wire;
063: }
064:
065: /**
066: *
067: * @see java.io.InputStream#read(byte[], int, int)
068: */
069: public int read(byte[] b, int off, int len) throws IOException {
070: int l = this .in.read(b, off, len);
071: if (l > 0) {
072: wire.input(b, off, l);
073: }
074: return l;
075: }
076:
077: /**
078: *
079: * @see java.io.InputStream#read()
080: */
081: public int read() throws IOException {
082: int l = this .in.read();
083: if (l > 0) {
084: wire.input(l);
085: }
086: return l;
087: }
088:
089: /**
090: *
091: * @see java.io.InputStream#read(byte[])
092: */
093: public int read(byte[] b) throws IOException {
094: int l = this .in.read(b);
095: if (l > 0) {
096: wire.input(b, 0, l);
097: }
098: return l;
099: }
100: }
|