001    package serp.bytecode;
002    
003    import java.io.*;
004    
005    import serp.bytecode.visitor.*;
006    
007    /**
008     * An unrecognized attribute; class files are allowed to contain
009     * attributes that are not recognized, and the JVM must ignore them.
010     *
011     * @author Abe White
012     */
013    public class UnknownAttribute extends Attribute {
014        private byte[] _value = new byte[0];
015    
016        UnknownAttribute(int nameIndex, Attributes owner) {
017            super(nameIndex, owner);
018        }
019    
020        int getLength() {
021            return _value.length;
022        }
023    
024        /**
025         * The value is of unknown content, so it is stored as a byte array.
026         */
027        public byte[] getValue() {
028            return _value;
029        }
030    
031        /**
032         * The value is of unknown content, so it is stored as a byte array.
033         */
034        public void setValue(byte[] value) {
035            if (value == null)
036                value = new byte[0];
037            _value = value;
038        }
039    
040        public void acceptVisit(BCVisitor visit) {
041            visit.enterUnknownAttribute(this);
042            visit.exitUnknownAttribute(this);
043        }
044    
045        void read(Attribute other) {
046            setValue(((UnknownAttribute) other).getValue());
047        }
048    
049        void read(DataInput in, int length) throws IOException {
050            _value = new byte[length];
051            in.readFully(_value);
052        }
053    
054        void write(DataOutput out, int length) throws IOException {
055            out.write(_value);
056        }
057    }