~ubuntu-branches/ubuntu/natty/cobertura/natty

« back to all changes in this revision

Viewing changes to src/net/sourceforge/cobertura/util/Source.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-05-11 19:21:46 UTC
  • mfrom: (0.1.4 sid) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100511192146-j742v5jsl89ztndu
Tags: 1.9.4.1+dfsg-2
* Now Build-Depends on libservlet2.5-java and add a missing Depends
  on the same package. (Closes: #580842). 
* Simplify list of JRE dependences for cobertura and drop JRE dependences for
  libcobertura-java as Java libraries are no longer required to depend on a
  JVM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cobertura - http://cobertura.sourceforge.net/
 
3
 *
 
4
 * Copyright (C) 2009 John Lewis
 
5
 *
 
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).
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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
 
23
 * USA
 
24
 */
 
25
package net.sourceforge.cobertura.util;
 
26
 
 
27
import java.io.File;
 
28
import java.io.InputStream;
 
29
import java.util.zip.ZipFile;
 
30
 
 
31
import org.apache.log4j.Logger;
 
32
 
 
33
public class Source {
 
34
        private InputStream is;
 
35
        
 
36
        //streamOrigin is either a File or a ZipFile
 
37
        private Object streamOrigin;
 
38
        
 
39
        private static Logger LOGGER = Logger.getLogger(Source.class);
 
40
 
 
41
        public Source(InputStream is, Object streamOrigin)
 
42
        {
 
43
                this.is = is;
 
44
                this.streamOrigin = streamOrigin;
 
45
        }
 
46
        
 
47
        public InputStream getInputStream()
 
48
        {
 
49
                return is;
 
50
        }
 
51
        
 
52
        /**
 
53
         * Close the source input stream and the archive if it came from one.
 
54
         * 
 
55
         * This will not throw anything.   Any throwable is caught and a warning is logged.
 
56
         */
 
57
        public void close()
 
58
        {
 
59
                try
 
60
                {
 
61
                        is.close();
 
62
                }
 
63
                catch (Throwable t)
 
64
                {
 
65
                        LOGGER.warn("Failure closing input stream for " + getOriginDesc(), t);
 
66
                }
 
67
                
 
68
                if (streamOrigin instanceof ZipFile)
 
69
                {
 
70
                        try
 
71
                        {
 
72
                                ((ZipFile) streamOrigin).close();
 
73
                        }
 
74
                        catch (Throwable t)
 
75
                        {
 
76
                                LOGGER.warn("Failure closing " + getOriginDesc(), t);
 
77
                        }
 
78
                }
 
79
        }
 
80
        
 
81
        public String getOriginDesc()
 
82
        {
 
83
                String ret = "";
 
84
                
 
85
                if (streamOrigin instanceof File)
 
86
                {
 
87
                        ret = "file " + ((File) streamOrigin).getAbsolutePath();
 
88
                }
 
89
                else
 
90
                {
 
91
                        ret = "archive " + ((ZipFile) streamOrigin).getName();
 
92
                }
 
93
                return ret;
 
94
        }
 
95
}