Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/java/BinaryAttribute.java
38918 views
/*1* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.java;2627import java.io.IOException;28import java.io.DataInputStream;29import java.io.DataOutputStream;3031/**32* This class is used to represent an attribute from a binary class.33* This class should go away once arrays are objects.34*35* WARNING: The contents of this source file are not part of any36* supported API. Code that depends on them does so at its own risk:37* they are subject to change or removal without notice.38*/39public final40class BinaryAttribute implements Constants {41Identifier name;42byte data[];43BinaryAttribute next;4445/**46* Constructor47*/48BinaryAttribute(Identifier name, byte data[], BinaryAttribute next) {49this.name = name;50this.data = data;51this.next = next;52}5354/**55* Load a list of attributes56*/57public static BinaryAttribute load(DataInputStream in, BinaryConstantPool cpool, int mask) throws IOException {58BinaryAttribute atts = null;59int natt = in.readUnsignedShort(); // JVM 4.6 method_info.attrutes_count6061for (int i = 0 ; i < natt ; i++) {62// id from JVM 4.7 attribute_info.attribute_name_index63Identifier id = cpool.getIdentifier(in.readUnsignedShort());64// id from JVM 4.7 attribute_info.attribute_length65int len = in.readInt();6667if (id.equals(idCode) && ((mask & ATT_CODE) == 0)) {68in.skipBytes(len);69} else {70byte data[] = new byte[len];71in.readFully(data);72atts = new BinaryAttribute(id, data, atts);73}74}75return atts;76}7778// write out the Binary attributes to the given stream79// (note that attributes may be null)80static void write(BinaryAttribute attributes, DataOutputStream out,81BinaryConstantPool cpool, Environment env) throws IOException {82// count the number of attributes83int attributeCount = 0;84for (BinaryAttribute att = attributes; att != null; att = att.next)85attributeCount++;86out.writeShort(attributeCount);8788// write out each attribute89for (BinaryAttribute att = attributes; att != null; att = att.next) {90Identifier name = att.name;91byte data[] = att.data;92// write the identifier93out.writeShort(cpool.indexString(name.toString(), env));94// write the length95out.writeInt(data.length);96// write the data97out.write(data, 0, data.length);98}99}100101/**102* Accessors103*/104105public Identifier getName() { return name; }106107public byte getData()[] { return data; }108109public BinaryAttribute getNextAttribute() { return next; }110111}112113114