(byte[] serialized, Class<T> clazz)
| 537 | } |
| 538 | |
| 539 | public static <T> T javaDeserialize(byte[] serialized, Class<T> clazz) { |
| 540 | if ("true".equalsIgnoreCase(System.getProperty("java.deserialization.disabled"))) { |
| 541 | throw new AssertionError("java deserialization has been disabled and is only safe from within a worker process"); |
| 542 | } |
| 543 | |
| 544 | try { |
| 545 | ByteArrayInputStream bis = new ByteArrayInputStream(serialized); |
| 546 | ObjectInputStream ois = null; |
| 547 | if (null == Utils.cl) { |
| 548 | ois = new ObjectInputStream(bis); |
| 549 | } else { |
| 550 | // Use custom class loader set in testing environment |
| 551 | ois = new ClassLoaderObjectInputStream(Utils.cl, bis); |
| 552 | } |
| 553 | Object ret = ois.readObject(); |
| 554 | ois.close(); |
| 555 | return (T) ret; |
| 556 | } catch (IOException ioe) { |
| 557 | throw new RuntimeException(ioe); |
| 558 | } catch (ClassNotFoundException e) { |
| 559 | throw new RuntimeException(e); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | public static <S, T> T get(Map<S, T> m, S key, T def) { |
| 564 | T ret = m.get(key); |
no test coverage detected