comparison gnv/src/main/java/de/intevation/gnv/util/CaptureInputStream.java @ 1025:2996395e44c9

Improved the logging of incoming mapviewer call data. gnv/trunk@1279 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 29 Nov 2010 09:20:01 +0000
parents
children
comparison
equal deleted inserted replaced
1024:b45faa9315ce 1025:2996395e44c9
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.util;
10
11 import java.io.FilterInputStream;
12 import java.io.ByteArrayOutputStream;
13 import java.io.InputStream;
14 import java.io.IOException;
15 import java.io.UnsupportedEncodingException;
16
17 /**
18 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha Teichmann</a>
19 */
20 public class CaptureInputStream
21 extends FilterInputStream
22 {
23 protected ByteArrayOutputStream copy;
24
25 public CaptureInputStream(InputStream in) {
26 super(in);
27 copy = new ByteArrayOutputStream(10*1024);
28 }
29
30 public int read() throws IOException {
31 int x = in.read();
32 if (x != -1) {
33 copy.write(x);
34 }
35 return x;
36 }
37
38 public int read(byte [] b, int off, int len) throws IOException {
39 int r = in.read(b, off, len);
40 if (r > 0) {
41 copy.write(b, off, r);
42 }
43 return r;
44 }
45
46 public long skip(long n) throws IOException {
47 long m = in.skip(n);
48 for (long i = m; i > 0L; --i) { // simulate gab
49 copy.write(0);
50 }
51 return m;
52 }
53
54 public String copyToString() {
55 return copy.toString();
56 }
57
58 public String copyToString(String charsetName)
59 throws UnsupportedEncodingException
60 {
61 return copy.toString(charsetName);
62 }
63
64 public byte [] toByteArray() {
65 return copy.toByteArray();
66 }
67
68 public void clear() {
69 copy.reset();
70 }
71 }

http://dive4elements.wald.intevation.org