01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.wfs;
17:
18: import java.io.IOException;
19: import java.io.InputStream;
20: import java.util.logging.Level;
21: import java.util.logging.Logger;
22:
23: /**
24: * A decorator that logs the Input to the Logger as input is accessed.
25: *
26: * @author Jesse
27: * @since 1.1.0
28: */
29: public class LogInputStream extends InputStream {
30: private InputStream delegate;
31: private Level level;
32:
33: StringBuffer buffer = new StringBuffer("Input: ");
34: private Logger logger;
35:
36: public LogInputStream(InputStream in, Logger logger, Level logLevel) {
37: this .delegate = in;
38: this .logger = logger;
39: this .level = logLevel;
40: }
41:
42: public void close() throws IOException {
43: delegate.close();
44: logger.log(level, buffer.toString());
45: buffer = new StringBuffer("Input: ");
46: }
47:
48: public int read() throws IOException {
49: int result = delegate.read();
50: buffer.append((char) result);
51: return result;
52: }
53:
54: }
|