diff --git a/binaries/jars/latest_development/intrace-agent.jar b/binaries/jars/latest_development/intrace-agent.jar index c74e85d..a9bc0a5 100644 Binary files a/binaries/jars/latest_development/intrace-agent.jar and b/binaries/jars/latest_development/intrace-agent.jar differ diff --git a/binaries/jars/latest_development/intrace-ui.jar b/binaries/jars/latest_development/intrace-ui.jar index d630bfd..548db2c 100644 Binary files a/binaries/jars/latest_development/intrace-ui.jar and b/binaries/jars/latest_development/intrace-ui.jar differ diff --git a/intrace.appengine/war/features/intrace.ecl.feature_0.20.0.jar b/intrace.appengine/war/features/intrace.ecl.feature_0.20.0.jar deleted file mode 100644 index 0245062..0000000 Binary files a/intrace.appengine/war/features/intrace.ecl.feature_0.20.0.jar and /dev/null differ diff --git a/intrace.appengine/war/plugins/intrace.ecl_0.20.0.jar b/intrace.appengine/war/plugins/intrace.ecl_0.20.0.jar deleted file mode 100644 index fe8d0aa..0000000 Binary files a/intrace.appengine/war/plugins/intrace.ecl_0.20.0.jar and /dev/null differ diff --git a/intrace.ecl.feature/feature.xml b/intrace.ecl.feature/feature.xml index 911c819..e33395f 100644 --- a/intrace.ecl.feature/feature.xml +++ b/intrace.ecl.feature/feature.xml @@ -2,7 +2,7 @@ + version="0.21"> Enable launching Java Applications with the InTrace agent. @@ -215,6 +215,6 @@ litigation. id="intrace.ecl" download-size="0" install-size="0" - version="0.20.0"/> + version="0.21.0"/> diff --git a/intrace.ecl.plugin/META-INF/MANIFEST.MF b/intrace.ecl.plugin/META-INF/MANIFEST.MF index ccaba4d..ca32e37 100644 --- a/intrace.ecl.plugin/META-INF/MANIFEST.MF +++ b/intrace.ecl.plugin/META-INF/MANIFEST.MF @@ -1,23 +1,23 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: InTrace Eclipse -Bundle-SymbolicName: intrace.ecl;singleton:=true -Bundle-Version: 0.20 -Bundle-Activator: intrace.ecl.Activator -Require-Bundle: org.eclipse.ui, - org.eclipse.core.runtime, - org.eclipse.debug.core, - org.eclipse.debug.ui, - org.eclipse.jdt.debug.ui, - org.eclipse.jdt.launching, - org.eclipse.ui.ide, - org.eclipse.jdt.junit, - org.eclipse.jdt.core -Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Bundle-ClassPath: lib/miglayout-3.7.3.1-swt.jar, - ., - lib/intrace-ui-helper.jar -Export-Package: intrace.ecl, - intrace.ecl.ui.launching, - intrace.ecl.ui.output +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: InTrace Eclipse +Bundle-SymbolicName: intrace.ecl;singleton:=true +Bundle-Version: 0.21 +Bundle-Activator: intrace.ecl.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.debug.core, + org.eclipse.debug.ui, + org.eclipse.jdt.debug.ui, + org.eclipse.jdt.launching, + org.eclipse.ui.ide, + org.eclipse.jdt.junit, + org.eclipse.jdt.core +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ClassPath: lib/miglayout-3.7.3.1-swt.jar, + ., + lib/intrace-ui-helper.jar +Export-Package: intrace.ecl, + intrace.ecl.ui.launching, + intrace.ecl.ui.output diff --git a/intrace.ecl.plugin/lib/intrace-agent.jar b/intrace.ecl.plugin/lib/intrace-agent.jar index c74e85d..a9bc0a5 100644 Binary files a/intrace.ecl.plugin/lib/intrace-agent.jar and b/intrace.ecl.plugin/lib/intrace-agent.jar differ diff --git a/intrace.ecl.plugin/lib/intrace-ui-helper.jar b/intrace.ecl.plugin/lib/intrace-ui-helper.jar index 6c9f1ad..96edcbc 100644 Binary files a/intrace.ecl.plugin/lib/intrace-ui-helper.jar and b/intrace.ecl.plugin/lib/intrace-ui-helper.jar differ diff --git a/intrace.ecl.site/artifacts.jar b/intrace.ecl.site/artifacts.jar deleted file mode 100644 index f3ba95b..0000000 Binary files a/intrace.ecl.site/artifacts.jar and /dev/null differ diff --git a/intrace.ecl.site/content.jar b/intrace.ecl.site/content.jar deleted file mode 100644 index 5ea3136..0000000 Binary files a/intrace.ecl.site/content.jar and /dev/null differ diff --git a/intrace.ecl.site/features/intrace.ecl.feature_0.20.0.jar b/intrace.ecl.site/features/intrace.ecl.feature_0.20.0.jar deleted file mode 100644 index 0245062..0000000 Binary files a/intrace.ecl.site/features/intrace.ecl.feature_0.20.0.jar and /dev/null differ diff --git a/intrace.ecl.site/plugins/intrace.ecl_0.20.0.jar b/intrace.ecl.site/plugins/intrace.ecl_0.20.0.jar deleted file mode 100644 index fe8d0aa..0000000 Binary files a/intrace.ecl.site/plugins/intrace.ecl_0.20.0.jar and /dev/null differ diff --git a/org.intrace/.classpath b/org.intrace/.classpath index b507ec2..4e3a570 100644 --- a/org.intrace/.classpath +++ b/org.intrace/.classpath @@ -8,8 +8,9 @@ - - + + + diff --git a/org.intrace/build.xml b/org.intrace/build.xml index ec7ffe7..8f08889 100644 --- a/org.intrace/build.xml +++ b/org.intrace/build.xml @@ -1,428 +1,430 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FindBugs: Errors found, please run "ant view-findbugs" - FindBugs: Warnings found, please run "ant view-findbugs" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - **** - **** - Now run Build All in Eclipse for the intrace.ecl.site project - **** - **** - - - - - - - - - - - - - - **** - **** - Now run Build All in Eclipse for the intrace.ecl.site project - **** - **** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FindBugs: Errors found, please run "ant view-findbugs" + FindBugs: Warnings found, please run "ant view-findbugs" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + **** + **** + Now run Build All in Eclipse for the intrace.ecl.site project + **** + **** + + + + + + + + + + + + + + **** + **** + Now run Build All in Eclipse for the intrace.ecl.site project + **** + **** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.intrace/conf/findbugs_exclude.xml b/org.intrace/conf/findbugs_exclude.xml index 9420ba6..e24478f 100644 --- a/org.intrace/conf/findbugs_exclude.xml +++ b/org.intrace/conf/findbugs_exclude.xml @@ -39,5 +39,10 @@ + ` ` + // Ignore all problems in Base64 which is an external class + + + diff --git a/org.intrace/lib/intrace-agent.jar b/org.intrace/lib/intrace-agent.jar index 2b7f669..a9bc0a5 100644 Binary files a/org.intrace/lib/intrace-agent.jar and b/org.intrace/lib/intrace-agent.jar differ diff --git a/org.intrace/lib/miglayout-3.7.3.1-swt.jar b/org.intrace/lib/miglayout-3.7.3.1-swt.jar deleted file mode 100644 index 65a5b95..0000000 Binary files a/org.intrace/lib/miglayout-3.7.3.1-swt.jar and /dev/null differ diff --git a/org.intrace/lib/miglayout-core-4.2.jar b/org.intrace/lib/miglayout-core-4.2.jar new file mode 100644 index 0000000..eff5670 Binary files /dev/null and b/org.intrace/lib/miglayout-core-4.2.jar differ diff --git a/org.intrace/lib/miglayout-swt-4.2.jar b/org.intrace/lib/miglayout-swt-4.2.jar new file mode 100644 index 0000000..471d22f Binary files /dev/null and b/org.intrace/lib/miglayout-swt-4.2.jar differ diff --git a/org.intrace/lib/swt-linux32-3.6.2.jar b/org.intrace/lib/swt-linux32-3.6.2.jar deleted file mode 100644 index 750f8ae..0000000 Binary files a/org.intrace/lib/swt-linux32-3.6.2.jar and /dev/null differ diff --git a/org.intrace/lib/swt-linux32-4.3.jar b/org.intrace/lib/swt-linux32-4.3.jar new file mode 100644 index 0000000..6fc5ea4 Binary files /dev/null and b/org.intrace/lib/swt-linux32-4.3.jar differ diff --git a/org.intrace/lib/swt-linux64-3.6.2.jar b/org.intrace/lib/swt-linux64-3.6.2.jar deleted file mode 100644 index db0e7a8..0000000 Binary files a/org.intrace/lib/swt-linux64-3.6.2.jar and /dev/null differ diff --git a/org.intrace/lib/swt-linux64-4.3.jar b/org.intrace/lib/swt-linux64-4.3.jar new file mode 100644 index 0000000..fa03f66 Binary files /dev/null and b/org.intrace/lib/swt-linux64-4.3.jar differ diff --git a/org.intrace/lib/swt-osx32-3.6.2.jar b/org.intrace/lib/swt-osx32-3.6.2.jar deleted file mode 100644 index dd313b2..0000000 Binary files a/org.intrace/lib/swt-osx32-3.6.2.jar and /dev/null differ diff --git a/org.intrace/lib/swt-osx32-4.3.jar b/org.intrace/lib/swt-osx32-4.3.jar new file mode 100644 index 0000000..0aa8831 Binary files /dev/null and b/org.intrace/lib/swt-osx32-4.3.jar differ diff --git a/org.intrace/lib/swt-osx64-3.6.2.jar b/org.intrace/lib/swt-osx64-3.6.2.jar deleted file mode 100644 index 12894a2..0000000 Binary files a/org.intrace/lib/swt-osx64-3.6.2.jar and /dev/null differ diff --git a/org.intrace/lib/swt-osx64-4.3.jar b/org.intrace/lib/swt-osx64-4.3.jar new file mode 100644 index 0000000..a931dd3 Binary files /dev/null and b/org.intrace/lib/swt-osx64-4.3.jar differ diff --git a/org.intrace/lib/swt-win32-3.6.2.jar b/org.intrace/lib/swt-win32-3.6.2.jar deleted file mode 100644 index 797b016..0000000 Binary files a/org.intrace/lib/swt-win32-3.6.2.jar and /dev/null differ diff --git a/org.intrace/lib/swt-win32-4.3.jar b/org.intrace/lib/swt-win32-4.3.jar new file mode 100644 index 0000000..bccb67d Binary files /dev/null and b/org.intrace/lib/swt-win32-4.3.jar differ diff --git a/org.intrace/lib/swt-win64-3.6.2.jar b/org.intrace/lib/swt-win64-3.6.2.jar deleted file mode 100644 index 4f3d5c2..0000000 Binary files a/org.intrace/lib/swt-win64-3.6.2.jar and /dev/null differ diff --git a/org.intrace/lib/swt-win64-4.3.jar b/org.intrace/lib/swt-win64-4.3.jar new file mode 100644 index 0000000..916306b Binary files /dev/null and b/org.intrace/lib/swt-win64-4.3.jar differ diff --git a/org.intrace/src/org/intrace/agent/ClassTransformer.java b/org.intrace/src/org/intrace/agent/ClassTransformer.java index 1ca65cd..912875c 100644 --- a/org.intrace/src/org/intrace/agent/ClassTransformer.java +++ b/org.intrace/src/org/intrace/agent/ClassTransformer.java @@ -27,7 +27,6 @@ import org.intrace.agent.server.AgentServer; import org.intrace.output.AgentHelper; import org.intrace.output.InstruRunnable; import org.intrace.output.trace.TraceHandler; -import org.intrace.output.trace.TraceSettings; import org.intrace.shared.AgentConfigConstants; import org.objectweb.asm.ClassReader; diff --git a/org.intrace/src/org/intrace/client/gui/helper/InTraceUI.java b/org.intrace/src/org/intrace/client/gui/helper/InTraceUI.java index eac5fd8..08f7de9 100644 --- a/org.intrace/src/org/intrace/client/gui/helper/InTraceUI.java +++ b/org.intrace/src/org/intrace/client/gui/helper/InTraceUI.java @@ -793,7 +793,7 @@ public class InTraceUI implements ISocketCallback, IControlConnectionListener private TraceTab(Composite parent) { - MigLayout windowLayout = new MigLayout("fill", "[80][80][250][100][grow]"); + MigLayout windowLayout = new MigLayout("fill", "[80][80][250][140][grow]"); composite = new Composite(parent, SWT.NONE); composite.setLayout(windowLayout); @@ -818,7 +818,6 @@ public class InTraceUI implements ISocketCallback, IControlConnectionListener exitStackTrace.setText(ClientStrings.ENABLE_EXIT_STACK_TRACE); exitStackTrace.setAlignment(SWT.CENTER); - entryExitTrace .addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() { diff --git a/org.intrace/src/org/intrace/output/trace/TraceHandler.java b/org.intrace/src/org/intrace/output/trace/TraceHandler.java index 935ef9f..c3ce315 100644 --- a/org.intrace/src/org/intrace/output/trace/TraceHandler.java +++ b/org.intrace/src/org/intrace/output/trace/TraceHandler.java @@ -4,10 +4,8 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.lang.reflect.Array; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Arrays; import java.util.Date; -import java.util.List; import java.util.Map; import org.intrace.output.AgentHelper; @@ -29,15 +27,16 @@ public class TraceHandler implements IInstrumentationHandler { // Private constructor } - + private boolean entryExitTrace = true; private boolean branchTrace = false; private boolean argTrace = true; private boolean truncateArrays = true; private boolean exitStackTrace = false; - + private static final TraceSettings traceSettings = new TraceSettings(""); + @Override public String getResponse(String args) { // TraceSettings oldSettings = new TraceSettings(traceSettings); @@ -60,10 +59,11 @@ public class TraceHandler implements IInstrumentationHandler argTrace = traceSettings.isArgTraceEnabled(); truncateArrays = traceSettings.isTruncateArraysEnabled(); exitStackTrace = traceSettings.isExitStackTraceEnabled(); - + return null; } + @Override public Map getSettingsMap() { return traceSettings.getSettingsMap(); @@ -78,7 +78,7 @@ public class TraceHandler implements IInstrumentationHandler } return lRet; } - + private String arrayStr(String xiArrStr) { String ret = xiArrStr; @@ -89,7 +89,7 @@ public class TraceHandler implements IInstrumentationHandler } return ret; } - + @Override public void val(String desc, String className, String methodName, byte byteArg) { @@ -100,6 +100,7 @@ public class TraceHandler implements IInstrumentationHandler } } + @Override public void val(String desc, String className, String methodName, byte[] byteArrayArg) { @@ -121,6 +122,7 @@ public class TraceHandler implements IInstrumentationHandler } } + @Override public void val(String desc, String className, String methodName, short[] shortArrayArg) { @@ -270,7 +272,7 @@ private static final String STACK_TRACE_DELIM = "~"; * Just like Arrays.toString(Object), place a comma between each element of the stack trace */ private static final Object STACK_ELE_DELIM = ","; - + private String replaceChars(String xiArg) { String ret = xiArg; @@ -278,21 +280,21 @@ private static final Object STACK_ELE_DELIM = ","; for (int ii = 0; ii < xiArg.length(); ii++) { char c = xiArg.charAt(ii); - + // Detect special char - if ((0x00 <= c) && + if ((0x00 <= c) && (c <= 0x20) && (c != '\r') && (c != '\n')) { // Replace char c = ESCAPE_REPLACEMENT; - + // Setup stringbuilder if (str == null) { str = new StringBuilder(); - + // Append any previous non special chars if (ii > 0) { @@ -300,23 +302,23 @@ private static final Object STACK_ELE_DELIM = ","; } } } - - // If we are storing chars we better write + + // If we are storing chars we better write // this one now if (str != null) { str.append(c); } } - + if (str != null) { ret = str.toString(); } - + return ret; } - + @Override public void val(String desc, String className, String methodName, Object objArg) @@ -337,12 +339,13 @@ private static final Object STACK_ELE_DELIM = ","; else { objStr = (objArg != null ? objArg.toString() : "null"); - } + } writeTraceOutput(className + ":" + methodName + ": " + desc + ": " + objStr); } } + @Override public void val(String desc, String className, String methodName, Object[] objArrayArg) { @@ -361,11 +364,12 @@ private static final Object STACK_ELE_DELIM = ","; { if (branchTrace) { - writeTraceOutput(className + ":" + methodName + ": /" + + writeTraceOutput(className + ":" + methodName + ": /" + (lineNo >= 0 ? ":" + lineNo : "")); } } + @Override public void val(String desc, String className, String methodName, int lineNo, Throwable throwable) { @@ -398,7 +402,7 @@ private static final Object STACK_ELE_DELIM = ","; { if (entryExitTrace) { - writeTraceOutput(className + ":" + methodName + ": {" + + writeTraceOutput(className + ":" + methodName + ": {" + (lineNo >= 0 ? ":" + lineNo : "")); } } @@ -408,17 +412,17 @@ private static final Object STACK_ELE_DELIM = ","; * @return */ public String getStackTrace() { - + StringBuilder sb = new StringBuilder(); int counter = 0; for(StackTraceElement ste : Thread.currentThread().getStackTrace() ) { - if ( ste.getClassName().indexOf(INTRACE_PACKAGE) <0 + if ( ste.getClassName().indexOf(INTRACE_PACKAGE) <0 && (ste.getClassName().indexOf(THREAD) < 0) && ste.getMethodName().indexOf(GET_STACK_TRACE)<0) { - if (counter++>0) sb.append(STACK_ELE_DELIM); //Just like Arrays.toString(), place a comma between each stack trace ele. + if (counter++>0) sb.append(STACK_ELE_DELIM); //Just like Arrays.toString(), place a comma between each stack trace ele. sb.append(ste.toString()); } } - + return sb.toString(); } @Override @@ -426,13 +430,13 @@ private static final Object STACK_ELE_DELIM = ","; { if (entryExitTrace) { - + if (exitStackTrace) { - writeTraceOutput(className + ":" + methodName + ": }" + - (lineNo >= 0 ? ":" + lineNo : "") + + writeTraceOutput(className + ":" + methodName + ": }" + + (lineNo >= 0 ? ":" + lineNo : "") + STACK_TRACE_DELIM + getStackTrace() ); } else { - writeTraceOutput(className + ":" + methodName + ": }" + + writeTraceOutput(className + ":" + methodName + ": }" + (lineNo >= 0 ? ":" + lineNo : "") ); } } @@ -445,7 +449,7 @@ private static final Object STACK_ELE_DELIM = ","; *
  • FileOut *
  • NetworkOut * - * + * * @param xiOutput */ public void writeTraceOutput(String xiOutput) diff --git a/org.intrace/src/org/intrace/shared/Base64.java b/org.intrace/src/org/intrace/shared/Base64.java index 4f8d7fc..c82ded0 100644 --- a/org.intrace/src/org/intrace/shared/Base64.java +++ b/org.intrace/src/org/intrace/shared/Base64.java @@ -2,16 +2,16 @@ package org.intrace.shared; /** *

    Encodes and decodes to and from Base64 notation.

    *

    Homepage: http://iharder.net/base64.

    - * + * *

    Example:

    - * + * * String encoded = Base64.encode( myByteArray ); *
    * byte[] myByteArray = Base64.decode( encoded ); * - *

    The options parameter, which appears in a few places, is used to pass - * several pieces of information to the encoder. In the "higher level" methods such as - * encodeBytes( bytes, options ) the options parameter can be used to indicate such + *

    The options parameter, which appears in a few places, is used to pass + * several pieces of information to the encoder. In the "higher level" methods such as + * encodeBytes( bytes, options ) the options parameter can be used to indicate such * things as first gzipping the bytes before encoding them, not inserting linefeeds, * and encoding using the URL-safe and Ordered dialects.

    * @@ -20,7 +20,7 @@ package org.intrace.shared; * to do so. I've got Base64 set to this behavior now, although earlier versions * broke lines by default.

    * - *

    The constants defined in Base64 can be OR-ed together to combine options, so you + *

    The constants defined in Base64 can be OR-ed together to combine options, so you * might make a call like this:

    * * String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DO_BREAK_LINES ); @@ -67,7 +67,7 @@ package org.intrace.shared; *
  • v2.3 - This is not a drop-in replacement! This is two years of comments * and bug fixes queued up and finally executed. Thanks to everyone who sent * me stuff, and I'm sorry I wasn't able to distribute your fixes to everyone else. - * Much bad coding was cleaned up including throwing exceptions where necessary + * Much bad coding was cleaned up including throwing exceptions where necessary * instead of returning null values or something similar. Here are some changes * that may affect you: *
      @@ -105,24 +105,24 @@ package org.intrace.shared; * Special thanks to Jim Kellerman at http://www.powerset.com/ * for contributing the new Base64 dialects. * - * + * *
    • v2.1 - Cleaned up javadoc comments and unused variables and methods. Added * some convenience methods for reading and writing to and from files.
    • *
    • v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems * with other encodings (like EBCDIC).
    • *
    • v2.0.1 - Fixed an error when decoding a single byte, that is, when the * encoded data was a single byte.
    • - *
    • v2.0 - I got rid of methods that used booleans to set options. + *
    • v2.0 - I got rid of methods that used booleans to set options. * Now everything is more consolidated and cleaner. The code now detects * when data that's being decoded is gzip-compressed and will decompress it * automatically. Generally things are cleaner. You'll probably have to * change some method calls that you were making to support the new * options format (ints that you "OR" together).
    • - *
    • v1.5.1 - Fixed bug when decompressing and decoding to a - * byte[] using decode( String s, boolean gzipCompressed ). - * Added the ability to "suspend" encoding in the Output Stream so - * you can turn on and off the encoding if you need to embed base64 - * data in an otherwise "normal" stream (like an XML file).
    • + *
    • v1.5.1 - Fixed bug when decompressing and decoding to a + * byte[] using decode( String s, boolean gzipCompressed ). + * Added the ability to "suspend" encoding in the Output Stream so + * you can turn on and off the encoding if you need to embed base64 + * data in an otherwise "normal" stream (like an XML file).
    • *
    • v1.5 - Output stream pases on flush() command but doesn't do anything itself. * This helps when using GZIP streams. * Added the ability to GZip-compress objects before encoding them.
    • @@ -148,36 +148,36 @@ package org.intrace.shared; */ public class Base64 { - -/* ******** P U B L I C F I E L D S ******** */ - - + +/* ******** P U B L I C F I E L D S ******** */ + + /** No options specified. Value is zero. */ public final static int NO_OPTIONS = 0; - + /** Specify encoding in first bit. Value is one. */ public final static int ENCODE = 1; - - + + /** Specify decoding in first bit. Value is zero. */ public final static int DECODE = 0; - + /** Specify that data should be gzip-compressed in second bit. Value is two. */ public final static int GZIP = 2; /** Specify that gzipped data should not be automatically gunzipped. */ public final static int DONT_GUNZIP = 4; - - + + /** Do break lines when encoding. Value is 8. */ public final static int DO_BREAK_LINES = 8; - - /** + + /** * Encode using Base64-like encoding that is URL- and Filename-safe as described - * in Section 4 of RFC3548: + * in Section 4 of RFC3548: * http://www.faqs.org/rfcs/rfc3548.html. - * It is important to note that data encoded this way is not officially valid Base64, + * It is important to note that data encoded this way is not officially valid Base64, * or at the very least should not be called Base64 without also specifying that is * was encoded using the URL- and Filename-safe dialect. */ @@ -189,50 +189,50 @@ public class Base64 * http://www.faqs.org/qa/rfcc-1940.html. */ public final static int ORDERED = 32; - - -/* ******** P R I V A T E F I E L D S ******** */ - - + + +/* ******** P R I V A T E F I E L D S ******** */ + + /** Maximum line length (76) of Base64 output. */ private final static int MAX_LINE_LENGTH = 76; - - + + /** The equals sign (=) as a byte. */ private final static byte EQUALS_SIGN = (byte)'='; - - + + /** The new line character (\n) as a byte. */ private final static byte NEW_LINE = (byte)'\n'; - - + + /** Preferred encoding. */ private final static String PREFERRED_ENCODING = "US-ASCII"; - - + + private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding - - -/* ******** S T A N D A R D B A S E 6 4 A L P H A B E T ******** */ - + + +/* ******** S T A N D A R D B A S E 6 4 A L P H A B E T ******** */ + /** The 64 valid Base64 values. */ /* Host platform me be something funny like EBCDIC, so we hardcode these values. */ private final static byte[] _STANDARD_ALPHABET = { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', - (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', + (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', - (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', + (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', - (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', + (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/' }; - - - /** + + + /** * Translates a Base64 value to either its 6-bit reconstruction value * or a negative number indicating some other meaning. **/ @@ -267,30 +267,30 @@ public class Base64 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 }; - - + + /* ******** U R L S A F E B A S E 6 4 A L P H A B E T ******** */ - + /** - * Used in the URL- and Filename-safe dialect described in Section 4 of RFC3548: + * Used in the URL- and Filename-safe dialect described in Section 4 of RFC3548: * http://www.faqs.org/rfcs/rfc3548.html. * Notice that the last two bytes become "hyphen" and "underscore" instead of "plus" and "slash." */ private final static byte[] _URL_SAFE_ALPHABET = { (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', - (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', + (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', - (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', + (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', - (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', + (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'-', (byte)'_' }; - + /** * Used in decoding URL- and Filename-safe dialects of Base64. */ @@ -329,7 +329,7 @@ public class Base64 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 }; @@ -355,7 +355,7 @@ public class Base64 (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z' }; - + /** * Used in decoding the "ordered" dialect of Base64. */ @@ -394,10 +394,10 @@ public class Base64 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 + -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 }; - + /* ******** D E T E R M I N E W H I C H A L H A B E T ******** */ @@ -437,16 +437,16 @@ public class Base64 } // end getAlphabet - + /** Defeats instantiation. */ private Base64(){} - - - -/* ******** E N C O D I N G M E T H O D S ******** */ - - + + + +/* ******** E N C O D I N G M E T H O D S ******** */ + + /** * Encodes up to the first three bytes of array threeBytes * and returns a four-byte array in Base64 notation. @@ -467,12 +467,12 @@ public class Base64 return b4; } // end encode3to4 - + /** *

      Encodes up to three bytes of the array source * and writes the resulting four Base64 bytes to destination. * The source and destination arrays can be manipulated - * anywhere along their length by specifying + * anywhere along their length by specifying * srcOffset and destOffset. * This method does not check to make sure your arrays * are large enough to accomodate srcOffset + 3 for @@ -491,19 +491,19 @@ public class Base64 * @return the destination array * @since 1.3 */ - private static byte[] encode3to4( + private static byte[] encode3to4( byte[] source, int srcOffset, int numSigBytes, byte[] destination, int destOffset, int options ) { - - byte[] ALPHABET = getAlphabet( options ); - - // 1 2 3 + + byte[] ALPHABET = getAlphabet( options ); + + // 1 2 3 // 01234567890123456789012345678901 Bit position // --------000000001111111122222222 Array position from threeBytes // --------| || || || | Six bit groups to index ALPHABET // >>18 >>12 >> 6 >> 0 Right shift necessary // 0x3f 0x3f 0x3f Additional AND - + // Create buffer with zero-padding if there are only one or two // significant bytes passed in the array. // We have to shift left 24 in order to flush out the 1's that appear @@ -520,21 +520,21 @@ public class Base64 destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; destination[ destOffset + 3 ] = ALPHABET[ (inBuff ) & 0x3f ]; return destination; - + case 2: destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; destination[ destOffset + 3 ] = EQUALS_SIGN; return destination; - + case 1: destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; destination[ destOffset + 2 ] = EQUALS_SIGN; destination[ destOffset + 3 ] = EQUALS_SIGN; return destination; - + default: return destination; } // end switch @@ -592,18 +592,18 @@ public class Base64 } - - + + /** * Serializes an object and returns the Base64-encoded - * version of that serialized object. - * + * version of that serialized object. + * *

      As of v 2.3, if the object * cannot be serialized or there is another error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but * in retrospect that's a pretty poor way to handle it.

      - * + * * The object is not GZip-compressed before being encoded. * * @param serializableObject The object to encode @@ -616,19 +616,19 @@ public class Base64 throws java.io.IOException { return encodeObject( serializableObject, NO_OPTIONS ); } // end encodeObject - + /** * Serializes an object and returns the Base64-encoded * version of that serialized object. - * + * *

      As of v 2.3, if the object * cannot be serialized or there is another error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but * in retrospect that's a pretty poor way to handle it.

      - * + * * The object is not GZip-compressed before being encoded. *

      * Example options:

      @@ -654,14 +654,14 @@ public class Base64
               if( serializableObject == null ){
                   throw new NullPointerException( "Cannot serialize a null object." );
               }   // end if: null
      -        
      +
               // Streams
      -        java.io.ByteArrayOutputStream  baos  = null; 
      +        java.io.ByteArrayOutputStream  baos  = null;
               java.io.OutputStream           b64os = null;
               java.util.zip.GZIPOutputStream gzos  = null;
               java.io.ObjectOutputStream     oos   = null;
      -        
      -        
      +
      +
               try {
                   // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream
                   baos  = new java.io.ByteArrayOutputStream();
      @@ -687,7 +687,7 @@ public class Base64
                   try{ b64os.close(); } catch( Exception e ){}
                   try{ baos.close();  } catch( Exception e ){}
               }   // end finally
      -        
      +
               // Return value according to relevant encoding.
               try {
                   return new String( baos.toByteArray(), PREFERRED_ENCODING );
      @@ -696,15 +696,15 @@ public class Base64
                   // Fall back to some Java default
                   return new String( baos.toByteArray() );
               }   // end catch
      -        
      +
           }   // end encode
      -    
      -    
      +
      +
       
           /**
            * Encodes a byte array into Base64 notation.
            * Does not GZip-compress data.
      -     *  
      +     *
            * @param source The data to convert
            * @return The data in Base64-encoded form
            * @throws NullPointerException if source array is null
      @@ -723,7 +723,7 @@ public class Base64
               assert encoded != null;
               return encoded;
           }   // end encodeBytes
      -    
      +
       
       
           /**
      @@ -739,12 +739,12 @@ public class Base64
            * 

      * Example: encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES ) * - * + * *

      As of v 2.3, if there is an error with the GZIP stream, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but * in retrospect that's a pretty poor way to handle it.

      - * + * * * @param source The data to convert * @param options Specified options @@ -758,17 +758,17 @@ public class Base64 public static String encodeBytes( byte[] source, int options ) throws java.io.IOException { return encodeBytes( source, 0, source.length, options ); } // end encodeBytes - - + + /** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. - * + * *

      As of v 2.3, if there is an error, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but * in retrospect that's a pretty poor way to handle it.

      - * + * * * @param source The data to convert * @param off Offset in array where conversion should begin @@ -791,8 +791,8 @@ public class Base64 assert encoded != null; return encoded; } // end encodeBytes - - + + /** * Encodes a byte array into Base64 notation. @@ -807,12 +807,12 @@ public class Base64 *

      * Example: encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES ) * - * + * *

      As of v 2.3, if there is an error with the GZIP stream, * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned a null value, but * in retrospect that's a pretty poor way to handle it.

      - * + * * * @param source The data to convert * @param off Offset in array where conversion should begin @@ -836,7 +836,7 @@ public class Base64 catch (java.io.UnsupportedEncodingException uue) { return new String( encoded ); } // end catch - + } // end encodeBytes @@ -986,34 +986,34 @@ public class Base64 //System.err.println("No need to resize array."); return outBuff; } - + } // end else: don't compress } // end encodeBytesToBytes - - - - + + + + /* ******** D E C O D I N G M E T H O D S ******** */ - - + + /** * Decodes four bytes from array source * and writes the resulting bytes (up to three of them) * to destination. * The source and destination arrays can be manipulated - * anywhere along their length by specifying + * anywhere along their length by specifying * srcOffset and destOffset. * This method does not check to make sure your arrays * are large enough to accomodate srcOffset + 4 for * the source array or destOffset + 3 for * the destination array. - * This method returns the actual number of bytes that + * This method returns the actual number of bytes that * were converted from the Base64 encoding. *

      This is the lowest level of the decoding methods with * all possible parameters.

      - * + * * * @param source the array to convert * @param srcOffset the index where conversion begins @@ -1026,10 +1026,10 @@ public class Base64 * or there is not enough room in the array. * @since 1.3 */ - private static int decode4to3( - byte[] source, int srcOffset, + private static int decode4to3( + byte[] source, int srcOffset, byte[] destination, int destOffset, int options ) { - + // Lots of error checking and exception throwing if( source == null ){ throw new NullPointerException( "Source array was null." ); @@ -1045,10 +1045,10 @@ public class Base64 throw new IllegalArgumentException( String.format( "Destination array with length %d cannot have offset of %d and still store three bytes.", destination.length, destOffset ) ); } // end if - - - byte[] DECODABET = getDecodabet( options ); - + + + byte[] DECODABET = getDecodabet( options ); + // Example: Dk== if( source[ srcOffset + 2] == EQUALS_SIGN ) { // Two ways to do the same thing. Don't know which way I like best. @@ -1056,11 +1056,11 @@ public class Base64 // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 ); int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 ); - + destination[ destOffset ] = (byte)( outBuff >>> 16 ); return 1; } - + // Example: DkL= else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) { // Two ways to do the same thing. Don't know which way I like best. @@ -1070,12 +1070,12 @@ public class Base64 int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 ); - + destination[ destOffset ] = (byte)( outBuff >>> 16 ); destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 ); return 2; } - + // Example: DkLE else { // Two ways to do the same thing. Don't know which way I like best. @@ -1088,7 +1088,7 @@ public class Base64 | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6) | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) ); - + destination[ destOffset ] = (byte)( outBuff >> 16 ); destination[ destOffset + 1 ] = (byte)( outBuff >> 8 ); destination[ destOffset + 2 ] = (byte)( outBuff ); @@ -1096,7 +1096,7 @@ public class Base64 return 3; } } // end decodeToBytes - + @@ -1125,8 +1125,8 @@ public class Base64 return decoded; } - - + + /** * Low-level access to decoding ASCII characters in * the form of a byte array. Ignores GUNZIP option, if @@ -1146,7 +1146,7 @@ public class Base64 */ public static byte[] decode( byte[] source, int off, int len, int options ) throws java.io.IOException { - + // Lots of error checking and exception throwing if( source == null ){ throw new NullPointerException( "Cannot decode null source array." ); @@ -1155,29 +1155,29 @@ public class Base64 throw new IllegalArgumentException( String.format( "Source array with length %d cannot have offset of %d and process %d bytes.", source.length, off, len ) ); } // end if - + if( len == 0 ){ return new byte[0]; }else if( len < 4 ){ - throw new IllegalArgumentException( + throw new IllegalArgumentException( "Base64-encoded string must have at least four characters, but length specified was " + len ); } // end if - + byte[] DECODABET = getDecodabet( options ); - + int len34 = len * 3 / 4; // Estimate on array size byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output int outBuffPosn = 0; // Keep track of where we're writing - + byte[] b4 = new byte[4]; // Four byte buffer from source, eliminating white space int b4Posn = 0; // Keep track of four byte input buffer int i = 0; // Source array counter byte sbiDecode = 0; // Special value from DECODABET - + for( i = off; i < off+len; i++ ) { // Loop through source - + sbiDecode = DECODABET[ source[i]&0xFF ]; - + // White space, Equals sign, or legit Base64 character // Note the values such as -5 and -9 in the // DECODABETs at the top of the file. @@ -1187,7 +1187,7 @@ public class Base64 if( b4Posn > 3 ) { // Time to decode? outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn, options ); b4Posn = 0; - + // If that was the equals sign, break out of 'for' loop if( source[i] == EQUALS_SIGN ) { break; @@ -1198,18 +1198,18 @@ public class Base64 else { // There's a bad input character in the Base64 stream. throw new java.io.IOException( String.format( - "Bad Base64 input character decimal %d in array position %d", ((int)source[i])&0xFF, i ) ); - } // end else: + "Bad Base64 input character decimal %d in array position %d", source[i]&0xFF, i ) ); + } // end else: } // each input character - + byte[] out = new byte[ outBuffPosn ]; - System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); + System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); return out; } // end decode - - - - + + + + /** * Decodes data from Base64 notation, automatically * detecting gzip-compressed data and decompressing it. @@ -1223,8 +1223,8 @@ public class Base64 return decode( s, NO_OPTIONS ); } - - + + /** * Decodes data from Base64 notation, automatically * detecting gzip-compressed data and decompressing it. @@ -1237,11 +1237,11 @@ public class Base64 * @since 1.4 */ public static byte[] decode( String s, int options ) throws java.io.IOException { - + if( s == null ){ throw new NullPointerException( "Input string was null." ); } // end if - + byte[] bytes; try { bytes = s.getBytes( PREFERRED_ENCODING ); @@ -1250,16 +1250,16 @@ public class Base64 bytes = s.getBytes(); } // end catch // - + // Decode bytes = decode( bytes, 0, bytes.length, options ); - + // Check to see if it's gzip-compressed // GZIP Magic Two-Byte Number: 0x8b1f (35615) boolean dontGunzip = (options & DONT_GUNZIP) != 0; if( (bytes != null) && (bytes.length >= 4) && (!dontGunzip) ) { - - int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + + int head = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) { java.io.ByteArrayInputStream bais = null; java.util.zip.GZIPInputStream gzis = null; @@ -1292,7 +1292,7 @@ public class Base64 } // end if: gzipped } // end if: bytes.length >= 2 - + return bytes; } // end decode @@ -1314,7 +1314,7 @@ public class Base64 throws java.io.IOException, java.lang.ClassNotFoundException { return decodeToObject(encodedObject,NO_OPTIONS,null); } - + /** * Attempts to decode Base64 data and deserialize a Java @@ -1328,21 +1328,21 @@ public class Base64 * @return The decoded and deserialized object * @throws NullPointerException if encodedObject is null * @throws java.io.IOException if there is a general error - * @throws ClassNotFoundException if the decoded object is of a + * @throws ClassNotFoundException if the decoded object is of a * class that cannot be found by the JVM * @since 2.3.4 */ - public static Object decodeToObject( + public static Object decodeToObject( String encodedObject, int options, final ClassLoader loader ) throws java.io.IOException, java.lang.ClassNotFoundException { - + // Decode and gunzip if necessary byte[] objBytes = decode( encodedObject, options ); - + java.io.ByteArrayInputStream bais = null; java.io.ObjectInputStream ois = null; Object obj = null; - + try { bais = new java.io.ByteArrayInputStream( objBytes ); @@ -1358,7 +1358,7 @@ public class Base64 @Override public Class resolveClass(java.io.ObjectStreamClass streamClass) throws java.io.IOException, ClassNotFoundException { - Class c = Class.forName(streamClass.getName(), false, loader); + Class c = Class.forName(streamClass.getName(), false, loader); if( c == null ){ return super.resolveClass(streamClass); } else { @@ -1367,7 +1367,7 @@ public class Base64 } // end resolveClass }; // end ois } // end else: no custom class loader - + obj = ois.readObject(); } // end try catch( java.io.IOException e ) { @@ -1380,12 +1380,12 @@ public class Base64 try{ bais.close(); } catch( Exception e ){} try{ ois.close(); } catch( Exception e ){} } // end finally - + return obj; } // end decodeObject - - - + + + /** * Convenience method for encoding data to a file. * @@ -1393,7 +1393,7 @@ public class Base64 * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but * in retrospect that's a pretty poor way to handle it.

      - * + * * @param dataToEncode byte array of data to encode in base64 form * @param filename Filename for saving encoded data * @throws java.io.IOException if there is an error @@ -1402,14 +1402,14 @@ public class Base64 */ public static void encodeToFile( byte[] dataToEncode, String filename ) throws java.io.IOException { - + if( dataToEncode == null ){ throw new NullPointerException( "Data to encode was null." ); } // end iff - + Base64.OutputStream bos = null; try { - bos = new Base64.OutputStream( + bos = new Base64.OutputStream( new java.io.FileOutputStream( filename ), Base64.ENCODE ); bos.write( dataToEncode ); } // end try @@ -1419,10 +1419,10 @@ public class Base64 finally { try{ bos.close(); } catch( Exception e ){} } // end finally - + } // end encodeToFile - - + + /** * Convenience method for decoding data to a file. * @@ -1430,7 +1430,7 @@ public class Base64 * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but * in retrospect that's a pretty poor way to handle it.

      - * + * * @param dataToDecode Base64-encoded data as a string * @param filename Filename for saving decoded data * @throws java.io.IOException if there is an error @@ -1438,10 +1438,10 @@ public class Base64 */ public static void decodeToFile( String dataToDecode, String filename ) throws java.io.IOException { - + Base64.OutputStream bos = null; try{ - bos = new Base64.OutputStream( + bos = new Base64.OutputStream( new java.io.FileOutputStream( filename ), Base64.DECODE ); bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) ); } // end try @@ -1451,12 +1451,12 @@ public class Base64 finally { try{ bos.close(); } catch( Exception e ){} } // end finally - + } // end decodeToFile - - - - + + + + /** * Convenience method for reading a base64-encoded * file and decoding it. @@ -1465,7 +1465,7 @@ public class Base64 * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but * in retrospect that's a pretty poor way to handle it.

      - * + * * @param filename Filename for reading encoded data * @return decoded byte array * @throws java.io.IOException if there is an error @@ -1473,7 +1473,7 @@ public class Base64 */ public static byte[] decodeFromFile( String filename ) throws java.io.IOException { - + byte[] decodedData = null; Base64.InputStream bis = null; try @@ -1483,28 +1483,28 @@ public class Base64 byte[] buffer = null; int length = 0; int numBytes = 0; - + // Check for size of file if( file.length() > Integer.MAX_VALUE ) { throw new java.io.IOException( "File is too big for this convenience method (" + file.length() + " bytes)." ); } // end if: file too big for int index buffer = new byte[ (int)file.length() ]; - + // Open a stream - bis = new Base64.InputStream( - new java.io.BufferedInputStream( + bis = new Base64.InputStream( + new java.io.BufferedInputStream( new java.io.FileInputStream( file ) ), Base64.DECODE ); - + // Read until done while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) { length += numBytes; } // end while - + // Save in a variable to return decodedData = new byte[ length ]; System.arraycopy( buffer, 0, decodedData, 0, length ); - + } // end try catch( java.io.IOException e ) { throw e; // Catch and release to execute finally{} @@ -1512,12 +1512,12 @@ public class Base64 finally { try{ bis.close(); } catch( Exception e) {} } // end finally - + return decodedData; } // end decodeFromFile - - - + + + /** * Convenience method for reading a binary file * and base64-encoding it. @@ -1526,7 +1526,7 @@ public class Base64 * the method will throw an java.io.IOException. This is new to v2.3! * In earlier versions, it just returned false, but * in retrospect that's a pretty poor way to handle it.

      - * + * * @param filename Filename for reading binary data * @return base64-encoded string * @throws java.io.IOException if there is an error @@ -1534,7 +1534,7 @@ public class Base64 */ public static String encodeFromFile( String filename ) throws java.io.IOException { - + String encodedData = null; Base64.InputStream bis = null; try @@ -1544,20 +1544,20 @@ public class Base64 byte[] buffer = new byte[ Math.max((int)(file.length() * 1.4+1),40) ]; // Need max() for math on small files (v2.2.1); Need +1 for a few corner cases (v2.3.5) int length = 0; int numBytes = 0; - + // Open a stream - bis = new Base64.InputStream( - new java.io.BufferedInputStream( + bis = new Base64.InputStream( + new java.io.BufferedInputStream( new java.io.FileInputStream( file ) ), Base64.ENCODE ); - + // Read until done while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) { length += numBytes; } // end while - + // Save in a variable to return encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING ); - + } // end try catch( java.io.IOException e ) { throw e; // Catch and release to execute finally{} @@ -1565,10 +1565,10 @@ public class Base64 finally { try{ bis.close(); } catch( Exception e) {} } // end finally - + return encodedData; } // end encodeFromFile - + /** * Reads infile and encodes it to outfile. * @@ -1579,7 +1579,7 @@ public class Base64 */ public static void encodeFileToFile( String infile, String outfile ) throws java.io.IOException { - + String encoded = Base64.encodeFromFile( infile ); java.io.OutputStream out = null; try{ @@ -1593,7 +1593,7 @@ public class Base64 finally { try { out.close(); } catch( Exception ex ){} - } // end finally + } // end finally } // end encodeFileToFile @@ -1607,7 +1607,7 @@ public class Base64 */ public static void decodeFileToFile( String infile, String outfile ) throws java.io.IOException { - + byte[] decoded = Base64.decodeFromFile( infile ); java.io.OutputStream out = null; try{ @@ -1621,14 +1621,14 @@ public class Base64 finally { try { out.close(); } catch( Exception ex ){} - } // end finally + } // end finally } // end decodeFileToFile - - + + /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ - - - + + + /** * A {@link Base64.InputStream} will read data from another * java.io.InputStream, given in the constructor, @@ -1638,18 +1638,18 @@ public class Base64 * @since 1.3 */ public static class InputStream extends java.io.FilterInputStream { - - private boolean encode; // Encoding or decoding + + private final boolean encode; // Encoding or decoding private int position; // Current position in the buffer - private byte[] buffer; // Small buffer holding converted data - private int bufferLength; // Length of buffer (3 or 4) + private final byte[] buffer; // Small buffer holding converted data + private final int bufferLength; // Length of buffer (3 or 4) private int numSigBytes; // Number of meaningful bytes in the buffer private int lineLength; - private boolean breakLines; // Break lines at less than 80 characters - private int options; // Record options used to create the stream. - private byte[] decodabet; // Local copies to avoid extra method calls - - + private final boolean breakLines; // Break lines at less than 80 characters + private final int options; // Record options used to create the stream. + private final byte[] decodabet; // Local copies to avoid extra method calls + + /** * Constructs a {@link Base64.InputStream} in DECODE mode. * @@ -1659,8 +1659,8 @@ public class Base64 public InputStream( java.io.InputStream in ) { this( in, DECODE ); } // end constructor - - + + /** * Constructs a {@link Base64.InputStream} in * either ENCODE or DECODE mode. @@ -1682,7 +1682,7 @@ public class Base64 * @since 2.0 */ public InputStream( java.io.InputStream in, int options ) { - + super( in ); this.options = options; // Record for later this.breakLines = (options & DO_BREAK_LINES) > 0; @@ -1693,7 +1693,7 @@ public class Base64 this.lineLength = 0; this.decodabet = getDecodabet(options); } // end constructor - + /** * Reads enough of the input stream to convert * to/from Base64 and returns the next byte. @@ -1703,7 +1703,7 @@ public class Base64 */ @Override public int read() throws java.io.IOException { - + // Do we need to get data? if( position < 0 ) { if( encode ) { @@ -1719,9 +1719,9 @@ public class Base64 } else { break; // out of for loop } // end else: end of stream - + } // end for: each needed input byte - + if( numBinaryBytes > 0 ) { encode3to4( b3, 0, numBinaryBytes, buffer, 0, options ); position = 0; @@ -1731,7 +1731,7 @@ public class Base64 return -1; // Must be end of stream } // end else } // end if: encoding - + // Else decoding else { byte[] b4 = new byte[4]; @@ -1741,14 +1741,14 @@ public class Base64 int b = 0; do{ b = in.read(); } while( b >= 0 && decodabet[ b & 0x7f ] <= WHITE_SPACE_ENC ); - + if( b < 0 ) { break; // Reads a -1 if end of stream } // end if: end of stream - + b4[i] = (byte)b; } // end for: each needed input byte - + if( i == 4 ) { numSigBytes = decode4to3( b4, 0, buffer, 0, options ); position = 0; @@ -1759,18 +1759,18 @@ public class Base64 else { // Must have broken out from above. throw new java.io.IOException( "Improperly padded Base64 input." ); - } // end - + } // end + } // end else: decode } // end else: get data - + // Got data? if( position >= 0 ) { // End of relevant data? if( /*!encode &&*/ position >= numSigBytes ){ return -1; } // end if: got data - + if( encode && breakLines && lineLength >= MAX_LINE_LENGTH ) { lineLength = 0; return '\n'; @@ -1779,7 +1779,7 @@ public class Base64 lineLength++; // This isn't important when decoding // but throwing an extra "if" seems // just as wasteful. - + int b = buffer[ position++ ]; if( position >= bufferLength ) { @@ -1790,14 +1790,14 @@ public class Base64 // intended to be unsigned. } // end else } // end if: position >= 0 - + // Else error else { throw new java.io.IOException( "Error in Base64 code reading stream." ); } // end else } // end read - - + + /** * Calls {@link #read()} repeatedly until the end of stream * is reached or len bytes are read. @@ -1811,13 +1811,13 @@ public class Base64 * @since 1.3 */ @Override - public int read( byte[] dest, int off, int len ) + public int read( byte[] dest, int off, int len ) throws java.io.IOException { int i; int b; for( i = 0; i < len; i++ ) { b = read(); - + if( b >= 0 ) { dest[off + i] = (byte) b; } @@ -1830,18 +1830,18 @@ public class Base64 } // end for: each byte read return i; } // end read - + } // end inner class InputStream - - - - - - + + + + + + /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ - - - + + + /** * A {@link Base64.OutputStream} will write data to another * java.io.OutputStream, given in the constructor, @@ -1851,18 +1851,18 @@ public class Base64 * @since 1.3 */ public static class OutputStream extends java.io.FilterOutputStream { - - private boolean encode; + + private final boolean encode; private int position; private byte[] buffer; - private int bufferLength; + private final int bufferLength; private int lineLength; - private boolean breakLines; - private byte[] b4; // Scratch used in a few places + private final boolean breakLines; + private final byte[] b4; // Scratch used in a few places private boolean suspendEncoding; - private int options; // Record for later - private byte[] decodabet; // Local copies to avoid extra method calls - + private final int options; // Record for later + private final byte[] decodabet; // Local copies to avoid extra method calls + /** * Constructs a {@link Base64.OutputStream} in ENCODE mode. * @@ -1872,8 +1872,8 @@ public class Base64 public OutputStream( java.io.OutputStream out ) { this( out, ENCODE ); } // end constructor - - + + /** * Constructs a {@link Base64.OutputStream} in * either ENCODE or DECODE mode. @@ -1906,8 +1906,8 @@ public class Base64 this.options = options; this.decodabet = getDecodabet(options); } // end constructor - - + + /** * Writes the byte to the output stream after * converting to/from Base64 notation. @@ -1921,19 +1921,19 @@ public class Base64 * @since 1.3 */ @Override - public void write(int theByte) + public void write(int theByte) throws java.io.IOException { // Encoding suspended? if( suspendEncoding ) { this.out.write( theByte ); return; } // end if: supsended - + // Encode? if( encode ) { buffer[ position++ ] = (byte)theByte; if( position >= bufferLength ) { // Enough to encode. - + this.out.write( encode3to4( b4, buffer, bufferLength, options ) ); lineLength += 4; @@ -1952,7 +1952,7 @@ public class Base64 if( decodabet[ theByte & 0x7f ] > WHITE_SPACE_ENC ) { buffer[ position++ ] = (byte)theByte; if( position >= bufferLength ) { // Enough to output. - + int len = Base64.decode4to3( buffer, 0, b4, 0, options ); out.write( b4, 0, len ); position = 0; @@ -1963,11 +1963,11 @@ public class Base64 } // end else: not white space either } // end else: decoding } // end write - - - + + + /** - * Calls {@link #write(int)} repeatedly until len + * Calls {@link #write(int)} repeatedly until len * bytes are written. * * @param theBytes array from which to read bytes @@ -1976,22 +1976,22 @@ public class Base64 * @since 1.3 */ @Override - public void write( byte[] theBytes, int off, int len ) + public void write( byte[] theBytes, int off, int len ) throws java.io.IOException { // Encoding suspended? if( suspendEncoding ) { this.out.write( theBytes, off, len ); return; } // end if: supsended - + for( int i = 0; i < len; i++ ) { write( theBytes[ off + i ] ); } // end for: each byte written - + } // end write - - - + + + /** * Method added by PHIL. [Thanks, PHIL. -Rob] * This pads the buffer without closing the stream. @@ -2010,9 +2010,9 @@ public class Base64 } // end flush - - /** - * Flushes and closes (I think, in the superclass) the stream. + + /** + * Flushes and closes (I think, in the superclass) the stream. * * @since 1.3 */ @@ -2024,13 +2024,13 @@ public class Base64 // 2. Actually close the stream // Base class both flushes and closes. super.close(); - + buffer = null; out = null; } // end close - - - + + + /** * Suspends encoding of the stream. * May be helpful if you need to embed a piece of @@ -2043,8 +2043,8 @@ public class Base64 flushBase64(); this.suspendEncoding = true; } // end suspendEncoding - - + + /** * Resumes encoding of the stream. * May be helpful if you need to embed a piece of @@ -2055,10 +2055,10 @@ public class Base64 public void resumeEncoding() { this.suspendEncoding = false; } // end resumeEncoding - - - + + + } // end inner class OutputStream - - + + } // end class Base64 diff --git a/org.intrace/testsrc/org/intracetest/agent/StackTraceTest.java b/org.intrace/testsrc/org/intracetest/agent/StackTraceTest.java index a8faa33..86f8aff 100644 --- a/org.intrace/testsrc/org/intracetest/agent/StackTraceTest.java +++ b/org.intrace/testsrc/org/intracetest/agent/StackTraceTest.java @@ -1,18 +1,11 @@ package org.intracetest.agent; -import java.util.Map; - import junit.framework.TestCase; -import org.intrace.agent.AgentSettings; import org.intrace.output.trace.TraceHandler; -import org.intrace.output.trace.TraceSettings; -import org.intrace.shared.AgentConfigConstants; -import org.intrace.shared.TraceConfigConstants; public class StackTraceTest extends TestCase { - private static final String MY_PACKAGE_AND_CLASS = "org.intracetest.agent.StackTraceTest"; private String m_stackTrace; /** Here is the raw stack trace that we want to validate: *
      @@ -23,7 +16,7 @@ org.intracetest.agent.StackTraceTest.c(StackTraceTest.java:57),org.intracetest.a
          * 	
    • java.lang.Thread.getStackTrace
    • *
    • all org.intrace. activity
    • *
    - * + * */ public void testStackTrace() { @@ -41,14 +34,14 @@ public void testStackTrace() } private void validateStackTraceElement(String expectedPackageAndClassAndMethod, String actual) { String[] partsOfStackTraceElement = actual.split("[\\(:\\)]"); - assertEquals("The package and class and method name were not found in the right place", - expectedPackageAndClassAndMethod, + assertEquals("The package and class and method name were not found in the right place", + expectedPackageAndClassAndMethod, partsOfStackTraceElement[0]); - - assertEquals("source file not found in the right place", - "StackTraceTest.java", + + assertEquals("source file not found in the right place", + "StackTraceTest.java", partsOfStackTraceElement[1]); - + } private void a() { b(); diff --git a/org.intrace/testsrc/org/intracetest/agent/TraceSettingsTest.java b/org.intrace/testsrc/org/intracetest/agent/TraceSettingsTest.java index fe34af4..bcd7476 100644 --- a/org.intrace/testsrc/org/intracetest/agent/TraceSettingsTest.java +++ b/org.intrace/testsrc/org/intracetest/agent/TraceSettingsTest.java @@ -4,9 +4,7 @@ import java.util.Map; import junit.framework.TestCase; -import org.intrace.agent.AgentSettings; import org.intrace.output.trace.TraceSettings; -import org.intrace.shared.AgentConfigConstants; import org.intrace.shared.TraceConfigConstants; public class TraceSettingsTest extends TestCase @@ -25,7 +23,7 @@ public class TraceSettingsTest extends TestCase + TraceConfigConstants.EXIT_STACK_TRACE + "true" ); - + assertTrue(ts.isArgTraceEnabled()); assertTrue(ts.isEntryExitTraceEnabled()); assertTrue(ts.isBranchTraceEnabled());