01: /*
02: * Cobertura - http://cobertura.sourceforge.net/
03: *
04: * Copyright (C) 2006 John Lewis
05: * Copyright (C) 2006 Mark Doliner
06: *
07: * Note: This file is dual licensed under the GPL and the Apache
08: * Source License (so that it can be used from both the main
09: * 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: private byte[] bytes;
40: private boolean modified;
41: private CoberturaFile file;
42:
43: /**
44: * Create an object that holds a buffer to an archive that is within a parent archive.
45: *
46: * @param file The parent archive on the hard drive that holds the child archive.
47: * @param bytes The contents of the child archive.
48: */
49: Archive(CoberturaFile file, byte[] bytes) {
50: this .bytes = bytes;
51: this .file = file;
52: }
53:
54: /**
55: * Return an input stream for the contents of this archive (the child).
56: *
57: * @return An InputStream for the contents.
58: */
59: InputStream getInputStream() {
60: return new ByteArrayInputStream(this .bytes);
61: }
62:
63: /**
64: * Set this archive's bytes after they have been modified via instrumentation.
65: *
66: * @param bytes The new contents of the archive (instrumented).
67: */
68: void setModifiedBytes(byte[] bytes) {
69: this .bytes = bytes;
70: this .modified = true;
71: }
72:
73: /**
74: * Return true if this archive has been modified (instrumented).
75: *
76: * @return true if modified.
77: */
78: boolean isModified() {
79: return modified;
80: }
81:
82: /**
83: * Return the contents of this archive.
84: *
85: * @return A byte array with the contents of this archive.
86: */
87: byte[] getBytes() {
88: return this .bytes;
89: }
90:
91: /**
92: * Returns the parent archive that contains this archive.
93: *
94: * @return A CoberturaFile representing the parent archive.
95: */
96: CoberturaFile getCoberturaFile() {
97: return this.file;
98: }
99: }
|