Coverage Report - net.sourceforge.cobertura.instrument.Archive
 
Classes in this File Line Coverage Branch Coverage Complexity
Archive
100%
11/11
N/A
1
 
 1  
 /*
 2  
  * Cobertura - http://cobertura.sourceforge.net/
 3  
  *
 4  
  * Copyright (C) 2006 John Lewis
 5  
  * Copyright (C) 2006 Mark Doliner
 6  
  *
 7  
  * Note: This file is dual licensed under the GPL and the Apache
 8  
  * Source License (so that it can be used from both the main
 9  
  * Cobertura classes and the ant tasks).
 10  
  *
 11  
  * Cobertura is free software; you can redistribute it and/or modify
 12  
  * it under the terms of the GNU General Public License as published
 13  
  * by the Free Software Foundation; either version 2 of the License,
 14  
  * or (at your option) any later version.
 15  
  *
 16  
  * Cobertura is distributed in the hope that it will be useful, but
 17  
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 18  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 19  
  * General Public License for more details.
 20  
  *
 21  
  * You should have received a copy of the GNU General Public License
 22  
  * along with Cobertura; if not, write to the Free Software
 23  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 24  
  * USA
 25  
  */
 26  
 
 27  
 package net.sourceforge.cobertura.instrument;
 28  
 
 29  
 import java.io.ByteArrayInputStream;
 30  
 import java.io.InputStream;
 31  
 
 32  
 /**
 33  
  * This class represents an archive within an archive.
 34  
  * 
 35  
  * @author John Lewis
 36  
  */
 37  
 class Archive
 38  
 {
 39  
 
 40  
         private byte[] bytes;
 41  
         private boolean modified;
 42  
         private CoberturaFile file;
 43  
 
 44  
         /**
 45  
          * Create an object that holds a buffer to an archive that is within a parent archive.
 46  
          * 
 47  
          * @param file The parent archive on the hard drive that holds the child archive.
 48  
          * @param bytes The contents of the child archive.
 49  
          */
 50  
         Archive(CoberturaFile file, byte[] bytes)
 51  1
         {
 52  1
                 this.bytes = bytes;
 53  1
                 this.file = file;
 54  1
         }
 55  
 
 56  
         /**
 57  
          * Return an input stream for the contents of this archive (the child).
 58  
          * 
 59  
          * @return An InputStream for the contents.
 60  
          */
 61  
         InputStream getInputStream()
 62  
         {
 63  1
                 return new ByteArrayInputStream(this.bytes);
 64  
         }
 65  
 
 66  
         /**
 67  
          * Set this archive's bytes after they have been modified via instrumentation.
 68  
          * 
 69  
          * @param bytes The new contents of the archive (instrumented).
 70  
          */
 71  
         void setModifiedBytes(byte[] bytes)
 72  
         {
 73  1
                 this.bytes = bytes;
 74  1
                 this.modified = true;
 75  1
         }
 76  
 
 77  
         /**
 78  
          * Return true if this archive has been modified (instrumented).
 79  
          * 
 80  
          * @return true if modified.
 81  
          */
 82  
         boolean isModified()
 83  
         {
 84  1
                 return modified;
 85  
         }
 86  
 
 87  
         /**
 88  
          * Return the contents of this archive.
 89  
          * 
 90  
          * @return A byte array with the contents of this archive.
 91  
          */
 92  
         byte[] getBytes()
 93  
         {
 94  1
                 return this.bytes;
 95  
         }
 96  
 
 97  
         /**
 98  
          * Returns the parent archive that contains this archive.
 99  
          * 
 100  
          * @return A CoberturaFile representing the parent archive.
 101  
          */
 102  
         CoberturaFile getCoberturaFile()
 103  
         {
 104  1
                 return this.file;
 105  
         }
 106  
 }