/** * Deserializes an array of arguments from a byte array * * @param bytes The byte array containing the serialized arguments * @return an object array */ public static Object[] getInput(byte[] bytes) { if (bytes.length == 0 || (bytes.length == 1 && bytes[0] == 0)) return new Object[0]; ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = null; GZIPInputStream gzis = null; Object[] args = null; try { gzis = new GZIPInputStream(bais); ois = new ObjectInputStream(gzis); Object obj = ois.readObject(); if (obj.getClass().isArray()) { args = new Object[Array.getLength(obj)]; System.arraycopy(obj, 0, args, 0, args.length); } else { args = new Object[] {obj}; } return args; } catch (Exception ex) { throw new RuntimeException("Failed to decode MBeanServerConnection Invocation arguments", ex); } finally { try { bais.close(); } catch (Exception ex) { /* No Op */ } if (ois != null) try { ois.close(); } catch (Exception ex) { /* No Op */ } if (gzis != null) try { gzis.close(); } catch (Exception ex) { /* No Op */ } } }
// Deserialize properly private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); setState(0); // reset to unlocked state }