1 package uk.co.codemist.jlisp.core; 2 3 4 // $Id: CONSTANT_Utf8_info.java 3142 2015-06-21 22:27:59Z arthurcnorman $ 5 6 7 //created 02/02/02 8 9 /************************************************************************** 10 * Copyright (C) 1998-2015, Codemist Ltd. A C Norman * 11 * also contributions from Vijay Chauhan, 2002 * 12 * * 13 * Redistribution and use in source and binary forms, with or without * 14 * modification, are permitted provided that the following conditions are * 15 * met: * 16 * * 17 * * Redistributions of source code must retain the relevant * 18 * copyright notice, this list of conditions and the following * 19 * disclaimer. * 20 * * Redistributions in binary form must reproduce the above * 21 * copyright notice, this list of conditions and the following * 22 * disclaimer in the documentation and/or other materials provided * 23 * with the distribution. * 24 * * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * 28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * 29 * COPYRIGHT OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * 31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * 32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * 33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * 34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * 35 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 36 * DAMAGE. * 37 *************************************************************************/ 38 import java.io.*; 39 40 public class CONSTANT_Utf8_info extends Cp_info 41 { main(String[] args)42 public static void main(String[] args) 43 throws IOException, UnsupportedEncodingException, 44 ResourceException 45 { 46 String s = "<init>"; 47 CONSTANT_Utf8_info cu = new CONSTANT_Utf8_info(s); 48 cu.printBytes(cu.dumpBytes()); 49 Jlisp.println("\n"); 50 51 String s1 = "()V"; 52 CONSTANT_Utf8_info cu1 = new CONSTANT_Utf8_info(s1); 53 cu1.printBytes(cu1.dumpBytes()); 54 Jlisp.println("\n"); 55 56 String s2 = "Code"; 57 CONSTANT_Utf8_info cu2 = new CONSTANT_Utf8_info(s2); 58 cu2.printBytes(cu2.dumpBytes()); 59 Jlisp.println("\n"); 60 61 String s3 = "LineNumberTable"; 62 CONSTANT_Utf8_info cu3 = new CONSTANT_Utf8_info(s3); 63 cu3.printBytes(cu3.dumpBytes()); 64 Jlisp.println("\n"); 65 66 String s4 = "main"; 67 CONSTANT_Utf8_info cu4 = new CONSTANT_Utf8_info(s4); 68 cu4.printBytes(cu4.dumpBytes()); 69 Jlisp.println("\n"); 70 71 String s5 = "([Ljava/lang/String;)V"; 72 CONSTANT_Utf8_info cu5 = new CONSTANT_Utf8_info(s5); 73 cu5.printBytes(cu5.dumpBytes()); 74 Jlisp.println("\n"); 75 76 String s6 = "trivialMethod"; 77 CONSTANT_Utf8_info cu6 = new CONSTANT_Utf8_info(s6); 78 cu6.printBytes(cu6.dumpBytes()); 79 Jlisp.println("\n"); 80 81 String s7 = "(I)I"; 82 CONSTANT_Utf8_info cu7 = new CONSTANT_Utf8_info(s7); 83 cu7.printBytes(cu7.dumpBytes()); 84 Jlisp.println("\n"); 85 86 String s8 = "SourceFile"; 87 CONSTANT_Utf8_info cu8 = new CONSTANT_Utf8_info(s8); 88 cu8.printBytes(cu8.dumpBytes()); 89 Jlisp.println("\n"); 90 91 String s9 = "Trivial.java"; 92 CONSTANT_Utf8_info cu9 = new CONSTANT_Utf8_info(s9); 93 cu9.printBytes(cu9.dumpBytes()); 94 Jlisp.println("\n"); 95 96 String s10 = "Trivial"; 97 CONSTANT_Utf8_info cu10 = new CONSTANT_Utf8_info(s10); 98 cu10.printBytes(cu10.dumpBytes()); 99 Jlisp.println("\n"); 100 101 String s11 = "java/lang/Object"; 102 CONSTANT_Utf8_info cu11 = new CONSTANT_Utf8_info(s11); 103 cu11.printBytes(cu11.dumpBytes()); 104 Jlisp.println("\n"); 105 106 } 107 108 109 short length; 110 byte bytes[]; //should be [length] 111 112 //constructor CONSTANT_Utf8_info(String s)113 CONSTANT_Utf8_info(String s) 114 throws IOException, UnsupportedEncodingException 115 { tag = CONSTANT_Utf8; 116 bytes = s.getBytes("UTF-8"); 117 length = (short)bytes.length; 118 119 byte[][] infoTemp = new byte[2][0]; 120 infoTemp[0] = shortToByteArray(length); 121 infoTemp[1] = bytes; 122 123 info = new byte[totalArraySize(infoTemp)]; 124 info = flatBytes(infoTemp); 125 } 126 127 } 128 129 // end of CONSTANT_Utf8_info.java 130