NO_JIRA: Fixed whitespace issues in code: removed tabs, fixed indentation, removed trailing whitespace
Project: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/commit/36c7b3be Tree: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/tree/36c7b3be Diff: http://git-wip-us.apache.org/repos/asf/qpid-interop-test/diff/36c7b3be Branch: refs/heads/master Commit: 36c7b3be80e71f41f4a2625cf3cec336f205c2c5 Parents: 4e6f4f2 Author: Kim van der Riet <[email protected]> Authored: Wed May 4 13:36:28 2016 -0400 Committer: Kim van der Riet <[email protected]> Committed: Wed May 4 13:36:28 2016 -0400 ---------------------------------------------------------------------- .../obj_util/BytesToJavaObj.java | 110 +++++------ .../obj_util/JavaObjToBytes.java | 184 +++++++++---------- 2 files changed, 147 insertions(+), 147 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-interop-test/blob/36c7b3be/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/BytesToJavaObj.java ---------------------------------------------------------------------- diff --git a/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/BytesToJavaObj.java b/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/BytesToJavaObj.java index 8c461ce..0d97333 100644 --- a/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/BytesToJavaObj.java +++ b/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/BytesToJavaObj.java @@ -23,61 +23,61 @@ import java.io.ObjectInputStream; import java.io.Serializable; public class BytesToJavaObj { - String hexObjStr = null; - Serializable obj = null; - - public BytesToJavaObj(String hexObjStr) { - this.hexObjStr = hexObjStr; - } - - public String run() { - byte[] bytes = hexStrToByteArray(this.hexObjStr); - this.obj = byteArrayToObject(bytes); - if (this.obj != null) { - return this.obj.getClass().getName() + ":" + this.obj.toString(); - } - return "<null>"; - } - - protected Serializable byteArrayToObject(byte[] bytes) { - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - ObjectInput in = null; - try { - in = new ObjectInputStream(bis); - return (Serializable) in.readObject(); - } catch (ClassNotFoundException e) { - e.printStackTrace(System.out); - } catch (IOException e) { - e.printStackTrace(System.out); - } finally { - try { - bis.close(); - } catch (IOException e) {} // ignore - try { - in.close(); - } catch (IOException e) {} // ignore - } - return null; - } - - protected byte[] hexStrToByteArray(String hexStr) { - int len = hexStr.length(); - byte[] data = new byte[len / 2]; - for(int i=0; i<len; i+=2) { - data[i/2] = (byte)((Character.digit(hexStr.charAt(i), 16) << 4) + Character.digit(hexStr.charAt(i+1), 16)); - } - return data; - } - + String hexObjStr = null; + Serializable obj = null; + + public BytesToJavaObj(String hexObjStr) { + this.hexObjStr = hexObjStr; + } + + public String run() { + byte[] bytes = hexStrToByteArray(this.hexObjStr); + this.obj = byteArrayToObject(bytes); + if (this.obj != null) { + return this.obj.getClass().getName() + ":" + this.obj.toString(); + } + return "<null>"; + } + + protected Serializable byteArrayToObject(byte[] bytes) { + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInput in = null; + try { + in = new ObjectInputStream(bis); + return (Serializable) in.readObject(); + } catch (ClassNotFoundException e) { + e.printStackTrace(System.out); + } catch (IOException e) { + e.printStackTrace(System.out); + } finally { + try { + bis.close(); + } catch (IOException e) {} // ignore + try { + in.close(); + } catch (IOException e) {} // ignore + } + return null; + } + + protected byte[] hexStrToByteArray(String hexStr) { + int len = hexStr.length(); + byte[] data = new byte[len / 2]; + for(int i=0; i<len; i+=2) { + data[i/2] = (byte)((Character.digit(hexStr.charAt(i), 16) << 4) + Character.digit(hexStr.charAt(i+1), 16)); + } + return data; + } + // ========= main ========== - + public static void main(String[] args) { - if (args.length != 1) { - System.out.println("BytesToJavaObj: Incorrect argument count"); - System.out.println("BytesToJavaObj: Expected argument: \"<java_serialized_obj_str_hex>\""); - System.exit(1); - } - BytesToJavaObj btjo = new BytesToJavaObj(args[0]); - System.out.println(btjo.run()); - } + if (args.length != 1) { + System.out.println("BytesToJavaObj: Incorrect argument count"); + System.out.println("BytesToJavaObj: Expected argument: \"<java_serialized_obj_str_hex>\""); + System.exit(1); + } + BytesToJavaObj btjo = new BytesToJavaObj(args[0]); + System.out.println(btjo.run()); + } } http://git-wip-us.apache.org/repos/asf/qpid-interop-test/blob/36c7b3be/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/JavaObjToBytes.java ---------------------------------------------------------------------- diff --git a/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/JavaObjToBytes.java b/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/JavaObjToBytes.java index 2bfbde0..a16f0b1 100644 --- a/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/JavaObjToBytes.java +++ b/utils/src/main/java/org/apache/qpid/qpid_interop_test/obj_util/JavaObjToBytes.java @@ -26,104 +26,104 @@ import java.lang.reflect.InvocationTargetException; //import java.util.Arrays; public class JavaObjToBytes { - String javaClassName = null; - String ctorArgStr = null; - Serializable obj = null; - - public JavaObjToBytes(String javaClassName, String ctorArgStr) { - this.javaClassName = javaClassName; - this.ctorArgStr = ctorArgStr; - } - - public byte[] run() { - createJavaObject(); - return serializeJavaOjbect(); - } - + String javaClassName = null; + String ctorArgStr = null; + Serializable obj = null; + + public JavaObjToBytes(String javaClassName, String ctorArgStr) { + this.javaClassName = javaClassName; + this.ctorArgStr = ctorArgStr; + } + + public byte[] run() { + createJavaObject(); + return serializeJavaOjbect(); + } + protected void createJavaObject() { - try { - Class<?> c = Class.forName(this.javaClassName); - if (this.javaClassName.compareTo("java.lang.Character") == 0) { - Constructor ctor = c.getConstructor(char.class); - if (this.ctorArgStr.length() == 1) { - // Use first character of string - obj = (Serializable)ctor.newInstance(this.ctorArgStr.charAt(0)); - } else if (this.ctorArgStr.length() == 4 || this.ctorArgStr.length() == 6) { - // Format '\xNN' or '\xNNNN' - obj = (Serializable)ctor.newInstance((char)Integer.parseInt(this.ctorArgStr.substring(2), 16)); - } else { - throw new Exception("JavaObjToBytes.createJavaObject() Malformed char string: \"" + this.ctorArgStr + "\""); - } - } else { - // Use string constructor - Constructor ctor = c.getConstructor(String.class); - obj = (Serializable)ctor.newInstance(this.ctorArgStr); - } - } - catch (ClassNotFoundException e) { - e.printStackTrace(System.out); - } - catch (NoSuchMethodException e) { - e.printStackTrace(System.out); - } - catch (InstantiationException e) { - e.printStackTrace(System.out); - } - catch (IllegalAccessException e) { - e.printStackTrace(System.out); - } - catch (InvocationTargetException e) { - e.printStackTrace(System.out); - } - catch (Exception e) { - e.printStackTrace(System.out); - } + try { + Class<?> c = Class.forName(this.javaClassName); + if (this.javaClassName.compareTo("java.lang.Character") == 0) { + Constructor ctor = c.getConstructor(char.class); + if (this.ctorArgStr.length() == 1) { + // Use first character of string + obj = (Serializable)ctor.newInstance(this.ctorArgStr.charAt(0)); + } else if (this.ctorArgStr.length() == 4 || this.ctorArgStr.length() == 6) { + // Format '\xNN' or '\xNNNN' + obj = (Serializable)ctor.newInstance((char)Integer.parseInt(this.ctorArgStr.substring(2), 16)); + } else { + throw new Exception("JavaObjToBytes.createJavaObject() Malformed char string: \"" + this.ctorArgStr + "\""); + } + } else { + // Use string constructor + Constructor ctor = c.getConstructor(String.class); + obj = (Serializable)ctor.newInstance(this.ctorArgStr); + } + } + catch (ClassNotFoundException e) { + e.printStackTrace(System.out); + } + catch (NoSuchMethodException e) { + e.printStackTrace(System.out); + } + catch (InstantiationException e) { + e.printStackTrace(System.out); + } + catch (IllegalAccessException e) { + e.printStackTrace(System.out); + } + catch (InvocationTargetException e) { + e.printStackTrace(System.out); + } + catch (Exception e) { + e.printStackTrace(System.out); + } } - + protected byte[] serializeJavaOjbect() { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutput out = null; - try { - out = new ObjectOutputStream(bos); - out.writeObject(this.obj); - return bos.toByteArray(); - } catch (IOException e) { - e.printStackTrace(System.out); - } finally { - try { - if (out != null) { - out.close(); - } - } catch (IOException e) {} // ignore - try { - bos.close(); - } catch (IOException e) {} // ignore - } - return null; + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutput out = null; + try { + out = new ObjectOutputStream(bos); + out.writeObject(this.obj); + return bos.toByteArray(); + } catch (IOException e) { + e.printStackTrace(System.out); + } finally { + try { + if (out != null) { + out.close(); + } + } catch (IOException e) {} // ignore + try { + bos.close(); + } catch (IOException e) {} // ignore + } + return null; } - + // ========= main ========== - + public static void main(String[] args) { - if (args.length != 1) { - System.out.println("JavaObjToBytes: Incorrect argument count"); - System.out.println("JavaObjToBytes: Expected argument: \"<java_class_name>:<ctor_arg_str>\""); - System.exit(1); - } - int colonIndex = args[0].indexOf(":"); - if (colonIndex < 0) { - System.out.println("Error: Incorect argument format: " + args[0]); - System.exit(-1); - } - String javaClassName = args[0].substring(0, colonIndex); - String ctorArgStr = args[0].substring(colonIndex+1); - JavaObjToBytes jotb = new JavaObjToBytes(javaClassName, ctorArgStr); - byte[] bytes = jotb.run(); - System.out.println(args[0]); - for (byte b: bytes) { - System.out.print(String.format("%02x", b)); - } - System.out.println(); + if (args.length != 1) { + System.out.println("JavaObjToBytes: Incorrect argument count"); + System.out.println("JavaObjToBytes: Expected argument: \"<java_class_name>:<ctor_arg_str>\""); + System.exit(1); + } + int colonIndex = args[0].indexOf(":"); + if (colonIndex < 0) { + System.out.println("Error: Incorect argument format: " + args[0]); + System.exit(-1); + } + String javaClassName = args[0].substring(0, colonIndex); + String ctorArgStr = args[0].substring(colonIndex+1); + JavaObjToBytes jotb = new JavaObjToBytes(javaClassName, ctorArgStr); + byte[] bytes = jotb.run(); + System.out.println(args[0]); + for (byte b: bytes) { + System.out.print(String.format("%02x", b)); + } + System.out.println(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
