View Javadoc

1   /**********************************************************************
2    * LoggingInputStream.java
3    * created on 02.07.2005 by netseeker
4    * $$Source$$
5    * $Date$
6    * $$Revision$$
7    *
8    * ====================================================================
9    *
10   *  Copyright 2006 netseeker aka Michael Manske
11   *
12   *  Licensed under the Apache License, Version 2.0 (the "License");
13   *  you may not use this file except in compliance with the License.
14   *  You may obtain a copy of the License at
15   *
16   *      http://www.apache.org/licenses/LICENSE-2.0
17   *
18   *  Unless required by applicable law or agreed to in writing, software
19   *  distributed under the License is distributed on an "AS IS" BASIS,
20   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   *  See the License for the specific language governing permissions and
22   *  limitations under the License.
23   * ====================================================================
24   *
25   * This file is part of the ejoe framework.
26   * For more information on the author, please see
27   * <http://www.manskes.de/>.
28   *
29   *********************************************************************/
30  package de.netseeker.ejoe.io;
31  
32  import java.io.FilterInputStream;
33  import java.io.IOException;
34  import java.io.InputStream;
35  import java.util.logging.Level;
36  import java.util.logging.Logger;
37  
38  public class LoggingInputStream extends FilterInputStream
39  {
40      private static final Logger log = Logger.getLogger( LoggingInputStream.class.getName() );
41  
42      /***
43       * @param in
44       */
45      public LoggingInputStream(InputStream in)
46      {
47          super( in );
48      }
49  
50      /*
51       * (non-Javadoc)
52       * 
53       * @see java.io.InputStream#read(byte[], int, int)
54       */
55      public int read( byte[] arr, int offset, int length ) throws IOException
56      {
57          int res = super.read( arr, offset, length );
58          if ( res > 0 )
59          {
60              byte[] tmp = new byte[res];
61              System.arraycopy( arr, offset, tmp, 0, res );
62              log.log( Level.FINEST, new String( tmp, "UTF-8" ) );
63          }
64          return res;
65      }
66  
67      /*
68       * (non-Javadoc)
69       * 
70       * @see java.io.InputStream#read(byte[])
71       */
72      public int read( byte[] arr ) throws IOException
73      {
74          int res = super.read( arr );
75          if ( res > 0 )
76          {
77              byte[] tmp = new byte[res];
78              System.arraycopy( arr, 0, tmp, 0, res );
79              log.log( Level.FINEST, new String( tmp, "UTF-8" ) );
80          }
81          return res;
82      }
83  }