001/* 002 * Cobertura - http://cobertura.sourceforge.net/ 003 * 004 * Copyright (C) 2006 John Lewis 005 * Copyright (C) 2006 Mark Doliner 006 * 007 * Note: This file is dual licensed under the GPL and the Apache 008 * Source License (so that it can be used from both the main 009 * Cobertura classes and the ant tasks). 010 * 011 * Cobertura is free software; you can redistribute it and/or modify 012 * it under the terms of the GNU General Public License as published 013 * by the Free Software Foundation; either version 2 of the License, 014 * or (at your option) any later version. 015 * 016 * Cobertura is distributed in the hope that it will be useful, but 017 * WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 * General Public License for more details. 020 * 021 * You should have received a copy of the GNU General Public License 022 * along with Cobertura; if not, write to the Free Software 023 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 024 * USA 025 */ 026 027package net.sourceforge.cobertura.instrument; 028 029import java.io.ByteArrayInputStream; 030import java.io.InputStream; 031 032/** 033 * This class represents an archive within an archive. 034 * 035 * @author John Lewis 036 */ 037class Archive 038{ 039 040 private byte[] bytes; 041 private boolean modified; 042 private CoberturaFile file; 043 044 /** 045 * Create an object that holds a buffer to an archive that is within a parent archive. 046 * 047 * @param file The parent archive on the hard drive that holds the child archive. 048 * @param bytes The contents of the child archive. 049 */ 050 Archive(CoberturaFile file, byte[] bytes) 051 { 052 this.bytes = bytes; 053 this.file = file; 054 } 055 056 /** 057 * Return an input stream for the contents of this archive (the child). 058 * 059 * @return An InputStream for the contents. 060 */ 061 InputStream getInputStream() 062 { 063 return new ByteArrayInputStream(this.bytes); 064 } 065 066 /** 067 * Set this archive's bytes after they have been modified via instrumentation. 068 * 069 * @param bytes The new contents of the archive (instrumented). 070 */ 071 void setModifiedBytes(byte[] bytes) 072 { 073 this.bytes = bytes; 074 this.modified = true; 075 } 076 077 /** 078 * Return true if this archive has been modified (instrumented). 079 * 080 * @return true if modified. 081 */ 082 boolean isModified() 083 { 084 return modified; 085 } 086 087 /** 088 * Return the contents of this archive. 089 * 090 * @return A byte array with the contents of this archive. 091 */ 092 byte[] getBytes() 093 { 094 return this.bytes; 095 } 096 097 /** 098 * Returns the parent archive that contains this archive. 099 * 100 * @return A CoberturaFile representing the parent archive. 101 */ 102 CoberturaFile getCoberturaFile() 103 { 104 return this.file; 105 } 106}