Refine search
protected Object deserialize(byte[] bytes) { Object result = null; ObjectInputStream in = null; try { in = new ClassLoaderObjectInputStream(classLoader, new ByteArrayInputStream(bytes)); result = in.readObject(); } catch (Exception e) { throw new RuntimeException("Unable to deserialize stream ", e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }
/** * Deserialized with ClassLoader */ public static Object javaDeserializeWithCL(byte[] serialized, URLClassLoader loader) { try { ByteArrayInputStream bis = new ByteArrayInputStream(serialized); Object ret; if (loader != null) { ClassLoaderObjectInputStream cis = new ClassLoaderObjectInputStream(loader, bis); ret = cis.readObject(); cis.close(); } else { ObjectInputStream ois = new ObjectInputStream(bis); ret = ois.readObject(); ois.close(); } return ret; } catch (IOException | ClassNotFoundException ioe) { throw new RuntimeException(ioe); } }
@org.junit.Test public void testPrimitiveLong() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); final long input = 12345L; oos.writeLong(input); oos.close(); final InputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ClassLoaderObjectInputStream clois = new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais); final long result = clois.readLong(); assertEquals(input, result); clois.close(); }
@Override public Object read(Kryo kryo, Input input, Class c) { int len = input.readInt(); byte[] ser = new byte[len]; input.readBytes(ser); ByteArrayInputStream bis = new ByteArrayInputStream(ser); try { ClassLoaderObjectInputStream ois = new ClassLoaderObjectInputStream(kryo.getClassLoader(), bis); return ois.readObject(); } catch (Exception e) { throw new RuntimeException(e); } } }
@org.junit.Test public void testResolveProxyClass() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(Boolean.FALSE); final InputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ClassLoaderObjectInputStream clois = new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais); final String[] interfaces = new String[]{Comparable.class.getName()}; final Class<?> result = clois.resolveProxyClass(interfaces); assertTrue("Assignable", Comparable.class.isAssignableFrom(result)); clois.close(); }
ois = new ClassLoaderObjectInputStream(cl, fin); Object cgValue = (Object) ois.readObject();
@Override public Object read(InputStream is) throws IOException { byte[] bytes = (byte[]) super.read(is); if (bytes == null) { return null; } else { ClassLoaderObjectInputStream classLoaderIS = new ClassLoaderObjectInputStream(this.getClassLoader(), is); try { return classLoaderIS.readObject(); } catch (ClassNotFoundException e) { logger.warn(e.getMessage()); IOException iox = new IOException(); iox.initCause(e); throw iox; } finally { classLoaderIS.close(); } } }
public static LogicalPlan read(InputStream is) throws IOException, ClassNotFoundException { return (LogicalPlan)new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), is).readObject(); }
/** * Deserialize the input bytes into object */ @SuppressWarnings("unchecked") public static <T extends Serializable> T deserializeFromBytes(byte[] input, ClassLoader classLoader) throws Exception { //NOSONAR ByteArrayInputStream bis = new ByteArrayInputStream(input); return (T) new ClassLoaderObjectInputStream(classLoader, bis).readObject(); }
@org.junit.Test public void testResolveProxyClassWithMultipleInterfaces() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(Boolean.FALSE); final InputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ClassLoaderObjectInputStream clois = new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais); final String[] interfaces = new String[]{Comparable.class.getName(), Serializable.class.getName(), Runnable.class.getName()}; final Class<?> result = clois.resolveProxyClass(interfaces); assertTrue("Assignable", Comparable.class.isAssignableFrom(result)); assertTrue("Assignable", Runnable.class.isAssignableFrom(result)); assertTrue("Assignable", Serializable.class.isAssignableFrom(result)); assertFalse("Not Assignable", Flushable.class.isAssignableFrom(result)); clois.close(); } }
in = new ClassLoaderObjectInputStream(cl, inputStream); Object obj = in.readObject(); if (obj instanceof DeserializationPostInitialisable)
static <T extends VoidMessage> T fromBytes(byte[] array) { try { ObjectInputStream in = new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), new ByteArrayInputStream(array)); T result = (T) in.readObject(); return result; } catch (Exception e) { throw new RuntimeException(e); } //return SerializationUtils.deserialize(array); }
@org.junit.Test public void testExpected() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); final Object input = Boolean.FALSE; oos.writeObject(input); final InputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ClassLoaderObjectInputStream clois = new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais); final Object result = clois.readObject(); assertEquals(input, result); clois.close(); }
try { in = new ClassLoaderObjectInputStream(cl, inputStream); Object obj = in.readObject(); if (obj instanceof DeserializationPostInitialisable) {
static <T extends VoidMessage> T fromBytes(byte[] array) { try { ObjectInputStream in = new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), new ByteArrayInputStream(array)); T result = (T) in.readObject(); return result; } catch (Exception e) { throw new RuntimeException(e); } //return SerializationUtils.deserialize(array); }
@org.junit.Test public void testLong() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); final Object input = (long) 123; oos.writeObject(input); final InputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ClassLoaderObjectInputStream clois = new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais); final Object result = clois.readObject(); assertEquals(input, result); clois.close(); }
protected Object deserialize(byte[] bytes) { Object result = null; ObjectInputStream in = null; try { in = new ClassLoaderObjectInputStream(classLoader, new ByteArrayInputStream(bytes)); result = in.readObject(); } catch (Exception e) { throw new RuntimeException("Unable to deserialize stream ", e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }
@org.junit.Test public void testObject1() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); final Object input = new Test(123, null); oos.writeObject(input); oos.close(); final InputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ClassLoaderObjectInputStream clois = new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais); final Object result = clois.readObject(); assertEquals(input, result); clois.close(); }
public static Object deserialize(String str) throws IOException { if (str == null || str.length() == 0) return null; ObjectInputStream objStream = null; try { ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str)); objStream = new ClassLoaderObjectInputStream(Thread.currentThread().getContextClassLoader(), new InflaterInputStream(serialObj)); return objStream.readObject(); } catch (Exception e) { throw new IOException("Deserialization error: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(objStream); } }
@org.junit.Test public void testObject2() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); final Object input = new Test(123, 0); oos.writeObject(input); oos.close(); final InputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ClassLoaderObjectInputStream clois = new ClassLoaderObjectInputStream(getClass().getClassLoader(), bais); final Object result = clois.readObject(); assertEquals(input, result); clois.close(); }