Mercurial > dive4elements > gnv-client
view gnv/src/main/java/de/intevation/gnv/util/CaptureInputStream.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | 2996395e44c9 |
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(); } }