2
* Cobertura - http://cobertura.sourceforge.net/
4
* Copyright (C) 2009 John Lewis
6
* Note: This file is dual licensed under the GPL and the Apache
7
* Source License (so that it can be used from both the main
8
* Cobertura classes and the ant tasks).
10
* Cobertura is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published
12
* by the Free Software Foundation; either version 2 of the License,
13
* or (at your option) any later version.
15
* Cobertura is distributed in the hope that it will be useful, but
16
* WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with Cobertura; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25
package net.sourceforge.cobertura.util;
28
import java.io.InputStream;
29
import java.util.zip.ZipFile;
31
import org.apache.log4j.Logger;
34
private InputStream is;
36
//streamOrigin is either a File or a ZipFile
37
private Object streamOrigin;
39
private static Logger LOGGER = Logger.getLogger(Source.class);
41
public Source(InputStream is, Object streamOrigin)
44
this.streamOrigin = streamOrigin;
47
public InputStream getInputStream()
53
* Close the source input stream and the archive if it came from one.
55
* This will not throw anything. Any throwable is caught and a warning is logged.
65
LOGGER.warn("Failure closing input stream for " + getOriginDesc(), t);
68
if (streamOrigin instanceof ZipFile)
72
((ZipFile) streamOrigin).close();
76
LOGGER.warn("Failure closing " + getOriginDesc(), t);
81
public String getOriginDesc()
85
if (streamOrigin instanceof File)
87
ret = "file " + ((File) streamOrigin).getAbsolutePath();
91
ret = "archive " + ((ZipFile) streamOrigin).getName();