01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package EDU.purdue.cs.bloat.file;
22:
23: import java.io.*;
24:
25: /**
26: * The Java Virtual Machine Specification allows implementors to invent their
27: * own attributes. GenericAttribute models attributes whose name BLOAT does not
28: * recognize.
29: *
30: * @author Nate Nystrom (<a
31: * href="mailto:nystrom@cs.purdue.edu">nystrom@cs.purdue.edu</a>)
32: */
33: public class GenericAttribute extends Attribute {
34: private byte[] data;
35:
36: /**
37: * Constructor. Create an attribute from a data stream.
38: *
39: * @param in
40: * The data stream of the class file.
41: * @param nameIndex
42: * The index into the constant pool of the name of the attribute.
43: * @param length
44: * The length of the attribute, excluding the header.
45: * @exception IOException
46: * If an error occurs while reading.
47: */
48: public GenericAttribute(final DataInputStream in,
49: final int nameIndex, final int length) throws IOException {
50: super (nameIndex, length);
51: data = new byte[length];
52: for (int read = 0; read < length;) {
53: read += in.read(data, read, length - read);
54: }
55: }
56:
57: /**
58: * Write the attribute to a data stream.
59: *
60: * @param out
61: * The data stream of the class file.
62: * @exception IOException
63: * If an error occurs while writing.
64: */
65: public void writeData(final DataOutputStream out)
66: throws IOException {
67: out.write(data, 0, data.length);
68: }
69:
70: /**
71: * Private constructor used in cloning.
72: */
73: private GenericAttribute(final GenericAttribute other) {
74: super (other.nameIndex, other.length);
75:
76: this .data = new byte[other.data.length];
77: System
78: .arraycopy(other.data, 0, this .data, 0,
79: other.data.length);
80: }
81:
82: public Object clone() {
83: return (new GenericAttribute(this));
84: }
85: }
|