1. /*
  2. * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v 1.15 2004/06/24 21:39:52 mbecke Exp $
  3. * $Revision: 1.15 $
  4. * $Date: 2004/06/24 21:39:52 $
  5. *
  6. * ====================================================================
  7. *
  8. * Copyright 1999-2004 The Apache Software Foundation
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * ====================================================================
  22. *
  23. * This software consists of voluntary contributions made by many
  24. * individuals on behalf of the Apache Software Foundation. For more
  25. * information on the Apache Software Foundation, please see
  26. * <http://www.apache.org/>.
  27. *
  28. */
  29. package org.apache.commons.httpclient;
  30. import java.io.FilterInputStream;
  31. import java.io.IOException;
  32. import java.io.InputStream;
  33. /**
  34. * Logs all data read to the wire LOG.
  35. *
  36. * @author Ortwin Gl�ck
  37. * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  38. * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
  39. *
  40. * @since 2.0
  41. */
  42. class WireLogInputStream extends FilterInputStream {
  43. /** Original input stream. */
  44. private InputStream in;
  45. /** The wire log to use for writing. */
  46. private Wire wire;
  47. /**
  48. * Create an instance that wraps the specified input stream.
  49. * @param in The input stream.
  50. * @param wire The wire log to use.
  51. */
  52. public WireLogInputStream(InputStream in, Wire wire) {
  53. super(in);
  54. this.in = in;
  55. this.wire = wire;
  56. }
  57. /**
  58. *
  59. * @see java.io.InputStream#read(byte[], int, int)
  60. */
  61. public int read(byte[] b, int off, int len) throws IOException {
  62. int l = this.in.read(b, off, len);
  63. if (l > 0) {
  64. wire.input(b, off, l);
  65. }
  66. return l;
  67. }
  68. /**
  69. *
  70. * @see java.io.InputStream#read()
  71. */
  72. public int read() throws IOException {
  73. int l = this.in.read();
  74. if (l > 0) {
  75. wire.input(l);
  76. }
  77. return l;
  78. }
  79. /**
  80. *
  81. * @see java.io.InputStream#read(byte[])
  82. */
  83. public int read(byte[] b) throws IOException {
  84. int l = this.in.read(b);
  85. if (l > 0) {
  86. wire.input(b, 0, l);
  87. }
  88. return l;
  89. }
  90. }