1 /* |
1 /* |
2 * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
26 package com.sun.tools.classfile; |
26 package com.sun.tools.classfile; |
27 |
27 |
28 import java.io.ByteArrayInputStream; |
28 import java.io.ByteArrayInputStream; |
29 import java.io.DataInputStream; |
29 import java.io.DataInputStream; |
30 import java.io.IOException; |
30 import java.io.IOException; |
|
31 import java.nio.charset.Charset; |
31 |
32 |
32 /** |
33 /** |
33 * See JVMS, section 4.8.15. |
34 * See JVMS, section 4.8.15. |
34 * |
35 * |
35 * <p><b>This is NOT part of any supported API. |
36 * <p><b>This is NOT part of any supported API. |
36 * If you write code that depends on this, you do so at your own risk. |
37 * If you write code that depends on this, you do so at your own risk. |
37 * This code and its internal interfaces are subject to change or |
38 * This code and its internal interfaces are subject to change or |
38 * deletion without notice.</b> |
39 * deletion without notice.</b> |
39 */ |
40 */ |
40 public class SourceDebugExtension_attribute extends Attribute { |
41 public class SourceDebugExtension_attribute extends Attribute { |
|
42 private static final Charset UTF8 = Charset.forName("UTF-8"); |
|
43 |
41 SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException { |
44 SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException { |
42 super(name_index, length); |
45 super(name_index, length); |
43 debug_extension = new byte[attribute_length]; |
46 debug_extension = new byte[attribute_length]; |
44 cr.readFully(debug_extension); |
47 cr.readFully(debug_extension); |
45 } |
48 } |
53 super(name_index, debug_extension.length); |
56 super(name_index, debug_extension.length); |
54 this.debug_extension = debug_extension; |
57 this.debug_extension = debug_extension; |
55 } |
58 } |
56 |
59 |
57 public String getValue() { |
60 public String getValue() { |
58 DataInputStream d = new DataInputStream(new ByteArrayInputStream(debug_extension)); |
61 return new String(debug_extension, UTF8); |
59 try { |
|
60 return d.readUTF(); |
|
61 } catch (IOException e) { |
|
62 return null; |
|
63 } |
|
64 } |
62 } |
65 |
63 |
66 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
64 public <R, D> R accept(Visitor<R, D> visitor, D data) { |
67 return visitor.visitSourceDebugExtension(this, data); |
65 return visitor.visitSourceDebugExtension(this, data); |
68 } |
66 } |