Mercurial > dive4elements > gnv-client
view 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 |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ package de.intevation.gnv.util; import java.io.FilterInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; /** * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha Teichmann</a> */ public class CaptureInputStream extends FilterInputStream { protected ByteArrayOutputStream copy; public CaptureInputStream(InputStream in) { super(in); copy = new ByteArrayOutputStream(10*1024); } public int read() throws IOException { int x = in.read(); if (x != -1) { copy.write(x); } return x; } public int read(byte [] b, int off, int len) throws IOException { int r = in.read(b, off, len); if (r > 0) { copy.write(b, off, r); } return r; } public long skip(long n) throws IOException { long m = in.skip(n); for (long i = m; i > 0L; --i) { // simulate gab copy.write(0); } return m; } public String copyToString() { return copy.toString(); } public String copyToString(String charsetName) throws UnsupportedEncodingException { return copy.toString(charsetName); } public byte [] toByteArray() { return copy.toByteArray(); } public void clear() { copy.reset(); } }