0001: /*
0002: * Util.java Copyright (c) 2006,07 Swaroop Belur
0003: *
0004: * This program is free software; you can redistribute it and/or
0005: * modify it under the terms of the GNU General Public License
0006: * as published by the Free Software Foundation; either version 2
0007: * of the License, or (at your option) any later version.
0008:
0009: * This program is distributed in the hope that it will be useful,
0010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012: * GNU General Public License for more details.
0013:
0014: * You should have received a copy of the GNU General Public License
0015: * along with this program; if not, write to the Free Software
0016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017: *
0018: */
0019: package net.sf.jdec.util;
0020:
0021: import net.sf.jdec.config.Configuration;
0022: import net.sf.jdec.constantpool.MethodInfo;
0023: import net.sf.jdec.core.LocalVariableHelper;
0024: import net.sf.jdec.exceptions.IOError;
0025: import net.sf.jdec.exceptions.InvalidInputException;
0026: import net.sf.jdec.main.ConsoleLauncher;
0027: import net.sf.jdec.ui.util.LogWriter;
0028: import net.sf.jdec.ui.util.UIUtil;
0029:
0030: import java.io.*;
0031: import java.util.*;
0032: import java.util.jar.JarFile;
0033: import java.util.zip.ZipEntry;
0034:
0035: public class Util {
0036:
0037: private static java.lang.String classFilePath = "***Not-Initialized***";
0038:
0039: /***************************************************************************
0040: * // Assumption : input represents The Full Path off The Class File
0041: *
0042: * @param input
0043: */
0044:
0045: public static void registerInputs(java.lang.String[] input)
0046: throws InvalidInputException, IOException {
0047: boolean inputSpecified = false;
0048: boolean jarSpecified = false;
0049: for (int i = 0; i < input.length; i++) {
0050:
0051: if (input[i].equalsIgnoreCase("-showImports")) {
0052: java.lang.String showImport = input[i + 1];
0053: Configuration.setShowImport(showImport);
0054:
0055: }
0056: if (input[i].equalsIgnoreCase("-outputMode")) {
0057: java.lang.String opMode = input[i + 1];
0058: Configuration.setOutputMode(opMode);
0059:
0060: }
0061: if (input[i].equalsIgnoreCase("-logMode")) {
0062: java.lang.String logMode = input[i + 1];
0063: Configuration.setLogMode(logMode);
0064:
0065: }
0066: if (input[i].equalsIgnoreCase("-outputFolder")) {
0067: java.lang.String folder = input[i + 1];
0068: Configuration.setOutputFolderPath(folder);
0069: Configuration.backupOriginalOutputFilePath(folder);
0070: }
0071: if (input[i].equalsIgnoreCase("-logLevel")) {
0072: java.lang.String logl = input[i + 1];
0073: Configuration.setLogLevel(logl);
0074:
0075: }
0076: if (input[i].equalsIgnoreCase("-logPath")) {
0077: java.lang.String logP = input[i + 1];
0078: Configuration.setLogFilePath(logP);
0079: }
0080: if (input[i].equalsIgnoreCase("-tempDir")) {
0081: java.lang.String temp = input[i + 1];
0082: Configuration.setTempDir(temp);
0083: }
0084: if (input[i].equalsIgnoreCase("-innerDepth")) {
0085: java.lang.String temp = input[i + 1];
0086: Configuration.setInnerdepth(temp);
0087: }
0088:
0089: if (input[i].equals("-jar")) {
0090: java.lang.String jarPath = input[i + 1];
0091: Configuration.setJarPath(jarPath);
0092: Configuration.setDecompileroption("jar");
0093: jarSpecified = true;
0094: Configuration.setJarSpecified(true);
0095:
0096: }
0097:
0098: if (input[i].equals("-input")) {
0099: classFilePath = input[i + 1];
0100: inputSpecified = true;
0101: Configuration.setSingleClassSpecified(true);
0102: Configuration.setJavaClassFile(classFilePath);
0103: Configuration.setClassFilePath(classFilePath);
0104: }
0105: if (input[i].equals("-option")) {
0106: java.lang.String option = input[i + 1];
0107: if (option.equals("vcp")) {
0108: Configuration.setDecompileroption("vcp");
0109: } else if (option.equals("disassemble")
0110: || option.equals("dis")) {
0111: Configuration.setDecompileroption("dis");
0112: } else if (option.equals("dc")) {
0113: Configuration.setDecompileroption("dc");
0114: } else if (option.equals("dc_nocode")) {
0115: Configuration.setDecompileroption("nocode");
0116: } else if (option.equals("help")) {
0117: Configuration.setDecompileroption("help");
0118: } else if (option.equals("llv")
0119: || option.equalsIgnoreCase("listlocalvar")) {
0120: Configuration.setDecompileroption("llv");
0121: }
0122:
0123: else {
0124: throw new InvalidInputException(
0125: "Invalid Option specified to the Decompiler..."
0126: + option);
0127: }
0128: }
0129: }
0130: if (inputSpecified == false) {
0131: classFilePath = Configuration.getJavaClassFile();
0132: }
0133:
0134: }
0135:
0136: public static void showUsage() throws IOException {
0137: net.sf.jdec.io.Writer writer = net.sf.jdec.io.Writer
0138: .getWriter("log");
0139: if (writer == null) {
0140: throw new IOError(
0141: "**** Error While Creating Writer Object....");
0142: } else {
0143: try {
0144: writer
0145: .writeLog(" \n\nInvalid Usage of the Decompiler....\n");
0146: writer
0147: .writeLog(" Please use the help option to learn how to use the tool...");
0148: writer.writeLog(" \n***Way to Run Help....\n");
0149: writer
0150: .writeLog(" ---> 1> Type help as the argument Or\n");
0151: writer.writeLog(" ---> 2> Type /? as the argument\n");
0152: writer
0153: .writeLog(" ---> 1> Type -help as the argument\n\n");
0154: writer.flush();
0155: Thread.sleep(5000);
0156: System.exit(1);
0157: } catch (InterruptedException ie) {
0158: // Leave Blank
0159: }
0160:
0161: }
0162:
0163: }
0164:
0165: public static java.lang.String getClassPath() {
0166:
0167: return classFilePath;
0168:
0169: }
0170:
0171: public static java.lang.String[] parseAccessSpecifiers(
0172: Integer code, int type) {
0173: java.lang.String specifiers[] = null;
0174: if (type == Constants.FIELD_ACC) {
0175: specifiers = decodeFieldSpecifiers(code);
0176: }
0177: if (type == Constants.METHOD_ACC) {
0178: specifiers = decodeMethodSpecifiers(code);
0179: }
0180: return specifiers;
0181: }
0182:
0183: public static java.lang.String[] decodeFieldSpecifiers(Integer code) {
0184: int numberOfSpecifiers = -1;
0185: java.lang.String[] specifiers = null;
0186: switch (code.intValue()) {
0187:
0188: case Constants.ACC_PUB_F:
0189: numberOfSpecifiers = 1;
0190: specifiers = new java.lang.String[numberOfSpecifiers];
0191: specifiers[0] = "public";
0192: break;
0193: case Constants.ACC_PUB_STATIC:
0194: numberOfSpecifiers = 2;
0195: specifiers = new java.lang.String[numberOfSpecifiers];
0196: specifiers[0] = "public";
0197: specifiers[1] = "static";
0198: break;
0199: case Constants.ACC_PUB_F_FINAL:
0200: numberOfSpecifiers = 2;
0201: specifiers = new java.lang.String[numberOfSpecifiers];
0202: specifiers[0] = "public";
0203: specifiers[1] = "final";
0204: break;
0205: case Constants.ACC_PUB_STATIC_FINAL:
0206: numberOfSpecifiers = 3;
0207: specifiers = new java.lang.String[numberOfSpecifiers];
0208: specifiers[0] = "public";
0209: specifiers[1] = "static";
0210: specifiers[2] = "final";
0211: break;
0212: case Constants.ACC_PUB_STATIC_VOLATILE:
0213: numberOfSpecifiers = 3;
0214: specifiers = new java.lang.String[numberOfSpecifiers];
0215: specifiers[0] = "public";
0216: specifiers[1] = "static";
0217: specifiers[2] = "volatile";
0218: break;
0219: case Constants.ACC_PUB_STATIC_TRANSIENT:
0220: numberOfSpecifiers = 3;
0221: specifiers = new java.lang.String[numberOfSpecifiers];
0222: specifiers[0] = "public";
0223: specifiers[1] = "static";
0224: specifiers[2] = "transient";
0225: break;
0226: case Constants.ACC_PUB_TRANSIENT:
0227: numberOfSpecifiers = 2;
0228: specifiers = new java.lang.String[numberOfSpecifiers];
0229: specifiers[0] = "public";
0230: specifiers[1] = "transient";
0231: break;
0232: case Constants.ACC_PUB_STATIC_FINAL_TRANSIENT:
0233: numberOfSpecifiers = 4;
0234: specifiers = new java.lang.String[numberOfSpecifiers];
0235: specifiers[0] = "public";
0236: specifiers[1] = "static";
0237: specifiers[2] = "final";
0238: specifiers[3] = "transient";
0239: break;
0240: case Constants.ACC_PUB_FINAL_TRANSIENT:
0241: numberOfSpecifiers = 3;
0242: specifiers = new java.lang.String[numberOfSpecifiers];
0243: specifiers[0] = "public";
0244: specifiers[1] = "final";
0245: specifiers[2] = "transient";
0246: break;
0247: case Constants.ACC_PRI:
0248: numberOfSpecifiers = 1;
0249: specifiers = new java.lang.String[numberOfSpecifiers];
0250: specifiers[0] = "private";
0251: break;
0252:
0253: case Constants.ACC_PRI_STATIC:
0254: numberOfSpecifiers = 2;
0255: specifiers = new java.lang.String[numberOfSpecifiers];
0256: specifiers[0] = "private";
0257: specifiers[1] = "static";
0258:
0259: break;
0260: case Constants.ACC_PRI_FINAL:
0261: numberOfSpecifiers = 2;
0262: specifiers = new java.lang.String[numberOfSpecifiers];
0263: specifiers[0] = "private";
0264: specifiers[1] = "final";
0265: break;
0266:
0267: case Constants.ACC_PRI_STATIC_FINAL:
0268: numberOfSpecifiers = 3;
0269: specifiers = new java.lang.String[numberOfSpecifiers];
0270: specifiers[0] = "private";
0271: specifiers[1] = "static";
0272: specifiers[2] = "final";
0273: break;
0274:
0275: case Constants.ACC_PRI_STATIC_VOLATILE:
0276: numberOfSpecifiers = 3;
0277: specifiers = new java.lang.String[numberOfSpecifiers];
0278: specifiers[0] = "private";
0279: specifiers[1] = "static";
0280: specifiers[2] = "volatile";
0281: break;
0282:
0283: case Constants.ACC_PRI_STATIC_TRANSIENT:
0284: numberOfSpecifiers = 3;
0285: specifiers = new java.lang.String[numberOfSpecifiers];
0286: specifiers[0] = "private";
0287: specifiers[1] = "static";
0288: specifiers[2] = "transient";
0289: break;
0290: case Constants.ACC_PRI_TRANSIENT:
0291: numberOfSpecifiers = 2;
0292: specifiers = new java.lang.String[numberOfSpecifiers];
0293: specifiers[0] = "private";
0294: specifiers[1] = "transient";
0295: break;
0296:
0297: case Constants.ACC_PRI_STATIC_FINAL_TRANSIENT:
0298: numberOfSpecifiers = 4;
0299: specifiers = new java.lang.String[numberOfSpecifiers];
0300: specifiers[0] = "private";
0301: specifiers[1] = "static";
0302: specifiers[2] = "final";
0303: specifiers[3] = "transient";
0304: break;
0305:
0306: case Constants.ACC_PRI_FINAL_TRANSIENT:
0307: numberOfSpecifiers = 3;
0308: specifiers = new java.lang.String[numberOfSpecifiers];
0309: specifiers[0] = "private";
0310: specifiers[1] = "final";
0311: specifiers[2] = "transient";
0312: break;
0313:
0314: case Constants.ACC_PRO:
0315: numberOfSpecifiers = 1;
0316: specifiers = new java.lang.String[numberOfSpecifiers];
0317: specifiers[0] = "protected";
0318: break;
0319: case Constants.ACC_PRO_STATIC:
0320: numberOfSpecifiers = 2;
0321: specifiers = new java.lang.String[numberOfSpecifiers];
0322: specifiers[0] = "protected";
0323: specifiers[1] = "static";
0324: break;
0325:
0326: case Constants.ACC_PRO_FINAL:
0327: numberOfSpecifiers = 2;
0328: specifiers = new java.lang.String[numberOfSpecifiers];
0329: specifiers[0] = "protected";
0330: specifiers[1] = "final";
0331: break;
0332:
0333: case Constants.ACC_PRO_STATIC_FINAL:
0334: numberOfSpecifiers = 3;
0335: specifiers = new java.lang.String[numberOfSpecifiers];
0336: specifiers[0] = "protected";
0337: specifiers[1] = "static";
0338: specifiers[2] = "final";
0339: break;
0340: case Constants.ACC_PRO_STATIC_VOLATILE:
0341: numberOfSpecifiers = 3;
0342: specifiers = new java.lang.String[numberOfSpecifiers];
0343: specifiers[0] = "protected";
0344: specifiers[1] = "static";
0345: specifiers[2] = "volatile";
0346: break;
0347:
0348: case Constants.ACC_PRO_STATIC_TRANSIENT:
0349: numberOfSpecifiers = 3;
0350: specifiers = new java.lang.String[numberOfSpecifiers];
0351: specifiers[0] = "protected";
0352: specifiers[1] = "static";
0353: specifiers[2] = "transient";
0354: break;
0355:
0356: case Constants.ACC_PRO_TRANSIENT:
0357: numberOfSpecifiers = 2;
0358: specifiers = new java.lang.String[numberOfSpecifiers];
0359: specifiers[0] = "protected";
0360: specifiers[1] = "transient";
0361: break;
0362:
0363: case Constants.ACC_PRO_STATIC_FINAL_TRANSIENT:
0364: numberOfSpecifiers = 4;
0365: specifiers = new java.lang.String[numberOfSpecifiers];
0366: specifiers[0] = "protected";
0367: specifiers[1] = "static";
0368: specifiers[2] = "final";
0369: specifiers[3] = "transient";
0370: break;
0371:
0372: case Constants.ACC_PRO_FINAL_TRANSIENT:
0373: numberOfSpecifiers = 3;
0374: specifiers = new java.lang.String[numberOfSpecifiers];
0375: specifiers[0] = "protected";
0376: specifiers[1] = "final";
0377: specifiers[2] = "transient";
0378: break;
0379:
0380: case Constants.ACC_FINAL_VOLATILE:
0381: numberOfSpecifiers = 2;
0382: specifiers = new java.lang.String[numberOfSpecifiers];
0383: specifiers[0] = "final";
0384: specifiers[1] = "volatile";
0385: break;
0386:
0387: case Constants.ACC_FINAL_TRANSIENT:
0388: numberOfSpecifiers = 2;
0389: specifiers = new java.lang.String[numberOfSpecifiers];
0390: specifiers[1] = "final";
0391: specifiers[2] = "transient";
0392: break;
0393:
0394: case Constants.ACC_FINAL_STATIC:
0395: numberOfSpecifiers = 2;
0396: specifiers = new java.lang.String[numberOfSpecifiers];
0397: specifiers[0] = "final";
0398: specifiers[1] = "static";
0399: break;
0400:
0401: case Constants.ACC_FINAL_STATIC_VOLTILE:
0402: numberOfSpecifiers = 3;
0403: specifiers = new java.lang.String[numberOfSpecifiers];
0404: specifiers[0] = "final";
0405: specifiers[1] = "static";
0406: specifiers[2] = "volatile";
0407: break;
0408:
0409: case Constants.ACC_FINAL_STATIC_TRANSIENT:
0410: numberOfSpecifiers = 3;
0411: specifiers = new java.lang.String[numberOfSpecifiers];
0412: specifiers[0] = "final";
0413: specifiers[1] = "static";
0414: specifiers[2] = "transient";
0415: break;
0416:
0417: case Constants.ACC_FINAL_VOLATILE_TRANSIENT:
0418: numberOfSpecifiers = 3;
0419: specifiers = new java.lang.String[numberOfSpecifiers];
0420: specifiers[0] = "final";
0421: specifiers[1] = "volatile";
0422: specifiers[2] = "transient";
0423: break;
0424:
0425: case Constants.ACC_STATIC_VOLATILE:
0426: numberOfSpecifiers = 2;
0427: specifiers = new java.lang.String[numberOfSpecifiers];
0428: specifiers[0] = "static";
0429: specifiers[1] = "volatile";
0430: break;
0431:
0432: case Constants.ACC_STATIC_TRANSIENT:
0433: numberOfSpecifiers = 2;
0434: specifiers = new java.lang.String[numberOfSpecifiers];
0435: specifiers[0] = "static";
0436: specifiers[1] = "transient";
0437: break;
0438:
0439: case Constants.ACC_VOLATILE_TRANSIENT:
0440: numberOfSpecifiers = 2;
0441: specifiers = new java.lang.String[numberOfSpecifiers];
0442: specifiers[0] = "volatile";
0443: specifiers[1] = "transient";
0444: break;
0445:
0446: case Constants.ACC_F_STATIC:
0447: numberOfSpecifiers = 1;
0448: specifiers = new java.lang.String[numberOfSpecifiers];
0449: specifiers[0] = "static";
0450: break;
0451:
0452: case Constants.ACC_F_FINAL:
0453: numberOfSpecifiers = 1;
0454: specifiers = new java.lang.String[numberOfSpecifiers];
0455: specifiers[0] = "final";
0456: break;
0457:
0458: case Constants.ACC_VOLATILE:
0459: numberOfSpecifiers = 1;
0460: specifiers = new java.lang.String[numberOfSpecifiers];
0461: specifiers[0] = "volatile";
0462: break;
0463:
0464: case Constants.ACC_TRANSIENT:
0465: numberOfSpecifiers = 1;
0466: specifiers = new java.lang.String[numberOfSpecifiers];
0467: specifiers[0] = "transient";
0468: break;
0469:
0470: default:
0471: numberOfSpecifiers = 1;
0472: specifiers = new java.lang.String[numberOfSpecifiers];
0473: // specifiers[0]=Constants.UNKNOWNACCESSORS; // NOt Correct For
0474: // Default Access
0475: specifiers[0] = "";
0476: break;
0477:
0478: }
0479: return specifiers;
0480: }
0481:
0482: public static java.lang.String[] decodeMethodSpecifiers(Integer code) {
0483: int numberOfSpecifiers = -1;
0484: java.lang.String[] specifiers = null;
0485: switch (code.intValue()) {
0486:
0487: case Constants.M_PUB:
0488: numberOfSpecifiers = 1;
0489: specifiers = new java.lang.String[numberOfSpecifiers];
0490: specifiers[0] = "public";
0491: break;
0492:
0493: case Constants.M_PUB_ABS:
0494: numberOfSpecifiers = 2;
0495: specifiers = new java.lang.String[numberOfSpecifiers];
0496: specifiers[0] = "public";
0497: specifiers[1] = "abstract";
0498: break;
0499:
0500: case Constants.M_PUB_FINAL:
0501: numberOfSpecifiers = 2;
0502: specifiers = new java.lang.String[numberOfSpecifiers];
0503: specifiers[0] = "public";
0504: specifiers[1] = "final";
0505: break;
0506:
0507: case Constants.M_PUB_NATIVE:
0508: numberOfSpecifiers = 2;
0509: specifiers = new java.lang.String[numberOfSpecifiers];
0510: specifiers[0] = "public";
0511: specifiers[1] = "native";
0512: break;
0513:
0514: case Constants.M_PUB_STATIC:
0515: numberOfSpecifiers = 2;
0516: specifiers = new java.lang.String[numberOfSpecifiers];
0517: specifiers[0] = "public";
0518: specifiers[1] = "static";
0519: break;
0520:
0521: case Constants.M_PUB_STATIC_FINAL:
0522: numberOfSpecifiers = 3;
0523: specifiers = new java.lang.String[numberOfSpecifiers];
0524: specifiers[0] = "public";
0525: specifiers[1] = "static";
0526: specifiers[2] = "final";
0527: break;
0528:
0529: case Constants.M_PUB_STATIC_FINAL_NATIVE:
0530: numberOfSpecifiers = 4;
0531: specifiers = new java.lang.String[numberOfSpecifiers];
0532: specifiers[0] = "public";
0533: specifiers[1] = "static";
0534: specifiers[2] = "final";
0535: specifiers[3] = "native";
0536: break;
0537:
0538: case Constants.M_PUB_STATIC_FINAL_STRICT:
0539: numberOfSpecifiers = 4;
0540: specifiers = new java.lang.String[numberOfSpecifiers];
0541: specifiers[0] = "public";
0542: specifiers[1] = "static";
0543: specifiers[2] = "final";
0544: specifiers[3] = "strictfp";
0545: break;
0546:
0547: case Constants.M_PUB_STATIC_FINAL_SYNCH:
0548: numberOfSpecifiers = 4;
0549: specifiers = new java.lang.String[numberOfSpecifiers];
0550: specifiers[0] = "public";
0551: specifiers[1] = "static";
0552: specifiers[2] = "final";
0553: specifiers[3] = "synchronized";
0554: break;
0555:
0556: case Constants.M_PUB_STATIC_FINAL_SYNCH_NATIVE:
0557: numberOfSpecifiers = 5;
0558: specifiers = new java.lang.String[numberOfSpecifiers];
0559: specifiers[0] = "public";
0560: specifiers[1] = "static";
0561: specifiers[2] = "final";
0562: specifiers[3] = "native";
0563: specifiers[4] = "synchronized";
0564: break;
0565:
0566: case net.sf.jdec.util.Constants.M_PUB_STATIC_FINAL_SYNCH_STRICT:
0567: numberOfSpecifiers = 5;
0568: specifiers = new java.lang.String[numberOfSpecifiers];
0569: specifiers[0] = "public";
0570: specifiers[1] = "static";
0571: specifiers[2] = "final";
0572: specifiers[3] = "synchronized";
0573: specifiers[4] = "strictfp";
0574: break;
0575: case net.sf.jdec.util.Constants.M_PUB_STATIC_NATIVE:
0576: numberOfSpecifiers = 3;
0577: specifiers = new java.lang.String[numberOfSpecifiers];
0578: specifiers[0] = "public";
0579: specifiers[1] = "static";
0580: specifiers[2] = "native";
0581: break;
0582: case net.sf.jdec.util.Constants.M_PUB_STATIC_STRICT:
0583: numberOfSpecifiers = 3;
0584: specifiers = new java.lang.String[numberOfSpecifiers];
0585: specifiers[0] = "public";
0586: specifiers[1] = "static";
0587: specifiers[2] = "strictfp";
0588: break;
0589: case Constants.M_PUB_STATIC_SYNCHRONIZED:
0590: numberOfSpecifiers = 3;
0591: specifiers = new java.lang.String[numberOfSpecifiers];
0592: specifiers[0] = "public";
0593: specifiers[1] = "static";
0594: specifiers[2] = "synchronized";
0595: break;
0596: case Constants.M_PUB_SYNCHRONIZED:
0597: numberOfSpecifiers = 2;
0598: specifiers = new java.lang.String[numberOfSpecifiers];
0599: specifiers[0] = "public";
0600: specifiers[1] = "synchronized";
0601:
0602: break;
0603: case Constants.M_PUB_STRICT:
0604: numberOfSpecifiers = 2;
0605: specifiers = new java.lang.String[numberOfSpecifiers];
0606: specifiers[0] = "public";
0607: specifiers[1] = "strictfp";
0608:
0609: break;
0610:
0611: case Constants.M_PRIVATE:
0612: numberOfSpecifiers = 1;
0613: specifiers = new java.lang.String[numberOfSpecifiers];
0614: specifiers[0] = "private";
0615: break;
0616:
0617: case Constants.M_PRIVATE_FINAL:
0618: numberOfSpecifiers = 2;
0619: specifiers = new java.lang.String[numberOfSpecifiers];
0620: specifiers[0] = "private";
0621: specifiers[1] = "final";
0622: break;
0623: case Constants.M_PRIVATE_NATIVE:
0624: numberOfSpecifiers = 2;
0625: specifiers = new java.lang.String[numberOfSpecifiers];
0626: specifiers[0] = "private";
0627: specifiers[1] = "native";
0628:
0629: break;
0630: case Constants.M_PRIVATE_STATIC:
0631: numberOfSpecifiers = 2;
0632: specifiers = new java.lang.String[numberOfSpecifiers];
0633: specifiers[0] = "private";
0634: specifiers[1] = "static";
0635:
0636: break;
0637: case Constants.M_PRIVATE_STATIC_FINAL:
0638: numberOfSpecifiers = 3;
0639: specifiers = new java.lang.String[numberOfSpecifiers];
0640: specifiers[0] = "private";
0641: specifiers[1] = "static";
0642: specifiers[2] = "final";
0643:
0644: break;
0645: case Constants.M_PRIVATE_STATIC_FINAL_NATIVE:
0646: numberOfSpecifiers = 4;
0647: specifiers = new java.lang.String[numberOfSpecifiers];
0648: specifiers[0] = "private";
0649: specifiers[1] = "static";
0650: specifiers[2] = "final";
0651: specifiers[3] = "native";
0652: break;
0653: case Constants.M_PRIVATE_STATIC_FINAL_STRICT:
0654: numberOfSpecifiers = 4;
0655: specifiers = new java.lang.String[numberOfSpecifiers];
0656: specifiers[0] = "private";
0657: specifiers[1] = "static";
0658: specifiers[2] = "final";
0659: specifiers[3] = "strictfp";
0660:
0661: break;
0662: case Constants.M_PRIVATE_STATIC_FINAL_SYNCH:
0663: numberOfSpecifiers = 4;
0664: specifiers = new java.lang.String[numberOfSpecifiers];
0665: specifiers[0] = "private";
0666: specifiers[1] = "static";
0667: specifiers[2] = "final";
0668: specifiers[3] = "synchronized";
0669:
0670: break;
0671: case Constants.M_PRIVATE_STATIC_FINAL_SYNCH_NATIVE:
0672: numberOfSpecifiers = 5;
0673: specifiers = new java.lang.String[numberOfSpecifiers];
0674: specifiers[0] = "private";
0675: specifiers[1] = "static";
0676: specifiers[2] = "final";
0677: specifiers[3] = "native";
0678: specifiers[4] = "synchronized";
0679:
0680: break;
0681:
0682: case Constants.M_PRIVATE_STATIC_FINAL_SYNCH_STRICT:
0683: numberOfSpecifiers = 5;
0684: specifiers = new java.lang.String[numberOfSpecifiers];
0685: specifiers[0] = "private";
0686: specifiers[1] = "static";
0687: specifiers[2] = "final";
0688: specifiers[3] = "synchronized";
0689: specifiers[4] = "strictfp";
0690: break;
0691: case Constants.M_PRIVATE_STATIC_NATIVE:
0692: numberOfSpecifiers = 3;
0693: specifiers = new java.lang.String[numberOfSpecifiers];
0694: specifiers[0] = "private";
0695: specifiers[1] = "static";
0696: specifiers[2] = "native";
0697: break;
0698: case Constants.M_PRIVATE_STATIC_STRICT:
0699: numberOfSpecifiers = 3;
0700: specifiers = new java.lang.String[numberOfSpecifiers];
0701: specifiers[0] = "private";
0702: specifiers[1] = "static";
0703: specifiers[2] = "strictfp";
0704: break;
0705: case Constants.M_PRIVATE_STATIC_SYNCHRONIZED:
0706: numberOfSpecifiers = 3;
0707: specifiers = new java.lang.String[numberOfSpecifiers];
0708: specifiers[0] = "private";
0709: specifiers[1] = "static";
0710: specifiers[2] = "synchronized";
0711: break;
0712: case Constants.M_PRIVATE_SYNCHRONIZED:
0713: numberOfSpecifiers = 2;
0714: specifiers = new java.lang.String[numberOfSpecifiers];
0715: specifiers[0] = "private";
0716: specifiers[1] = "synchronized";
0717:
0718: break;
0719: case Constants.M_PRIVATE_STRICT:
0720: numberOfSpecifiers = 2;
0721: specifiers = new java.lang.String[numberOfSpecifiers];
0722: specifiers[0] = "private";
0723: specifiers[1] = "strictfp";
0724:
0725: break;
0726:
0727: case Constants.M_PROTECTED:
0728: numberOfSpecifiers = 1;
0729: specifiers = new java.lang.String[numberOfSpecifiers];
0730: specifiers[0] = "protected";
0731: break;
0732: case Constants.M_PROTECTED_ABS:
0733: numberOfSpecifiers = 2;
0734: specifiers = new java.lang.String[numberOfSpecifiers];
0735: specifiers[0] = "protected";
0736: specifiers[1] = "abstract";
0737: break;
0738: case Constants.M_PROTECTED_FINAL:
0739: numberOfSpecifiers = 2;
0740: specifiers = new java.lang.String[numberOfSpecifiers];
0741: specifiers[0] = "protected";
0742: specifiers[1] = "final";
0743: break;
0744: case Constants.M_PROTECTED_NATIVE:
0745: numberOfSpecifiers = 2;
0746: specifiers = new java.lang.String[numberOfSpecifiers];
0747: specifiers[0] = "protected";
0748: specifiers[1] = "native";
0749:
0750: break;
0751: case Constants.M_PROTECTED_STATIC:
0752: numberOfSpecifiers = 2;
0753: specifiers = new java.lang.String[numberOfSpecifiers];
0754: specifiers[0] = "protected";
0755: specifiers[1] = "static";
0756:
0757: break;
0758: case Constants.M_PROTECTED_STATIC_FINAL:
0759: numberOfSpecifiers = 3;
0760: specifiers = new java.lang.String[numberOfSpecifiers];
0761: specifiers[0] = "protected";
0762: specifiers[1] = "static";
0763: specifiers[2] = "final";
0764:
0765: break;
0766: case Constants.M_PROTECTED_STATIC_FINAL_NATIVE:
0767: numberOfSpecifiers = 4;
0768: specifiers = new java.lang.String[numberOfSpecifiers];
0769: specifiers[0] = "protected";
0770: specifiers[1] = "static";
0771: specifiers[2] = "final";
0772: specifiers[3] = "native";
0773: break;
0774: case Constants.M_PROTECTED_STATIC_FINAL_STRICT:
0775: numberOfSpecifiers = 4;
0776: specifiers = new java.lang.String[numberOfSpecifiers];
0777: specifiers[0] = "protected";
0778: specifiers[1] = "static";
0779: specifiers[2] = "final";
0780: specifiers[3] = "strictfp";
0781:
0782: break;
0783: case Constants.M_PROTECTED_STATIC_FINAL_SYNCH:
0784: numberOfSpecifiers = 4;
0785: specifiers = new java.lang.String[numberOfSpecifiers];
0786: specifiers[0] = "protected";
0787: specifiers[1] = "static";
0788: specifiers[2] = "final";
0789: specifiers[3] = "synchronized";
0790:
0791: break;
0792: case Constants.M_PROTECTED_STATIC_FINAL_SYNCH_NATIVE:
0793: numberOfSpecifiers = 5;
0794: specifiers = new java.lang.String[numberOfSpecifiers];
0795: specifiers[0] = "protected";
0796: specifiers[1] = "static";
0797: specifiers[2] = "final";
0798: specifiers[3] = "native";
0799: specifiers[4] = "synchronized";
0800:
0801: break;
0802:
0803: case Constants.M_PROTECTED_STATIC_FINAL_SYNCH_STRICT:
0804: numberOfSpecifiers = 5;
0805: specifiers = new java.lang.String[numberOfSpecifiers];
0806: specifiers[0] = "protected";
0807: specifiers[1] = "static";
0808: specifiers[2] = "final";
0809: specifiers[3] = "synchronized";
0810: specifiers[4] = "strictfp";
0811: break;
0812:
0813: case Constants.M_PROTECTED_STATIC_NATIVE:
0814: numberOfSpecifiers = 3;
0815: specifiers = new java.lang.String[numberOfSpecifiers];
0816: specifiers[0] = "protected";
0817: specifiers[1] = "static";
0818: specifiers[2] = "native";
0819: break;
0820: case Constants.M_PROTECTED_STATIC_STRICT:
0821: numberOfSpecifiers = 3;
0822: specifiers = new java.lang.String[numberOfSpecifiers];
0823: specifiers[0] = "protected";
0824: specifiers[1] = "static";
0825: specifiers[2] = "strictfp";
0826: break;
0827: case Constants.M_PROTECTED_STATIC_SYNCHRONIZED:
0828: numberOfSpecifiers = 3;
0829: specifiers = new java.lang.String[numberOfSpecifiers];
0830: specifiers[0] = "protected";
0831: specifiers[1] = "static";
0832: specifiers[2] = "synchronized";
0833: break;
0834: case Constants.M_PROTECTED_SYNCHRONIZED:
0835: numberOfSpecifiers = 2;
0836: specifiers = new java.lang.String[numberOfSpecifiers];
0837: specifiers[0] = "protected";
0838: specifiers[1] = "synchronized";
0839: break;
0840:
0841: case Constants.M_PROTECTED_STRICT:
0842: numberOfSpecifiers = 2;
0843: specifiers = new java.lang.String[numberOfSpecifiers];
0844: specifiers[0] = "protected";
0845: specifiers[1] = "strictfp";
0846: break;
0847:
0848: case Constants.M_STATIC:
0849: numberOfSpecifiers = 1;
0850: specifiers = new java.lang.String[numberOfSpecifiers];
0851: specifiers[0] = "static";
0852: break;
0853:
0854: case Constants.M_FINAL:
0855: numberOfSpecifiers = 1;
0856: specifiers = new java.lang.String[numberOfSpecifiers];
0857: specifiers[0] = "final";
0858: break;
0859:
0860: case Constants.M_SYNCHRONIZED:
0861: numberOfSpecifiers = 1;
0862: specifiers = new java.lang.String[numberOfSpecifiers];
0863: specifiers[0] = "synchronized";
0864: break;
0865:
0866: case Constants.M_NATIVE:
0867: numberOfSpecifiers = 1;
0868: specifiers = new java.lang.String[numberOfSpecifiers];
0869: specifiers[0] = "native";
0870: break;
0871:
0872: case Constants.M_ABS:
0873: numberOfSpecifiers = 1;
0874: specifiers = new java.lang.String[numberOfSpecifiers];
0875: specifiers[0] = "abstract";
0876: break;
0877:
0878: case Constants.M_STRICT:
0879: numberOfSpecifiers = 1;
0880: specifiers = new java.lang.String[numberOfSpecifiers];
0881: specifiers[0] = "strictfp";
0882: break;
0883:
0884: case Constants.M_STATIC_FINAL:
0885: numberOfSpecifiers = 2;
0886: specifiers = new java.lang.String[numberOfSpecifiers];
0887: specifiers[0] = "static";
0888: specifiers[1] = "final";
0889: break;
0890:
0891: case Constants.M_STATIC_SYNCHRONIZED:
0892: numberOfSpecifiers = 2;
0893: specifiers = new java.lang.String[numberOfSpecifiers];
0894: specifiers[0] = "static";
0895: specifiers[1] = "synchronized";
0896: break;
0897:
0898: case Constants.M_STATIC_NATIVE:
0899: numberOfSpecifiers = 2;
0900: specifiers = new java.lang.String[numberOfSpecifiers];
0901: specifiers[0] = "static";
0902: specifiers[1] = "native";
0903: break;
0904:
0905: case Constants.M_STATIC_STRICT:
0906: numberOfSpecifiers = 2;
0907: specifiers = new java.lang.String[numberOfSpecifiers];
0908: specifiers[0] = "static";
0909: specifiers[1] = "strictfp";
0910: break;
0911:
0912: case Constants.M_STATIC_FINAL_SYNCH:
0913: numberOfSpecifiers = 3;
0914: specifiers = new java.lang.String[numberOfSpecifiers];
0915: specifiers[0] = "static";
0916: specifiers[1] = "final";
0917: specifiers[2] = "synchronized";
0918: break;
0919:
0920: case Constants.M_STATIC_FINAL_NATIVE:
0921: numberOfSpecifiers = 3;
0922: specifiers = new java.lang.String[numberOfSpecifiers];
0923: specifiers[0] = "static";
0924: specifiers[1] = "final";
0925: specifiers[2] = "native";
0926: break;
0927:
0928: case Constants.M_STATIC_FINAL_STRICT:
0929: numberOfSpecifiers = 3;
0930: specifiers = new java.lang.String[numberOfSpecifiers];
0931: specifiers[0] = "static";
0932: specifiers[1] = "final";
0933: specifiers[2] = "strictfp";
0934: break;
0935: case Constants.M_STATIC_FINAL_SYNCH_NATIVE:
0936: numberOfSpecifiers = 4;
0937: specifiers = new java.lang.String[numberOfSpecifiers];
0938: specifiers[0] = "static";
0939: specifiers[1] = "final";
0940: specifiers[2] = "synchronized";
0941: specifiers[3] = "native";
0942: break;
0943: case Constants.M_STATIC_FINAL_SYNCH_STRICT:
0944: numberOfSpecifiers = 4;
0945: specifiers = new java.lang.String[numberOfSpecifiers];
0946: specifiers[0] = "static";
0947: specifiers[1] = "final";
0948: specifiers[2] = "synchronized";
0949: specifiers[3] = "strictfp";
0950: break;
0951:
0952: case Constants.M_FINAL_SYNCH:
0953: numberOfSpecifiers = 2;
0954: specifiers = new java.lang.String[numberOfSpecifiers];
0955: specifiers[0] = "final";
0956: specifiers[1] = "synchronized";
0957: break;
0958:
0959: case Constants.M_FINAL_NATIVE:
0960: numberOfSpecifiers = 2;
0961: specifiers = new java.lang.String[numberOfSpecifiers];
0962: specifiers[0] = "final";
0963: specifiers[1] = "native";
0964: break;
0965:
0966: case Constants.M_FINAL_STRICT:
0967: numberOfSpecifiers = 2;
0968: specifiers = new java.lang.String[numberOfSpecifiers];
0969: specifiers[0] = "final";
0970: specifiers[1] = "strictfp";
0971: break;
0972:
0973: case Constants.M_FINAL_SYNCH_NATIVE:
0974: numberOfSpecifiers = 3;
0975: specifiers = new java.lang.String[numberOfSpecifiers];
0976: specifiers[0] = "final";
0977: specifiers[1] = "synchronized";
0978: specifiers[2] = "native";
0979: break;
0980:
0981: case Constants.M_FINAL_SYNCH_STRICT:
0982: numberOfSpecifiers = 3;
0983: specifiers = new java.lang.String[numberOfSpecifiers];
0984: specifiers[0] = "final";
0985: specifiers[1] = "synchronized";
0986: specifiers[2] = "strictfp";
0987: break;
0988:
0989: case Constants.M_SYNCH_NATIVE:
0990: numberOfSpecifiers = 2;
0991: specifiers = new java.lang.String[numberOfSpecifiers];
0992: specifiers[0] = "native";
0993: specifiers[1] = "synchronized";
0994: break;
0995:
0996: case Constants.M_SYNCH_STRICT:
0997: numberOfSpecifiers = 2;
0998: specifiers = new java.lang.String[numberOfSpecifiers];
0999: specifiers[0] = "strictfp";
1000: specifiers[1] = "synchronized";
1001: break;
1002: default:
1003: numberOfSpecifiers = 1;
1004: specifiers = new java.lang.String[numberOfSpecifiers];
1005: // specifiers[0]=Constants.UNKNOWNACCESSORS; Not Correct for Default
1006: // Access
1007: specifiers[0] = "";
1008:
1009: }
1010: return specifiers;
1011: }
1012:
1013: // METHOD BUGGY NEED TO FIX
1014: public static int getNumberOfParameters(String parameterString) {
1015: /*
1016: * parameterString = parameterString.substring(1); parameterString =
1017: * parameterString.substring(0,parameterString.length()-1);
1018: */
1019: int charIndex = 0;
1020: ArrayList parameters = new ArrayList();
1021: while (parameterString.length() > 0) {
1022: if (parameterString.startsWith("L")) {
1023: java.lang.String objectString = parameterString
1024: .substring(0, parameterString.indexOf(";"));
1025: objectString = objectString.replace('/', '.');
1026: parameters.add(objectString);
1027: charIndex = charIndex + (objectString.length() + 2);
1028: parameterString = parameterString
1029: .substring(parameterString.indexOf(";") + 1);
1030: } else {
1031: char parameterChar = parameterString.charAt(0);
1032: if (parameterChar == ')')
1033: break;
1034: if (parameterChar == '[') {
1035: java.lang.String arrString = "[";
1036: if (parameterString.indexOf(";") != -1) {
1037: java.lang.String objectString = parameterString
1038: .substring(0, parameterString
1039: .indexOf(";"));
1040: objectString = objectString.replace('/', '.');
1041: parameters.add(objectString);
1042: parameterString = parameterString
1043: .substring(parameterString.indexOf(";") + 1);
1044: } else {
1045: parameterString = parameterString
1046: .substring(parameterString.indexOf("[") + 1);
1047: }
1048: } else {
1049: if (parameterChar == 'I') {
1050: parameters.add("int");
1051: }
1052: if (parameterChar == 'B') {
1053: parameters.add("byte");
1054: }
1055: if (parameterChar == 'C') {
1056: parameters.add("char");
1057: }
1058: if (parameterChar == 'D') {
1059: parameters.add("double");
1060: }
1061: if (parameterChar == 'F') {
1062: parameters.add("float");
1063: }
1064: if (parameterChar == 'J') {
1065: parameters.add("long");
1066: }
1067: if (parameterChar == 'S') {
1068: parameters.add("short");
1069: }
1070: if (parameterChar == 'Z') {
1071: parameters.add("boolean");
1072: }
1073: parameterString = parameterString.substring(1);
1074: }
1075: }
1076: }
1077: return parameters.size();
1078: }
1079:
1080: public static String getPrevCurSpace() {
1081: return prevCurSpace;
1082: }
1083:
1084: // Following code are used for formatting the decompiled code
1085: // for user friendliness.
1086:
1087: private static String prevCurSpace = " ";
1088:
1089: private final static String initialMethodSpace = " ";
1090:
1091: private final static java.lang.String incrementSpace = " ";
1092:
1093: private static java.lang.String currentSpace = initialMethodSpace
1094: .concat(incrementSpace);
1095:
1096: private static final java.lang.String disSpace = initialMethodSpace
1097: .concat(incrementSpace);
1098:
1099: public static void resetCurrentSpace() {
1100: currentSpace = initialMethodSpace.concat(incrementSpace);
1101: }
1102:
1103: /***************************************************************************
1104: * This is the amount of space to be used to output to the result before
1105: * adding on something new to codeStatements in parseJvmCode method of
1106: * Decompiler Class.
1107: *
1108: */
1109:
1110: public static java.lang.String getCurrentSpace() {
1111: return currentSpace;
1112: }
1113:
1114: /***************************************************************************
1115: * This is the amount of space which will be used to add on to the
1116: * currentSpace Or the amount of space to be removed from the currentSpace
1117: * for the cases when '{' and '}' respectively
1118: *
1119: */
1120:
1121: public static java.lang.String getIncrementSpace() {
1122: return incrementSpace;
1123: }
1124:
1125: /***************************************************************************
1126: * Returns the space to be added before declaration of a method
1127: *
1128: */
1129: public static String getInitialMethodSpace() {
1130: return initialMethodSpace;
1131: }
1132:
1133: // The only setter method
1134: /***************************************************************************
1135: * Intentionally the only setter method. Use this to set the currentSpace
1136: * when the amount of space has to be changed. ex:
1137: * Util.setCurrentSpace(Util.getCurrentSpace().concat(Util.getIncrementSpace());
1138: */
1139:
1140: public static void setCurrentSpace(java.lang.String newSpace) {
1141: currentSpace = newSpace;
1142: }
1143:
1144: /***************************************************************************
1145: * NOTE: For proper result, ensure that the input to this method contains
1146: * "\n" already. That is , if the input contains a { then ensure that { is
1147: * preceded and followed by a \n character
1148: *
1149: * Also Dont pass as input a statement like while(true){} In this case pass
1150: * while(true)\n{\n first time and make second call as }\n
1151: *
1152: * Even for simple statment like int i=1 pass it as int i=1\n
1153: *
1154: * Purpose of this method is just to format the content in a user friendly
1155: * readable manner and not take into account conditions where the input does
1156: * not have a delimiter like line separator character.
1157: *
1158: * Need to take care of the above while passing input
1159: *
1160: * Keep these points in mind generally when using this function:
1161: *
1162: * 1> Try not use a '\n' as the character before '}' (check example below)
1163: * 2> Try to include a '\n' before and after a '{' as this will ensure line
1164: * separbility between 2 lines. NOTE: this function does not take trouble of
1165: * introducing a new line character . SO user should include '\n' in the
1166: * input itself 3> Very Importans point: When using a '} ' in the input
1167: * ensure that there is NO more than a SINGLE of }. So when there are 2 or
1168: * more of '}' just use a temporary strings to include these '}' and format
1169: * separately. Else the output may not be formatted neatly. Example:
1170: *
1171: * codeStatements+="}\n\n}"; for the baove: String temp1="}"; // Assuming
1172: * previous line has included new line character
1173: * temp1=Util.formatDecompiledStatement(temp1); codeStatements+=temp1;
1174: * codeStatements+="\n\n"; temp1="}";
1175: * temp1=Util.formatDecompiledStatement(temp1); codeStatements+=temp1;
1176: *
1177: * It is bit laborious but comes correctly (Remember it was fully
1178: * intentional to keep it simple but effective -:) )
1179: *
1180: * @param input
1181: *
1182: */
1183:
1184: public static String formatDecompiledStatement_DONOTUSE(String input) {
1185: String formattedOutput = "";
1186: int openFlowerBracket = input.indexOf("{");
1187: int closeFlowerBracket = input.indexOf("}");
1188: int slashn = input.indexOf("\n");
1189: java.lang.String part1 = "";
1190: java.lang.String part2 = "";
1191: if (openFlowerBracket != -1 && closeFlowerBracket == -1) {
1192: boolean slashnAt0 = false;
1193: input = Util.trimString(input);
1194: slashn = input.indexOf("\n");
1195: if (slashn == 0) {
1196: slashnAt0 = true;
1197: formattedOutput += "\n";
1198: input = input.substring(1);
1199: }
1200: formattedOutput += currentSpace;
1201: /*
1202: * if(slashnAt0) part1=input.substring(0,openFlowerBracket-1); else
1203: * part1=input.substring(0,openFlowerBracket);
1204: */
1205: openFlowerBracket = input.indexOf("{");
1206: part1 = input.substring(0, openFlowerBracket);
1207: part2 = input.substring(openFlowerBracket);
1208: part2 = part2.trim();
1209: formattedOutput += part1;
1210: formattedOutput += currentSpace;
1211: if (part2.indexOf("{") == 0) {
1212: boolean include = false;
1213: int t = 1;
1214: if (part2.length() > t) {
1215: char c = part2.charAt(t);
1216: while (c == '\n') {
1217: include = true;
1218: t++;
1219: if (part2.length() > t)
1220: c = part2.charAt(t);
1221: else
1222: break;
1223: }
1224: }
1225: if (t < part2.length())
1226: part2 = part2.substring(t);
1227: if (include) {
1228: formattedOutput += "{";
1229: formattedOutput += "\n" + currentSpace + " "
1230: + part2 + "\n";
1231: } else
1232: formattedOutput += "\n" + currentSpace + part2
1233: + "\n";
1234: } else
1235: formattedOutput += part2;
1236:
1237: updateCurrentSpace(Util.getIncrementSpace(), "add");
1238: return formattedOutput;
1239: }
1240: if (openFlowerBracket == -1 && closeFlowerBracket != -1) {
1241: updateCurrentSpace(Util.getIncrementSpace(), "remove");
1242: formattedOutput += Util.getCurrentSpace();
1243: boolean partsFormed = false;
1244: if (slashn != -1 && slashn < closeFlowerBracket) {
1245: part1 = input.substring(0, closeFlowerBracket);
1246: part2 = input.substring(closeFlowerBracket);
1247: partsFormed = true;
1248: }
1249: if (partsFormed) {
1250: formattedOutput += part1;
1251: formattedOutput += Util.getCurrentSpace();
1252: formattedOutput += part2;
1253: } else
1254: formattedOutput += input;
1255: return formattedOutput;
1256: }
1257: if (openFlowerBracket == -1 && closeFlowerBracket == -1
1258: && input.trim().length() > 0) {
1259: input = Util.trimString(input);
1260: boolean partsFormed = false;
1261: slashn = input.indexOf("\n");
1262: if (slashn == 0) {
1263: part1 = input.substring(0, slashn + 1);
1264: part2 = input.substring(slashn + 1);
1265: partsFormed = true;
1266: }
1267: if (partsFormed) {
1268: formattedOutput += part1;
1269: formattedOutput += Util.getCurrentSpace();
1270: formattedOutput += part2;
1271: }
1272: if (!partsFormed) {
1273: formattedOutput += currentSpace;
1274: formattedOutput += input;
1275: }
1276: return formattedOutput;
1277: }
1278: //
1279: if (openFlowerBracket != -1 && closeFlowerBracket != -1) {
1280: boolean slashnAt0 = false;
1281: input = Util.trimString(input);
1282: slashn = input.indexOf("\n");
1283: if (slashn == 0) {
1284: slashnAt0 = true;
1285: formattedOutput += "\n";
1286: input = input.substring(1);
1287: }
1288: formattedOutput += currentSpace;
1289: /*
1290: * if(slashnAt0) part1=input.substring(0,openFlowerBracket-1); else
1291: * part1=input.substring(0,openFlowerBracket);
1292: */
1293: openFlowerBracket = input.indexOf("{");
1294: part1 = input.substring(0, openFlowerBracket);
1295: part2 = input.substring(openFlowerBracket);
1296: part2 = part2.trim();
1297: formattedOutput += part1;
1298: formattedOutput += currentSpace;
1299:
1300: boolean include = false;
1301: int t = 1;
1302: if (part2.length() > t) {
1303: char c = part2.charAt(t);
1304: while (c == '\n') {
1305: include = true;
1306: t++;
1307: if (part2.length() > t)
1308: c = part2.charAt(t);
1309: else
1310: break;
1311: }
1312: }
1313: if (t < part2.length())
1314: part2 = part2.substring(t);
1315: if (include) {
1316: formattedOutput += "{";
1317: if (part2.indexOf("}") != -1) {
1318: java.lang.String sub = part2.substring(0, part2
1319: .indexOf("}"));
1320: formattedOutput += "\n" + currentSpace + " " + sub
1321: + "\n";
1322: updateCurrentSpace(Util.getIncrementSpace(),
1323: "remove");
1324: formattedOutput += currentSpace + "}\n";
1325:
1326: } else
1327: formattedOutput += "\n" + currentSpace + " "
1328: + part2 + "\n";
1329: } else {
1330: formattedOutput += "{";
1331: if (part2.indexOf("}") != -1) {
1332: java.lang.String sub = part2.substring(0, part2
1333: .indexOf("}"));
1334: formattedOutput += "\n" + currentSpace + " " + sub
1335: + "\n";
1336: updateCurrentSpace(Util.getIncrementSpace(),
1337: "remove");
1338: formattedOutput += currentSpace + " " + "}\n";
1339:
1340: } else {
1341: if (part2.equals("{") == false)
1342: formattedOutput += "\n" + currentSpace + " "
1343: + part2 + "\n";
1344: if (part2.indexOf("{") >= 0) {
1345: int t1 = part2.indexOf("{");
1346: // if((t1+1) != part2.length())
1347: // {
1348: if ((t1 + 1) < part2.length()) {
1349: part2 = part2.substring(t1 + 1);
1350: formattedOutput += "\n" + currentSpace
1351: + " " + part2 + "\n";
1352: }
1353: // }
1354:
1355: }
1356: }
1357: }
1358:
1359: updateCurrentSpace(Util.getIncrementSpace(), "add");
1360: return formattedOutput;
1361: }
1362:
1363: return input; // Default Case;
1364: }
1365:
1366: public static void updateCurrentSpace(java.lang.String changeValue,
1367: java.lang.String typeofupdate) {
1368: prevCurSpace = Util.getCurrentSpace();
1369: if (typeofupdate.equals("add")) {
1370: setCurrentSpace(Util.getCurrentSpace().concat(changeValue));
1371: }
1372: if (typeofupdate.equals("remove")) {
1373: /*
1374: * int numberOfTabsReqd=Util.getCurrentSpace().lastIndexOf("\t");
1375: * java.lang.String tab="\t";
1376: */
1377: java.lang.String temp = "";
1378: int incrLength = incrementSpace.length();
1379: int upperLimit = Util.getCurrentSpace().length()
1380: - incrLength;
1381: if (upperLimit < Util.getCurrentSpace().length()
1382: && upperLimit >= 0)
1383: temp = Util.getCurrentSpace().substring(0, upperLimit);
1384: else
1385: temp = Util.getCurrentSpace();
1386: /*
1387: * for(int s=1;s<=numberOfTabsReqd;s++) temp+=tab;
1388: */
1389: Util.setCurrentSpace(temp);
1390: }
1391:
1392: }
1393:
1394: public static java.lang.String formatFieldsOrMethodHeader(
1395: java.lang.String input, java.lang.String type) {
1396: if (input != null && input.trim().length() > 0) {
1397:
1398: /*
1399: * input=input.trim(); if(input.charAt(0)=='\n')
1400: * input=input.substring(1);
1401: */
1402:
1403: input = trimString(input);
1404: java.lang.String formatttedInputStmt = "";
1405: if (type.indexOf("field") != -1
1406: && type.indexOf("method") == -1)
1407: formatttedInputStmt += Util.getInitialMethodSpace();
1408: java.lang.String part1 = "";
1409: java.lang.String part2 = "";
1410:
1411: int openFlowerBracket = input.indexOf("{");
1412: int closeFlowerBracket = input.indexOf("}");
1413: if (openFlowerBracket != -1) {
1414: formatttedInputStmt += Util.getInitialMethodSpace();
1415: part1 = input.substring(0, openFlowerBracket);
1416: part2 = input.substring(openFlowerBracket);
1417: formatttedInputStmt += part1;
1418: formatttedInputStmt += Util.getInitialMethodSpace();
1419: formatttedInputStmt += part2;
1420: return formatttedInputStmt;
1421: }
1422: if (closeFlowerBracket != -1) {
1423: formatttedInputStmt += Util.getInitialMethodSpace();
1424: part1 = input.substring(0, closeFlowerBracket);
1425: part2 = input.substring(closeFlowerBracket);
1426: formatttedInputStmt += part1;
1427: if (part1.trim().length() > 0)
1428: formatttedInputStmt += Util.getInitialMethodSpace();
1429: formatttedInputStmt += part2;
1430: return formatttedInputStmt;
1431: }
1432: if (type.indexOf("method") != -1
1433: && type.indexOf("field") == -1)
1434: formatttedInputStmt += Util.getInitialMethodSpace();
1435:
1436: formatttedInputStmt += input;
1437: return formatttedInputStmt;
1438: }
1439:
1440: else
1441: return input;
1442: }
1443:
1444: public static java.lang.String trimString(String input) {
1445: if (input == null)
1446: return input;
1447: String trimmedString = "";
1448: boolean skip = false;
1449: int start = 0;
1450:
1451: if (input.length() > 0) {
1452: char space = input.charAt(0);
1453: char tab = input.charAt(0);
1454: if (space == ' ' || tab == '\t')
1455: skip = true;
1456:
1457: while (skip) {
1458: start = start + 1;
1459: if (input.length() > start) {
1460: space = input.charAt(start);
1461: tab = input.charAt(start);
1462: if (space == ' ' || tab == '\t')
1463: skip = true;
1464: else
1465: skip = false;
1466: } else
1467: skip = false;
1468: }
1469: }
1470: trimmedString = input.substring(start);
1471: return trimmedString;
1472:
1473: }
1474:
1475: // Expects String as a member of Array
1476: public static ArrayList removeDuplicates(ArrayList input) {
1477: ArrayList updatedList = new ArrayList();
1478: if (input != null && input.size() > 0) {
1479: String[] fullList = (java.lang.String[]) input
1480: .toArray(new java.lang.String[] {});
1481: java.util.Arrays.sort(fullList);
1482: updatedList.add(fullList[0]);
1483: for (int s = 1; s < fullList.length; s++) {
1484: if (s < fullList.length) {
1485: String currentItem = fullList[s];
1486: currentItem = currentItem.trim();
1487: int prev = s - 1;
1488: String temp = "";
1489: if (prev >= 0 && prev < fullList.length) {
1490: temp = fullList[prev];
1491: temp = temp.trim();
1492: if (temp.equals(currentItem) == false) {
1493: if (currentItem.indexOf("[") == -1)
1494: updatedList.add(currentItem);
1495: }
1496: }
1497:
1498: }
1499:
1500: }
1501:
1502: }
1503: return updatedList;
1504:
1505: }
1506:
1507: // sbelur:
1508: /***************************************************************************
1509: * Be careful while using this method. Ensure that the individual objects in
1510: * input AraryList implement Comparable Interface This method was written
1511: * when unique Integer Objects were required as the earlier function ws only
1512: * meant for java.lang.String Objects
1513: */
1514:
1515: public static List genericRemoveDuplicates(List input) {
1516: try {
1517: ArrayList updatedList = new ArrayList();
1518: if (input != null && input.size() > 0) {
1519: Object[] fullList = input.toArray();
1520: java.util.Arrays.sort(fullList);
1521: updatedList.add(fullList[0]);
1522: for (int s = 1; s < fullList.length; s++) {
1523: if (s < fullList.length) {
1524: Object currentItem = fullList[s];
1525: int prev = s - 1;
1526: Object temp;
1527: if (prev >= 0 && prev < fullList.length) {
1528: temp = fullList[prev];
1529:
1530: if (temp.equals(currentItem) == false) {
1531: updatedList.add(currentItem);
1532: }
1533: }
1534:
1535: }
1536:
1537: }
1538:
1539: }
1540: return updatedList;
1541: } catch (Throwable t) {
1542:
1543: return input;
1544:
1545: }
1546:
1547: }
1548:
1549: public static Object reInitializeStructure(Object o) {
1550:
1551: if (o instanceof ArrayList) {
1552: return new ArrayList(); // Just send a empty ArrayList back
1553: } else {
1554: // PlaceHolder for others like HashMap etc
1555: return null;
1556: }
1557:
1558: }
1559:
1560: static ArrayList parsedSignature = null;
1561:
1562: static ArrayList returnSignature = null;
1563:
1564: static boolean isParameterArray = false;
1565:
1566: public static ArrayList getParsedSignatureAsList() {
1567: return parsedSignature;
1568: }
1569:
1570: public static void parseDescriptor(java.lang.String descriptor) {
1571: ArrayList parameters = new ArrayList();
1572: parsedSignature = parameters;
1573: int charIndex = 0;
1574: java.lang.String parameterString = descriptor.substring(1,
1575: descriptor.lastIndexOf(")"));
1576: /*
1577: * java.lang.String returnString =
1578: * descriptor.substring(descriptor.lastIndexOf(")")+1);
1579: * if(returnString.trim().length() > 0){
1580: * if(returnString.trim().charAt(0)=='L' ||
1581: * returnString.trim().charAt(0)=='[')
1582: * this.setReturnTypeAsObjectOrArrayType(true); else
1583: * this.setReturnTypeAsObjectOrArrayType(false); }
1584: */
1585:
1586: java.lang.String arrString = "";
1587: // while(charIndex < parameterString.length())
1588: while (parameterString.length() > 0) {
1589: if (parameterString.startsWith("L")) {
1590: java.lang.String objectString = parameterString
1591: .substring(0, parameterString.indexOf(";"));
1592: objectString = objectString.replace('/', '.');
1593: parameters.add(objectString);
1594: charIndex = charIndex + (objectString.length() + 2);
1595: parameterString = parameterString
1596: .substring(parameterString.indexOf(";") + 1);
1597: } else {
1598: char parameterChar = parameterString.charAt(0);
1599: if (parameterChar == '[') {
1600: arrString = "";
1601: while (parameterString.startsWith("[")) {
1602: arrString += "[";
1603: parameterString = parameterString.substring(1,
1604: parameterString.length());
1605: isParameterArray = true;
1606: }
1607: java.lang.String objectString = "";
1608: if (parameterString.charAt(0) == 'L') {
1609: objectString = parameterString.substring(0,
1610: parameterString.indexOf(";"));
1611: parameterString = parameterString
1612: .substring(parameterString.indexOf(";") + 1);
1613: objectString = objectString.replace('/', '.');
1614: parameters.add(arrString + objectString);
1615: isParameterArray = false;
1616: }
1617: /*
1618: * while(objectString.startsWith("[")) { arrString += "[";
1619: * objectString =
1620: * objectString.substring(1,objectString.length()); }
1621: * objectString = objectString.substring(1); objectString =
1622: * objectString.replace('/','.');
1623: * parameters.add(objectString); charIndex = charIndex +
1624: * (objectString.length() + 2);
1625: * parameters.add(arrString+objectString);
1626: */
1627:
1628: } else {
1629: if (parameterChar == 'I') {
1630: if (isParameterArray) {
1631: parameters.add(arrString + "int");
1632: isParameterArray = false;
1633: } else {
1634: parameters.add("int");
1635: }
1636: }
1637: if (parameterChar == 'B') {
1638: if (isParameterArray) {
1639: parameters.add(arrString + "byte");
1640: isParameterArray = false;
1641: } else {
1642: parameters.add("byte");
1643: }
1644: }
1645: if (parameterChar == 'C') {
1646: if (isParameterArray) {
1647: parameters.add(arrString + "char");
1648: isParameterArray = false;
1649: } else {
1650: parameters.add("char");
1651: }
1652: }
1653: if (parameterChar == 'D') {
1654: if (isParameterArray) {
1655: parameters.add(arrString + "double");
1656: isParameterArray = false;
1657: } else {
1658: parameters.add("double");
1659: }
1660: }
1661: if (parameterChar == 'F') {
1662: if (isParameterArray) {
1663: parameters.add(arrString + "float");
1664: isParameterArray = false;
1665: } else {
1666: parameters.add("float");
1667: }
1668: }
1669: if (parameterChar == 'J') {
1670: if (isParameterArray) {
1671: parameters.add(arrString + "long");
1672: isParameterArray = false;
1673: } else {
1674: parameters.add("long");
1675: }
1676: }
1677: if (parameterChar == 'S') {
1678: if (isParameterArray) {
1679: parameters.add(arrString + "short");
1680: isParameterArray = false;
1681: } else {
1682: parameters.add("short");
1683: }
1684: }
1685: if (parameterChar == 'Z') {
1686: if (isParameterArray) {
1687: parameters.add(arrString + "boolean");
1688: isParameterArray = false;
1689: } else {
1690: parameters.add("boolean");
1691: }
1692: }
1693: parameterString = parameterString.substring(1);
1694: }
1695:
1696: }
1697: }
1698:
1699: /*
1700: * if(returnString.indexOf(";") !=-1) { returnString =
1701: * returnString.substring(0,returnString.indexOf(";")); }
1702: *
1703: * while(returnString.length() > 0) { // System.out.println();
1704: * if(returnString.startsWith("L")) { //System.out.println(returnString + "
1705: * "+returnType.length()); returnType =
1706: * returnString.substring(1,returnString.length()); returnType =
1707: * returnType.replace('/','.'); returnString=""; } else {
1708: * if(returnString.equals("I")) { returnType = "int"; returnString = ""; }
1709: * if(returnString.equals("B")) { returnType = "byte"; returnString =
1710: * ""; } if(returnString.equals("C")) { returnType = "char";
1711: * returnString = ""; } if(returnString.equals("D")) { returnType =
1712: * "double"; returnString = ""; } if(returnString.equals("F")) {
1713: * returnType = "float"; returnString = ""; }
1714: * if(returnString.equals("J")) { returnType = "long"; returnString =
1715: * ""; } if(returnString.equals("S")) { returnType = "short";
1716: * returnString = ""; } if(returnString.equals("Z")) { returnType =
1717: * "boolean"; returnString = ""; } if(returnString.equals("V")) {
1718: * returnType = "void"; returnString = ""; }
1719: * if(returnString.startsWith("[")) { returnTypeIsArray = true;
1720: * returnTypeArrayDimension = returnString.lastIndexOf("[")+1;
1721: * if(returnString.indexOf("L")!=-1) { returnType =
1722: * returnString.substring(returnString.lastIndexOf("[")+2); returnType =
1723: * returnType.replace('/','.'); returnString = ""; //returnString
1724: * =returnType; } else { returnString =
1725: * returnString.substring(returnString.lastIndexOf("[")+1);
1726: * //returnString = ""; } } } }
1727: */
1728:
1729: }
1730:
1731: public static boolean forceNewLine = true;
1732:
1733: public static boolean forceStartSpace = true;
1734:
1735: public static boolean forceBeginStartSpace = true;
1736:
1737: public static boolean newlinebeg = true;
1738:
1739: // belurs:
1740: // RE Wrote This function as the earlier function was not covering all cases
1741: // very well
1742: // The purpose of this function is to take any input and return a formatted
1743: // output
1744:
1745: public static boolean forceTrimString = true;
1746:
1747: public static boolean forceTrimLines = true;
1748:
1749: public static String formatDecompiledStatement(String input) {
1750:
1751: // if(input.indexOf("[]")!=-1){
1752: // forceNewLine=false;forceStartSpace=false;};
1753: // if(input.indexOf("[ ]")!=-1){
1754: // forceNewLine=false;forceStartSpace=false;}
1755:
1756: String formattedOutput = "";
1757: java.lang.String temp = "";
1758: char c;
1759: char prev = '#'; // default
1760: char next = '#';
1761: if (input == null || input.trim().length() == 0) {
1762: forceNewLine = true;
1763: forceStartSpace = true;
1764: return formattedOutput;
1765: }
1766:
1767: int sqbr = input.indexOf("[]");
1768: if (sqbr == -1)
1769: sqbr = input.indexOf("[ ]");
1770: if (sqbr != -1) {
1771: int curbr = input.indexOf("{");
1772: if (curbr != -1 && curbr > sqbr) {
1773: forceNewLine = true;
1774: forceStartSpace = true;
1775: newlinebeg = true;
1776: if (input.trim().endsWith(",")) {
1777: return currentSpace + input
1778: + System.getProperty("line.separator")
1779: + currentSpace;
1780: } else
1781: return input.trim();
1782: }
1783: }
1784:
1785: if (forceTrimString)
1786: input = trimString(input);
1787: if (forceTrimLines)
1788: input = trimNewLines(input);
1789: // input=input.replaceAll("\n\n","\n");
1790: input = input.replaceAll("\t\t", "\t");
1791: if (forceTrimString)
1792: input = input.replaceAll("\t", " ");
1793: if (input.endsWith(";\n;\n")) {
1794: int d = input.indexOf(";\n;\n");
1795: if (d != -1) {
1796: input = input.substring(0, d);
1797: input += ";\n";
1798: }
1799: }
1800: for (int s = 0; s < input.length(); s++) {
1801:
1802: c = input.charAt(s);
1803: if (c == '"') {
1804: int endQuote = input.indexOf("\"", s + 1);
1805: if (endQuote != -1) {
1806: int endIndex = endQuote + 1;
1807: if (endIndex > input.length()) {
1808: endIndex = endQuote;
1809: }
1810: if (endIndex <= input.length()) {
1811: String quoteString = input.substring(s,
1812: endIndex);
1813: temp += quoteString;
1814: s = endQuote;
1815: continue;
1816: }
1817: }
1818:
1819: }
1820:
1821: if (s == 0 && newlinebeg && forceBeginStartSpace)
1822: temp += currentSpace; // updateCurrentSpace(Util.getIncrementSpace(),"add");
1823: c = input.charAt(s);
1824: if (s > 0)
1825: prev = input.charAt((s - 1));
1826: if ((s + 1) < input.length())
1827: next = input.charAt((s + 1));
1828: if (c == '}') {
1829: // ObjectStreamClass$FieldReflector
1830: if (prev != '\n') {
1831: if (forceNewLine)
1832: temp += "\n";
1833: if (forceStartSpace)
1834: temp += currentSpace;
1835: updateCurrentSpace(Util.getIncrementSpace(),
1836: "remove");
1837:
1838: if (forceStartSpace)
1839: temp += currentSpace;
1840: temp += c;
1841: if (next != '\n' && forceNewLine) {
1842: temp += "\n";
1843: }
1844:
1845: } else {
1846: // updateCurrentSpace(Util.getIncrementSpace(),"remove");
1847: if (forceStartSpace)
1848: temp += currentSpace;
1849: temp += c;
1850: if (next != '\n' && forceNewLine) {
1851: temp += "\n";
1852: }
1853: }
1854: int n = temp.indexOf("\n");
1855: if (n != -1) {
1856: String s1 = temp.substring(0, n + 1);
1857: if (n + 3 < temp.length()) {
1858: temp = temp.substring(1);
1859: String s2 = temp.substring(n + 3);
1860: temp = s1 + " " + s2;
1861:
1862: }
1863: }
1864:
1865: } else if (c == '{') {
1866: if (prev == '\n') {
1867: if (forceStartSpace)
1868: temp += currentSpace;
1869: // sbelur
1870: // Hack ... until a better and new indentation algorithm is
1871: // designed [ Commented for 1.2.1]
1872: // if(input.indexOf("{\nbreak;")!=-1)
1873: // temp+=" ";
1874: // end
1875: temp += c;
1876: updateCurrentSpace(Util.getIncrementSpace(), "add");
1877: if (next != '\n' && forceNewLine) {
1878: temp += "\n";
1879: }
1880: } else {
1881: if (forceNewLine)
1882: temp += "\n";
1883:
1884: if (forceStartSpace && prev != ']')
1885: temp += currentSpace;
1886: // temp+=" ";
1887: temp += c;
1888: updateCurrentSpace(Util.getIncrementSpace(), "add");
1889: if (next != '\n' && forceNewLine) {
1890: temp += "\n";
1891: }
1892:
1893: }
1894: } else if (c == '\n') {
1895:
1896: boolean withinQuotes = isNewLineWithinQuotes(input, s);
1897: if (withinQuotes) {
1898: temp += "\\n";
1899: } else {
1900:
1901: if (next == '{') {
1902: temp += c;
1903: // temp+=" ";
1904: if (forceStartSpace)
1905: temp += currentSpace;
1906: } else if (next == '}') {
1907: if (trimString(input).charAt(0) == '\n') {
1908: temp = c + temp;
1909: } else
1910: temp += c;
1911: updateCurrentSpace(Util.getIncrementSpace(),
1912: "remove");
1913: // updateCurrentSpace(Util.getIncrementSpace(),"remove");
1914: if (forceStartSpace)
1915: temp += currentSpace;
1916:
1917: } else {
1918: if (!(s == input.length() - 1) && c == '\n') {
1919: temp += c;
1920: if (forceStartSpace)
1921: temp += currentSpace;
1922:
1923: } else {
1924: temp += c;
1925: // if(forceStartSpace) // Added here also bcoz of
1926: // indentation issue
1927: // temp+=currentSpace;
1928: }
1929:
1930: }
1931: }
1932:
1933: } else {
1934: if (c != ' ') {
1935: boolean withinQuotes = isNewLineWithinQuotes(input,
1936: s - 1);
1937: if (!withinQuotes) {
1938:
1939: if (prev == '\n' && forceStartSpace)
1940: temp += currentSpace;
1941: }
1942: if (s == 0 && newlinebeg && forceBeginStartSpace)
1943: temp += currentSpace;
1944:
1945: }
1946: if (s == input.length() - 1 && c == ' ') {
1947:
1948: } else
1949: temp += c;
1950:
1951: }
1952:
1953: }
1954: int anysc = temp.indexOf(";");
1955: int lastsc = temp.lastIndexOf(";");
1956: if (anysc != lastsc && (anysc + 1 == lastsc)) {
1957: temp = temp.substring(0, lastsc);
1958:
1959: }
1960: forceNewLine = true;
1961: forceStartSpace = true;
1962: newlinebeg = true;
1963: return temp;
1964: }
1965:
1966: // Removes from beginning
1967:
1968: public static java.lang.String trimNewLines(java.lang.String in) {
1969:
1970: if (in == null || in.length() == 0) {
1971: return in;
1972: } else {
1973: int pos = -1;
1974: for (int s = 0; s < in.length(); s++) {
1975: char c = in.charAt(s);
1976: if (c == '\n')
1977: continue;
1978: else {
1979: pos = s;
1980: break;
1981: }
1982: }
1983:
1984: return in.substring(pos);
1985: }
1986:
1987: }
1988:
1989: public static ArrayList getreturnSignatureAsList() {
1990: return returnSignature;
1991: }
1992:
1993: public static void parseReturnType(java.lang.String descriptor) {
1994: ArrayList parameters = new ArrayList();
1995: returnSignature = parameters;
1996: java.lang.String orig = descriptor;
1997: int charIndex = 0;
1998: java.lang.String parameterString = descriptor;
1999: /*
2000: * java.lang.String returnString =
2001: * descriptor.substring(descriptor.lastIndexOf(")")+1);
2002: * if(returnString.trim().length() > 0){
2003: * if(returnString.trim().charAt(0)=='L' ||
2004: * returnString.trim().charAt(0)=='[')
2005: * this.setReturnTypeAsObjectOrArrayType(true); else
2006: * this.setReturnTypeAsObjectOrArrayType(false); }
2007: */
2008:
2009: java.lang.String arrString = "";
2010: // while(charIndex < parameterString.length())
2011: while (parameterString.length() > 0) {
2012: if (parameterString.startsWith("L")) {
2013: java.lang.String objectString = parameterString
2014: .substring(1, parameterString.indexOf(";"));
2015: objectString = objectString.replace('/', '.');
2016: parameters.add(objectString);
2017: charIndex = charIndex + (objectString.length() + 2);
2018: parameterString = parameterString
2019: .substring(parameterString.indexOf(";") + 1);
2020: } else {
2021: char parameterChar = parameterString.charAt(0);
2022: if (parameterChar == '[') {
2023: arrString = "";
2024: while (parameterString.startsWith("[")) {
2025: arrString += "[]";
2026: parameterString = parameterString.substring(1,
2027: parameterString.length());
2028: isParameterArray = true;
2029: }
2030: java.lang.String objectString = "";
2031: if (parameterString.charAt(0) == 'L') {
2032: objectString = parameterString.substring(1,
2033: parameterString.indexOf(";"));
2034: parameterString = parameterString
2035: .substring(parameterString.indexOf(";") + 1);
2036: objectString = objectString.replace('/', '.');
2037: parameters.add(objectString + " " + arrString);
2038: isParameterArray = false;
2039: }
2040: /*
2041: * while(objectString.startsWith("[")) { arrString += "[";
2042: * objectString =
2043: * objectString.substring(1,objectString.length()); }
2044: * objectString = objectString.substring(1); objectString =
2045: * objectString.replace('/','.');
2046: * parameters.add(objectString); charIndex = charIndex +
2047: * (objectString.length() + 2);
2048: * parameters.add(arrString+objectString);
2049: */
2050:
2051: } else {
2052: if (parameterChar == 'V') {
2053: if (orig.indexOf("L") == -1
2054: || orig.indexOf("[") == -1)
2055: parameters.add("void");
2056: else
2057: parameters.add("V");
2058:
2059: }
2060: if (parameterChar == 'I') {
2061: if (isParameterArray) {
2062: parameters.add("int " + arrString);
2063: isParameterArray = false;
2064: } else {
2065: parameters.add("int");
2066: }
2067: }
2068: if (parameterChar == 'B') {
2069: if (isParameterArray) {
2070: parameters.add("byte " + arrString);
2071: isParameterArray = false;
2072: } else {
2073: parameters.add("byte");
2074: }
2075: }
2076: if (parameterChar == 'C') {
2077: if (isParameterArray) {
2078: parameters.add("char " + arrString);
2079: isParameterArray = false;
2080: } else {
2081: parameters.add("char");
2082: }
2083: }
2084: if (parameterChar == 'D') {
2085: if (isParameterArray) {
2086: parameters.add("double " + arrString);
2087: isParameterArray = false;
2088: } else {
2089: parameters.add("double");
2090: }
2091: }
2092: if (parameterChar == 'F') {
2093: if (isParameterArray) {
2094: parameters.add("float " + arrString);
2095: isParameterArray = false;
2096: } else {
2097: parameters.add("float");
2098: }
2099: }
2100: if (parameterChar == 'J') {
2101: if (isParameterArray) {
2102: parameters.add("long " + arrString);
2103: isParameterArray = false;
2104: } else {
2105: parameters.add("long");
2106: }
2107: }
2108: if (parameterChar == 'S') {
2109: if (isParameterArray) {
2110: parameters.add("short " + arrString);
2111: isParameterArray = false;
2112: } else {
2113: parameters.add("short");
2114: }
2115: }
2116: if (parameterChar == 'Z') {
2117: if (isParameterArray) {
2118: parameters.add("boolean " + arrString);
2119: isParameterArray = false;
2120: } else {
2121: parameters.add("boolean");
2122: }
2123: }
2124: parameterString = parameterString.substring(1);
2125: }
2126:
2127: }
2128: }
2129:
2130: /*
2131: * if(returnString.indexOf(";") !=-1) { returnString =
2132: * returnString.substring(0,returnString.indexOf(";")); }
2133: *
2134: * while(returnString.length() > 0) { // System.out.println();
2135: * if(returnString.startsWith("L")) { //System.out.println(returnString + "
2136: * "+returnType.length()); returnType =
2137: * returnString.substring(1,returnString.length()); returnType =
2138: * returnType.replace('/','.'); returnString=""; } else {
2139: * if(returnString.equals("I")) { returnType = "int"; returnString = ""; }
2140: * if(returnString.equals("B")) { returnType = "byte"; returnString =
2141: * ""; } if(returnString.equals("C")) { returnType = "char";
2142: * returnString = ""; } if(returnString.equals("D")) { returnType =
2143: * "double"; returnString = ""; } if(returnString.equals("F")) {
2144: * returnType = "float"; returnString = ""; }
2145: * if(returnString.equals("J")) { returnType = "long"; returnString =
2146: * ""; } if(returnString.equals("S")) { returnType = "short";
2147: * returnString = ""; } if(returnString.equals("Z")) { returnType =
2148: * "boolean"; returnString = ""; } if(returnString.equals("V")) {
2149: * returnType = "void"; returnString = ""; }
2150: * if(returnString.startsWith("[")) { returnTypeIsArray = true;
2151: * returnTypeArrayDimension = returnString.lastIndexOf("[")+1;
2152: * if(returnString.indexOf("L")!=-1) { returnType =
2153: * returnString.substring(returnString.lastIndexOf("[")+2); returnType =
2154: * returnType.replace('/','.'); returnString = ""; //returnString
2155: * =returnType; } else { returnString =
2156: * returnString.substring(returnString.lastIndexOf("[")+1);
2157: * //returnString = ""; } } } }
2158: */
2159:
2160: }
2161:
2162: public static java.lang.String checkForImport(
2163: java.lang.String input, StringBuffer sb) {
2164: if (input.indexOf("JdecGenerated") != -1) {
2165: sb.append(input);
2166: return "";
2167: }
2168:
2169: // if(input.indexOf(".")==-1 && input.indexOf("/")==-1)
2170: // {
2171: // input=input.replaceAll("\\$",".");
2172: // sb.append(input);
2173: // return "";
2174: // }
2175: if (Configuration.getShowImport().equalsIgnoreCase("false")) {
2176:
2177: sb.append(input);
2178: return "";
2179: }
2180: if (Configuration.getShowImport().equalsIgnoreCase("true")) {
2181: java.lang.String simplename = "";
2182: java.lang.String fullName = input;
2183: int lastSlash = fullName.lastIndexOf("/");
2184: int dollar = input.lastIndexOf("$");
2185: java.lang.String sname = null;
2186: if (lastSlash != -1) {
2187: if (input.indexOf("$") != -1) {
2188: // sname=input.substring(dollar+1);
2189: input = input.replaceAll("\\$", "/");
2190: }
2191: } else {
2192: lastSlash = fullName.lastIndexOf(".");
2193: if (lastSlash != -1) {
2194: if (input.indexOf("$") != -1) {
2195: // sname=input.substring(dollar+1);
2196: input = input.replaceAll("\\$", ".");
2197: }
2198: }
2199: }
2200:
2201: if (lastSlash != -1) {
2202:
2203: if (sname == null)
2204: simplename = fullName.substring(lastSlash + 1);
2205: else
2206: simplename = sname;
2207: } else
2208: simplename = fullName;
2209: fullName = fullName.replace('/', '.');
2210: fullName = fullName.replaceAll("\\$", ".");
2211:
2212: StringBuffer fulltype = new StringBuffer();
2213: boolean present = LocalVariableHelper
2214: .simpleTypeAlreadyAddedToImports(simplename,
2215: fulltype);
2216: boolean addim = true;
2217: if (present) {
2218: if (fullName.trim().equals(fulltype.toString().trim())) {
2219: addim = true;
2220: } else {
2221: addim = false;
2222: }
2223: }
2224:
2225: if (addim) {
2226: ConsoleLauncher.addImportClass(fullName);
2227: sb.append(simplename);
2228: } else {
2229: sb.append(fullName);
2230: }
2231: return fullName;
2232:
2233: }
2234: // Default
2235: sb.append(input);
2236: return "";
2237:
2238: }
2239:
2240: public static void checkForImport(java.lang.String input,
2241: StringBuffer sb, boolean force) {
2242: // if(input.indexOf("$")!=-1){sb.append(input);return;};
2243: if (input.indexOf("JdecGenerated") != -1) {
2244: sb.append(input);
2245:
2246: }
2247: if (input.indexOf(".") == -1 && input.indexOf("/") == -1) {
2248: // input=input.replaceAll("\\$",".");
2249: // sb.append(input);
2250: // return ;
2251: }
2252: if (Configuration.getShowImport().equalsIgnoreCase("false")
2253: && !force) {
2254:
2255: sb.append(input);
2256: return;
2257: }
2258: if (Configuration.getShowImport().equalsIgnoreCase("true")) {
2259: java.lang.String simplename = "";
2260: java.lang.String fullName = input;
2261: int lastSlash = fullName.lastIndexOf("/");
2262: int dollar = input.lastIndexOf("$");
2263: java.lang.String sname = null;
2264: if (lastSlash != -1) {
2265: if (input.indexOf("$") != -1) {
2266: // sname=input.substring(dollar+1);
2267: // sname=input.repl
2268: // sname=input;
2269: input = input.replaceAll("\\$", "/");
2270:
2271: }
2272: } else {
2273: lastSlash = fullName.lastIndexOf(".");
2274: if (lastSlash != -1) {
2275: if (input.indexOf("$") != -1) {
2276: // sname=input.substring(dollar+1);
2277: // sname=input;
2278: input = input.replaceAll("\\$", ".");
2279: // sname=input;
2280: }
2281: }
2282: }
2283:
2284: if (lastSlash != -1) {
2285: if (sname == null)
2286: simplename = fullName.substring(lastSlash + 1);
2287: else
2288: simplename = sname;
2289: } else
2290: simplename = fullName;
2291: fullName = fullName.replace('/', '.');
2292: fullName = fullName.replaceAll("\\$", ".");
2293:
2294: StringBuffer fulltype = new StringBuffer();
2295: boolean present = LocalVariableHelper
2296: .simpleTypeAlreadyAddedToImports(simplename,
2297: fulltype);
2298: boolean addim = true;
2299: if (present) {
2300: if (fullName.trim().equals(fulltype.toString().trim())) {
2301: addim = true;
2302: } else {
2303: addim = false;
2304: }
2305: }
2306:
2307: if (addim) {
2308: ConsoleLauncher.addImportClass(fullName);
2309: sb.append(simplename);
2310: } else {
2311: sb.append(fullName);
2312: }
2313: return;
2314:
2315: }
2316:
2317: if (Configuration.getShowImport().equalsIgnoreCase("false")
2318: && force) {
2319: java.lang.String simplename = "";
2320: java.lang.String fullName = input;
2321: int lastSlash = fullName.lastIndexOf("/");
2322: if (lastSlash == -1) {
2323: lastSlash = fullName.lastIndexOf(".");
2324: }
2325: if (lastSlash != -1) {
2326: simplename = fullName.substring(lastSlash + 1);
2327: } else
2328: simplename = fullName;
2329: fullName = fullName.replace('/', '.');
2330:
2331: StringBuffer fulltype = new StringBuffer();
2332: boolean present = LocalVariableHelper
2333: .simpleTypeAlreadyAddedToImports(simplename,
2334: fulltype);
2335: boolean addim = true;
2336: if (present) {
2337: if (fullName.trim().equals(fulltype.toString().trim())) {
2338: addim = true;
2339: } else {
2340: addim = false;
2341: }
2342: }
2343:
2344: if (addim) {
2345: ConsoleLauncher.addImportClass(fullName);
2346: sb.append(simplename);
2347: } else {
2348: sb.append(fullName);
2349: }
2350: return;
2351:
2352: }
2353: // Default
2354: sb.append(input);
2355: return;
2356:
2357: }
2358:
2359: public static ArrayList getTablesSortedByGuardStart(ArrayList list) {
2360:
2361: ArrayList a = new ArrayList();
2362: if (list == null || list.size() == 0)
2363: return null;
2364: HashMap map = new HashMap();
2365: for (int z = 0; z < list.size(); z++) {
2366: MethodInfo.ExceptionTable t = (MethodInfo.ExceptionTable) list
2367: .get(z);
2368: map.put(new Integer(t.getStartPC()), t);
2369: }
2370: Collection c = map.keySet();
2371: Integer spcs[] = (Integer[]) c.toArray(new Integer[map.size()]);
2372: Arrays.sort(spcs);
2373: for (int z = 0; z < spcs.length; z++) {
2374: Integer in = spcs[z];
2375: MethodInfo.ExceptionTable tab = (MethodInfo.ExceptionTable) map
2376: .get(in);
2377: a.add(tab);
2378: }
2379:
2380: return a;
2381:
2382: }
2383:
2384: public static ArrayList getAllTablesWithFinallyAsHandler(
2385: ArrayList input) {
2386: ArrayList a = new ArrayList();
2387: if (input == null || input.size() == 0) {
2388: return null;
2389: }
2390: for (int z = 0; z < input.size(); z++) {
2391:
2392: MethodInfo.ExceptionTable t = (MethodInfo.ExceptionTable) input
2393: .get(z);
2394: java.lang.String str = t.getHandlerBlockName();
2395: if (str.equals("FinallyBlock")) {
2396: a.add(t);
2397: }
2398: }
2399:
2400: return a;
2401: }
2402:
2403: public static ArrayList getAllTablesWithFinallyAsHandler(
2404: ArrayList input, int hpc) {
2405: ArrayList a = new ArrayList();
2406: if (input == null || input.size() == 0) {
2407: return null;
2408: }
2409: for (int z = 0; z < input.size(); z++) {
2410:
2411: MethodInfo.ExceptionTable t = (MethodInfo.ExceptionTable) input
2412: .get(z);
2413: java.lang.String str = t.getHandlerBlockName();
2414: if (str.equals("FinallyBlock")
2415: && t.getStartOfHandler() == hpc) {
2416: a.add(t);
2417: }
2418: }
2419:
2420: return a;
2421: }
2422:
2423: // Todo
2424: public static java.lang.String formatDisassembledOutput(
2425: java.lang.String input) {
2426:
2427: java.lang.String temp = "";
2428:
2429: if (input.charAt(0) == '\n') {
2430: if (input.length() > 1) {
2431: temp = "\n";
2432: temp += disSpace + input.substring(1);
2433: }
2434:
2435: } else {
2436: temp = disSpace + input;
2437: }
2438: return temp;
2439:
2440: }
2441:
2442: private static boolean isNewLineWithinQuotes(
2443: java.lang.String input, int s) {
2444:
2445: boolean yes = false;
2446: int start = s - 1;
2447: int end = 0;
2448: boolean before = false;
2449: boolean after = false;
2450: if (s < 0 || s > input.length())
2451: return false;
2452: if (input.charAt(s) != '\n')
2453: return false;
2454:
2455: for (int k = start; k >= end; k--) {
2456: char c = input.charAt(k);
2457: if (c == '"') {
2458: before = true;
2459: break;
2460: }
2461:
2462: }
2463: start = s + 1;
2464: end = input.length();
2465: for (int k = start; k < end; k++) {
2466: char c = input.charAt(k);
2467: if (c == '"') {
2468: after = true;
2469: break;
2470: }
2471:
2472: }
2473: if (before && after) {
2474: return true;
2475:
2476: }
2477:
2478: return yes;
2479: }
2480:
2481: public static java.lang.String checkForUTF(char c) {
2482: if (c >= 127)
2483: return "UTF";
2484: else if (c < 32)
2485: return "octal";
2486: return "ascii";
2487: }
2488:
2489: public static java.lang.String interpretCharForUTF(char ch,
2490: StringBuffer tp) {
2491: String res = "" + ch;
2492: char i;
2493: String type = "";
2494: String forcenonascii = UIUtil.getUIUtil().getForceNonAscii();
2495: if (forcenonascii.equals("true")) {
2496: type = tp.toString();// checkForUTF(ch);
2497: } else {
2498: type = checkForUTF(ch);
2499: }
2500: if (type.equals("UTF")) {
2501: String hexrep = Integer.toHexString(ch);
2502: int length = hexrep.length();
2503: int diff = 4 - length;
2504: String temp = "";
2505: for (int x = 1; x <= diff; x++) {
2506: temp += "0";
2507: }
2508: res = "\\u" + temp + hexrep;
2509:
2510: } else if (type.equals("octal")) {
2511: String octrep = Integer.toOctalString(ch);
2512: int length = octrep.length();
2513: int diff = 3 - length;
2514: String temp = "";
2515: for (int x = 1; x <= diff; x++) {
2516: temp += "0";
2517: }
2518:
2519: res = "\\" + temp + octrep;
2520:
2521: } else {
2522: // No Action for ascii
2523: }
2524: return res;
2525: }
2526:
2527: private char[] keepAsIsChars = {
2528:
2529: };
2530:
2531: public static java.lang.String formatForUTF(String value,
2532: String dataType, StringBuffer tp) {
2533: String s = value;
2534: if (dataType.equals("char") || dataType.equals("String")) {
2535: String forcenonascii = UIUtil.getUIUtil()
2536: .getForceNonAscii();
2537: if (dataType.equals("char")) {
2538: char c = (char) Integer.parseInt(value);
2539: java.lang.String charType = "";
2540: if (forcenonascii.equals("true")) {
2541: charType = tp.toString();
2542: } else {
2543: charType = checkForUTF(c);
2544: }
2545: charType = tp.toString();// Util.checkForUTF(c);
2546: if (charType.equals("UTF")) {
2547:
2548: String hexrep = Integer.toHexString(c);
2549: int length = hexrep.length();
2550: int diff = 4 - length;
2551: String temp = "";
2552: for (int x = 1; x <= diff; x++) {
2553: temp += "0";
2554: }
2555:
2556: s = "\'" + "\\u" + temp + hexrep + "\'";
2557:
2558: } else if (charType.equals("octal")) {
2559: String octrep = Integer.toOctalString(c);
2560: int length = octrep.length();
2561: int diff = 3 - length;
2562: String temp = "";
2563: for (int x = 1; x <= diff; x++) {
2564: temp += "0";
2565: }
2566: s = "'\\" + temp + octrep + '\'';
2567: } else {
2568:
2569: s = value;// Ascii
2570: }
2571:
2572: } else// String
2573: {
2574: StringBuffer sbf = new StringBuffer();
2575: for (int z = 0; z < value.length(); z++) {
2576: char ch = value.charAt(z);
2577: String str = Util.interpretCharForUTF(ch, tp);
2578: sbf.append(str);
2579: }
2580: // s="\""+sbf.toString()+"\"";
2581: s = sbf.toString();
2582: }
2583: }
2584: return s;
2585: }
2586:
2587: public static String returnUnInterpretedNonAscii(String value) {
2588: String str1 = value.toString();
2589: StringBuffer sbf1 = new StringBuffer("");
2590: for (int z = 0; z < str1.length(); z++) {
2591: char c1 = str1.charAt(z);
2592: if (c1 >= 32 && c1 < 127) {
2593: sbf1.append(c1);
2594: } else {
2595: sbf1.append("?");// c1); // removed ?
2596: }
2597:
2598: }
2599: String v1 = sbf1.toString();
2600: return v1;
2601:
2602: }
2603:
2604: public static ArrayList getRegisteredClasses() {
2605: return registeredClasses;
2606: }
2607:
2608: private static ArrayList registeredClasses = null;
2609:
2610: public static java.lang.String explodeJar(File f) {
2611:
2612: if (f == null || !f.exists())
2613: return "";
2614: try {
2615: registeredClasses = new ArrayList();
2616: JarFile jarFile = new JarFile(f.getAbsolutePath());
2617: Enumeration e = jarFile.entries();
2618: String projectTempDir = Configuration.getTempDir();
2619: if (projectTempDir == null
2620: || projectTempDir.trim().length() == 0)
2621: projectTempDir = System.getProperty("user.dir");
2622:
2623: String name = f.getName();
2624: if (name.indexOf(".") != -1)
2625: name = name.substring(0, name.indexOf("."));
2626: File root = new File(projectTempDir + File.separator + name);
2627: if (root.exists() == false)
2628: root.mkdir();
2629:
2630: while (e.hasMoreElements()) {
2631:
2632: ZipEntry entry = (ZipEntry) e.nextElement();
2633: File currentDir = null;
2634:
2635: if (entry.isDirectory()) {
2636: currentDir = new File(root.getAbsolutePath()
2637: + File.separator + entry.getName());
2638: if (!currentDir.exists())
2639: currentDir.mkdirs();
2640:
2641: } else {
2642: boolean b = checkFilterSetting(entry);
2643: if (!b)
2644: continue;
2645: if (currentDir == null) {
2646:
2647: currentDir = root;
2648: }
2649: File currentFile = new File(currentDir
2650: + File.separator + entry.getName());
2651: boolean write = false;
2652: try {
2653: currentFile.createNewFile();
2654: write = true;
2655: System.out.println("Registered File: "
2656: + currentFile.getAbsolutePath());
2657: writeToFile(currentFile, entry, jarFile);
2658: registeredClasses.add(currentFile);
2659: write = false;
2660: } catch (Exception e2) {
2661:
2662: String path = currentFile.getAbsolutePath();
2663: int lastSlash = path
2664: .lastIndexOf(File.separator);
2665: String s = path.substring(0, lastSlash);
2666: File f3 = new File(s);
2667: if (!f3.exists())
2668: f3.mkdirs();
2669: currentFile.createNewFile(); // Should not throw
2670: // Exception
2671: if (write) {
2672: System.out.println("Registered File: "
2673: + currentFile.getAbsolutePath());
2674: writeToFile(currentFile, entry, jarFile);
2675: }
2676:
2677: }
2678:
2679: }
2680:
2681: }
2682: return root.getAbsolutePath();
2683: } catch (Exception e) {
2684:
2685: AllExceptionHandler handler = new AllExceptionHandler(e);
2686: handler.reportException();
2687: return "";
2688:
2689: }
2690:
2691: }
2692:
2693: private static boolean checkFilterSetting(ZipEntry entry) {
2694:
2695: Configuration.getInCludedPkgs();
2696:
2697: String name = entry.getName();
2698: if (entry.isDirectory()) {
2699: name = name.replaceAll("/", ".");
2700: ArrayList list = ConsoleLauncher.getInclList();
2701: if (list == null || list.size() == 0)
2702: return true;
2703: if (list.get(0).toString().equals("pkg-all")
2704: || list.get(0).toString().equals("All")
2705: || list.get(0).toString().equals("[]")
2706: || list.get(0).toString().equals("[ ]")) {
2707: return true;
2708: }
2709: for (Iterator iter = list.iterator(); iter.hasNext();) {
2710: String element = (String) iter.next();
2711: if (element.equals(name)) {
2712: return true;
2713: }
2714: }
2715: return false;
2716: } else {
2717: if (name.endsWith(".class")) {
2718: String defaultClz = Configuration
2719: .getProcessOnlyDefault();
2720: int sl = name.indexOf("/");
2721: if (sl == -1)
2722: return true;
2723: if (defaultClz != null && defaultClz.equals("true")) {
2724: if (sl != -1) {
2725: return false;
2726: } else
2727: return true;
2728: }
2729: name = name.substring(0, name.lastIndexOf("/"));
2730: name = name.replaceAll("/", ".");
2731: ArrayList list = ConsoleLauncher.getInclList();
2732: if (list == null || list.size() == 0)
2733: return true;
2734: if (list.get(0).toString().equals("pkg-all")
2735: || list.get(0).toString().equals("All")
2736: || list.get(0).toString().equals("[]")
2737: || list.get(0).toString().equals("[ ]")) {
2738: return true;
2739: }
2740: for (Iterator iter = list.iterator(); iter.hasNext();) {
2741: String element = (String) iter.next();
2742: if (element.equals(name)) {
2743: return true;
2744: }
2745: }
2746: return false;
2747:
2748: } else {
2749: String enclosedArch = Configuration
2750: .getProcessEnclosedArchives();
2751: int dot = name.indexOf(".");
2752: if (dot != -1) {
2753: String ext = name.substring(dot + 1);
2754: if (enclosedArch != null
2755: && enclosedArch.equalsIgnoreCase("true")) {
2756: String types = Configuration
2757: .getRegsiteredArchiveTypes();
2758: int startbr = types.indexOf("[");
2759: int endbr = types.indexOf("]");
2760: if (startbr != -1 && endbr != -1) {
2761: types = types.substring(startbr + 1, endbr);
2762: StringTokenizer st = new StringTokenizer(
2763: types, ",");
2764: while (st.hasMoreTokens()) {
2765: String c = (String) st.nextToken();
2766: if (c.equalsIgnoreCase(ext)) {
2767: return true;
2768: }
2769: }
2770: return false;
2771: }
2772:
2773: } else
2774: return false;
2775:
2776: }
2777: return false;
2778:
2779: }
2780: }
2781:
2782: }
2783:
2784: private static void writeToFile(File currentFile, ZipEntry entry,
2785: JarFile jarFile) {
2786: ArrayList bytes = new ArrayList();
2787: try {
2788: InputStream is = jarFile.getInputStream(entry);
2789: OutputStream os = new FileOutputStream(currentFile
2790: .getAbsolutePath());
2791: // DataOutputStream dos=new DataOutputStream(os);
2792: int x = is.read();
2793: while (x != -1) {
2794: os.write(x);
2795: x = is.read();
2796: }
2797: os.flush();
2798: os.close();
2799:
2800: } catch (IOException ioe) {
2801: try {
2802: LogWriter lg = LogWriter.getInstance();
2803: lg
2804: .writeLog("[ERROR]: Method: writeToFile\n\tClass: UIUtil.class");
2805: lg
2806: .writeLog("------------------------------------------------");
2807: lg.writeLog("Exception Stack Trace");
2808: ioe.printStackTrace(lg.getPrintWriter());
2809: lg.flush();
2810: } catch (Exception e) {
2811: //
2812: }
2813:
2814: }
2815:
2816: }
2817:
2818: }
|