java.io.Externalizable Java Examples

The following examples show how to use java.io.Externalizable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: spliceengine   Author: splicemachine   File: KafkaUtils.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public static long messageCount(String bootstrapServers, String topicName, int partition) {
    Properties props = new Properties();
    String consumerId = UUID.randomUUID().toString();
    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
    props.put(ConsumerConfig.GROUP_ID_CONFIG, "spark-consumer-group-"+consumerId);
    props.put(ConsumerConfig.CLIENT_ID_CONFIG, "spark-consumer-"+consumerId);
    props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, IntegerDeserializer.class.getName());
    props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ExternalizableDeserializer.class.getName());

    KafkaConsumer<Integer, Externalizable> consumer = new KafkaConsumer<Integer, Externalizable>(props);

    TopicPartition topicPartition = new TopicPartition(topicName, partition);
    List<TopicPartition> partitionList = Arrays.asList(topicPartition);
    consumer.assign(partitionList);
    consumer.seekToEnd(partitionList);
    long nextOffset = consumer.position(topicPartition);

    consumer.seekToBeginning(partitionList);
    long firstOffset = consumer.position(topicPartition);

    consumer.close();

    return nextOffset - firstOffset;
}
 
Example #2
Source Project: QNotified   Author: cinit   File: ChatActivityFacade.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void sendAbsStructMsg(QQAppInterface qqAppInterface, Parcelable sessionInfo, Externalizable absStructMsg) {
    if (qqAppInterface == null) throw new NullPointerException("qqAppInterface == null");
    if (sessionInfo == null) throw new NullPointerException("sessionInfo == null");
    if (absStructMsg == null) throw new NullPointerException("absStructMsg == null");
    Method send = null;
    for (Method m : DexKit.doFindClass(DexKit.C_FACADE).getMethods()) {
        if (m.getReturnType().equals(void.class)) {
            Class<?>[] clz = m.getParameterTypes();
            if (clz.length != 3) continue;
            if (clz[0].equals(QQAppInterface.class) && clz[1].equals(_SessionInfo()) && clz[2].isInstance(absStructMsg)) {
                send = m;
                break;
            }
        }
    }
    try {
        send.invoke(null, qqAppInterface, sessionInfo, absStructMsg);
    } catch (Exception e) {
        log(e);
    }
}
 
Example #3
Source Project: kogito-runtimes   Author: kiegroup   File: ClassUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static <T extends Externalizable> T deepClone(T origin, ClassLoader classLoader, Map<String, Object> cloningResources) {
    if (origin == null) {
        return null;
    }
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DroolsObjectOutputStream oos = new DroolsObjectOutputStream(baos);
        if ( cloningResources != null ) { cloningResources.forEach( (k, v) -> oos.addCustomExtensions(k, v) ); }
        oos.writeObject(origin);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        DroolsObjectInputStream ois = new DroolsObjectInputStream(bais, classLoader);
        if ( cloningResources != null ) { cloningResources.forEach( (k, v) -> ois.addCustomExtensions(k, v) ); }
        Object deepCopy = ois.readObject();
        return (T)deepCopy;
    } catch(IOException ioe) {
        throw new RuntimeException(ioe);
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }
}
 
Example #4
Source Project: spliceengine   Author: splicemachine   File: SparkDataSetProcessor.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
public <V> DataSet<ExecRow> readKafkaTopic(String topicName, OperationContext context) throws StandardException {
    Properties props = new Properties();
    String consumerGroupId = "spark-consumer-dss-sdsp";
    String bootstrapServers = SIDriver.driver().getConfiguration().getKafkaBootstrapServers();
    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
    props.put(ConsumerConfig.GROUP_ID_CONFIG, consumerGroupId);
    props.put(ConsumerConfig.CLIENT_ID_CONFIG, consumerGroupId+"-"+UUID.randomUUID());
    props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, IntegerDeserializer.class.getName());
    props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ExternalizableDeserializer.class.getName());

    KafkaConsumer<Integer, Externalizable> consumer = new KafkaConsumer<Integer, Externalizable>(props);
    List ps = consumer.partitionsFor(topicName);
    List<Integer> partitions = new ArrayList<>(ps.size());
    for (int i = 0; i < ps.size(); ++i) {
        partitions.add(i);
    }
    consumer.close();

    SparkDataSet rdd = new SparkDataSet(SpliceSpark.getContext().parallelize(partitions, partitions.size()));
    return rdd.flatMap(new KafkaReadFunction(context, topicName, bootstrapServers));
}
 
Example #5
Source Project: flex-blazeds   Author: apache   File: Amf3Input.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 */
protected void readExternalizable(String className, Object object) throws ClassNotFoundException, IOException
{
    if (object instanceof Externalizable)
    {
        if (isDebug)
            trace.startExternalizableObject(className, objectTable.size() - 1);

        ((Externalizable)object).readExternal(this);
    }
    else
    {
        //Class '{className}' must implement java.io.Externalizable to receive client IExternalizable instances.
        SerializationException ex = new SerializationException();
        ex.setMessage(10305, new Object[] {object.getClass().getName()});
        throw ex;
    }
}
 
Example #6
Source Project: incubator-hivemall   Author: apache   File: ObjectUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static byte[] toCompressedBytes(@Nonnull final Externalizable obj,
        @Nonnull final CompressionAlgorithm algo, final boolean bin2txt) throws IOException {
    FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
    OutputStream out = null;
    FinishableOutputStream dos = null;
    try {
        out = bin2txt ? new Base91OutputStream(bos) : bos;
        dos = CompressionStreamFactory.createOutputStream(out, algo);
        toStream(obj, dos);
        dos.finish(); // flush is called
        return bos.toByteArray_clear();
    } finally {
        IOUtils.closeQuietly(dos);
        IOUtils.closeQuietly(out);
    }
}
 
Example #7
Source Project: riotapi   Author: loldevs   File: Amf0ObjectDeserializer.java    License: Apache License 2.0 6 votes vote down vote up
@SneakyThrows
public Object deserialize(AmfReader reader) {
    Object result = cls.newInstance();

    if (result instanceof Externalizable) {
        ((Externalizable) result).readExternal(reader);
        return result;
    }


    for (Map.Entry<String, Object> field : reader.readAmf0KeyValuePairs().entrySet()) {
        setField(result, field.getKey(), field.getValue());
    }

    return result;
}
 
Example #8
Source Project: Flink-CEPplus   Author: ljygz   File: ClosureCleaner.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean usesCustomSerialization(Class<?> cls) {
	try {
		cls.getDeclaredMethod("writeObject", ObjectOutputStream.class);
		return true;
	} catch (NoSuchMethodException ignored) {}

	return Externalizable.class.isAssignableFrom(cls);
}
 
Example #9
Source Project: spliceengine   Author: splicemachine   File: ExternalizableSerializer.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Externalizable read(Kryo kryo, Input input, Class<Externalizable> type) {
    try {
        Externalizable e = kryo.newInstance(type);
        KryoObjectInput koi = new KryoObjectInput(input,kryo);
        e.readExternal(koi);
        return e;
    } catch (IOException | ClassNotFoundException e1) {
        throw new RuntimeException(e1);
    }
}
 
Example #10
Source Project: streaminer   Author: mayconbordin   File: ExternalizableUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static byte[] toBytes(Externalizable o) throws IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    o.writeExternal(out);
    out.flush();
    return baos.toByteArray();
}
 
Example #11
Source Project: java-technology-stack   Author: codeEngraver   File: ClassUtilsTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testIsCacheSafe() {
	ClassLoader childLoader1 = new ClassLoader(classLoader) {};
	ClassLoader childLoader2 = new ClassLoader(classLoader) {};
	ClassLoader childLoader3 = new ClassLoader(classLoader) {
		@Override
		public Class<?> loadClass(String name) throws ClassNotFoundException {
			return childLoader1.loadClass(name);
		}
	};
	Class<?> composite = ClassUtils.createCompositeInterface(
			new Class<?>[] {Serializable.class, Externalizable.class}, childLoader1);

	assertTrue(ClassUtils.isCacheSafe(String.class, null));
	assertTrue(ClassUtils.isCacheSafe(String.class, classLoader));
	assertTrue(ClassUtils.isCacheSafe(String.class, childLoader1));
	assertTrue(ClassUtils.isCacheSafe(String.class, childLoader2));
	assertTrue(ClassUtils.isCacheSafe(String.class, childLoader3));
	assertFalse(ClassUtils.isCacheSafe(InnerClass.class, null));
	assertTrue(ClassUtils.isCacheSafe(InnerClass.class, classLoader));
	assertTrue(ClassUtils.isCacheSafe(InnerClass.class, childLoader1));
	assertTrue(ClassUtils.isCacheSafe(InnerClass.class, childLoader2));
	assertTrue(ClassUtils.isCacheSafe(InnerClass.class, childLoader3));
	assertFalse(ClassUtils.isCacheSafe(composite, null));
	assertFalse(ClassUtils.isCacheSafe(composite, classLoader));
	assertTrue(ClassUtils.isCacheSafe(composite, childLoader1));
	assertFalse(ClassUtils.isCacheSafe(composite, childLoader2));
	assertTrue(ClassUtils.isCacheSafe(composite, childLoader3));
}
 
Example #12
Source Project: JPPF   Author: jppf-grid   File: ClassDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initialize a class descriptor from the specified class.
 * @param clazz the class from which to initialize.
 * @param serializing whether we are serializing or deserializing.
 * @throws Exception if any error occurs.
 */
void fillIn(final Class<?> clazz, final boolean serializing) throws Exception {
  populated = true;
  this.clazz = clazz;
  primitive = clazz.isPrimitive();
  enumType = clazz.isEnum();
  if (!primitive && !enumType) {
    externalizable = Externalizable.class.isAssignableFrom(clazz);
    //hasReadWriteObject = handleReadOrWriteObjectMethod(true) && handleReadOrWriteObjectMethod(false);
    hasReadWriteObject = handleReadOrWriteObjectMethod(serializing);
    array = clazz.isArray();
    if (!array) fields = SerializationReflectionHelper.getPersistentDeclaredFields(clazz);
  }
  if (signature == null) signature = SerializationReflectionHelper.getSignatureFromType(clazz);
}
 
Example #13
Source Project: tomee   Author: apache   File: JndiRequestTest.java    License: Apache License 2.0 5 votes vote down vote up
private void externalize(final Externalizable original, final Externalizable copy) throws IOException, ClassNotFoundException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream out = new ObjectOutputStream(baos);

    original.writeExternal(out);
    out.close();

    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream in = new ObjectInputStream(bais);

    copy.readExternal(in);
}
 
Example #14
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ReflectionFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an accessible no-arg constructor for an externalizable class to be
 * initialized using a public no-argument constructor.
 *
 * @param cl the class to instantiate
 * @return A no-arg constructor for the class; returns {@code null} if
 *     the class does not implement {@link java.io.Externalizable}
 */
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
Example #15
Source Project: lams   Author: lamsfoundation   File: AbstractJsonWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method to declare various Java types to be handles as JSON array.
 * 
 * @param clazz the type
 * @return <code>true</code> if handles as array
 * @since 1.4
 */
protected boolean isArray(Class clazz) {
    return clazz != null && (clazz.isArray()
        || Collection.class.isAssignableFrom(clazz)
        || Externalizable.class.isAssignableFrom(clazz)
        || Map.class.isAssignableFrom(clazz)
        || Map.Entry.class.isAssignableFrom(clazz));
}
 
Example #16
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ReflectionFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an accessible no-arg constructor for an externalizable class to be
 * initialized using a public no-argument constructor.
 *
 * @param cl the class to instantiate
 * @return A no-arg constructor for the class; returns {@code null} if
 *     the class does not implement {@link java.io.Externalizable}
 */
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
Example #17
Source Project: Bytecoder   Author: mirkosertic   File: ReflectionFactory.java    License: Apache License 2.0 5 votes vote down vote up
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
Example #18
Source Project: japicmp   Author: siom79   File: JavaObjectSerializationCompatibility.java    License: Apache License 2.0 5 votes vote down vote up
private JApiJavaObjectSerializationCompatibility.JApiJavaObjectSerializationChangeStatus checkChangesForInterfaces(JApiClass jApiClass, JApiJavaObjectSerializationCompatibility.JApiJavaObjectSerializationChangeStatus state) {
	boolean serializableAdded = false;
	boolean serializableRemoved = false;
	boolean serializableUnchanged = false;
	boolean externalizableAdded = false;
	boolean externalizableRemoved = false;
	for (JApiImplementedInterface implementedInterface : jApiClass.getInterfaces()) {
		if (Serializable.class.getCanonicalName().equals(implementedInterface.getFullyQualifiedName())) {
			if (implementedInterface.getChangeStatus() == JApiChangeStatus.NEW) {
				serializableAdded = true;
			} else if (implementedInterface.getChangeStatus() == JApiChangeStatus.REMOVED) {
				serializableRemoved = true;
			} else if (implementedInterface.getChangeStatus() == JApiChangeStatus.UNCHANGED) {
				serializableUnchanged = true;
			}
		}
		if (Externalizable.class.getCanonicalName().equals(implementedInterface.getFullyQualifiedName())) {
			if (implementedInterface.getChangeStatus() == JApiChangeStatus.NEW) {
				externalizableAdded = true;
			} else if (implementedInterface.getChangeStatus() == JApiChangeStatus.REMOVED) {
				externalizableRemoved = true;
			}
		}
	}
	if (serializableRemoved) {
		state = JApiJavaObjectSerializationCompatibility.JApiJavaObjectSerializationChangeStatus.SERIALIZABLE_INCOMPATIBLE_SERIALIZABLE_REMOVED;
	}
	if (externalizableRemoved) {
		state = JApiJavaObjectSerializationCompatibility.JApiJavaObjectSerializationChangeStatus.SERIALIZABLE_INCOMPATIBLE_EXTERNALIZABLE_REMOVED;
	}
	if ((serializableRemoved || serializableUnchanged || serializableAdded) && externalizableAdded) {
		state = JApiJavaObjectSerializationCompatibility.JApiJavaObjectSerializationChangeStatus.SERIALIZABLE_INCOMPATIBLE_CHANGED_FROM_SERIALIZABLE_TO_EXTERNALIZABLE;
	}
	if ((serializableUnchanged || serializableAdded) && externalizableRemoved) {
		state = JApiJavaObjectSerializationCompatibility.JApiJavaObjectSerializationChangeStatus.SERIALIZABLE_INCOMPATIBLE_CHANGED_FROM_EXTERNALIZABLE_TO_SERIALIZABLE;
	}
	return state;
}
 
Example #19
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ReflectionFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
Example #20
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: ReflectionFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an accessible no-arg constructor for an externalizable class to be
 * initialized using a public no-argument constructor.
 *
 * @param cl the class to instantiate
 * @return A no-arg constructor for the class; returns {@code null} if
 *     the class does not implement {@link java.io.Externalizable}
 */
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
Example #21
Source Project: jaxb2-basics   Author: highsource   File: JClassUtilsTest.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void correctlyChecksIsInstanceOf()
		throws JClassAlreadyExistsException {

	final JClass arrayList = codeModel.ref("java.util.ArrayList");
	Assert.assertTrue(JClassUtils.isInstanceOf(arrayList, Collection.class));
	final JDefinedClass subArrayList = codeModel._class("SubArrayList");
	subArrayList._extends(arrayList);
	Assert.assertTrue(JClassUtils.isInstanceOf(subArrayList,
			Collection.class));

	final JClass subArrayListOfObjects = subArrayList.narrow(Object.class);
	Assert.assertTrue(JClassUtils.isInstanceOf(subArrayListOfObjects,
			Collection.class));

	final JDefinedClass subExternalizable = codeModel
			._class("SubExternalizable");
	subExternalizable._implements(Externalizable.class);
	Assert.assertTrue(JClassUtils.isInstanceOf(subExternalizable,
			Externalizable.class));

	subArrayList._implements(subExternalizable);
	Assert.assertTrue(JClassUtils.isInstanceOf(subArrayList,
			Externalizable.class));

	Assert.assertFalse(JClassUtils.isInstanceOf(codeModel.NULL,
			Collection.class));

}
 
Example #22
Source Project: ignite   Author: apache   File: GridTopicExternalizableSelfTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSerializationTopicCreatedByStrinAndLong() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');

        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable)topic.topic(A_STRING, A_LONG);

            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
 
Example #23
Source Project: spliceengine   Author: splicemachine   File: ExternalizableSerializer.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, Externalizable object) {
    KryoObjectOutput koo = new KryoObjectOutput(output, kryo);
    try {
        object.writeExternal(koo);
    } catch (IOException e) {
        //shouldn't happen
        throw new RuntimeException(e);
    }
}
 
Example #24
Source Project: ignite   Author: apache   File: GridTopicExternalizableSelfTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSerializationTopicCreatedByStringAndUUIDAndLong() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');

        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable)topic.topic(A_STRING, AN_UUID, A_LONG);

            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
 
Example #25
Source Project: jdk8u_jdk   Author: JetBrains   File: ReflectionFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an accessible no-arg constructor for an externalizable class to be
 * initialized using a public no-argument constructor.
 *
 * @param cl the class to instantiate
 * @return A no-arg constructor for the class; returns {@code null} if
 *     the class does not implement {@link java.io.Externalizable}
 */
public final Constructor<?> newConstructorForExternalization(Class<?> cl) {
    if (!Externalizable.class.isAssignableFrom(cl)) {
        return null;
    }
    try {
        Constructor<?> cons = cl.getConstructor();
        cons.setAccessible(true);
        return cons;
    } catch (NoSuchMethodException ex) {
        return null;
    }
}
 
Example #26
Source Project: incubator-hivemall   Author: apache   File: ObjectUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static byte[] toCompressedBytes(@Nonnull final Externalizable obj) throws IOException {
    FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos);
    try {
        toStream(obj, dos);
        dos.finish();
        dos.flush();
        return bos.toByteArray_clear();
    } finally {
        IOUtils.closeQuietly(dos);
    }
}
 
Example #27
Source Project: incubator-hivemall   Author: apache   File: ObjectUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void readCompressedObject(@Nonnull final byte[] src,
        @Nonnull final Externalizable dst) throws IOException, ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(src);
    final InflaterInputStream iis = new InflaterInputStream(bis);
    try {
        readObject(iis, dst);
    } finally {
        IOUtils.closeQuietly(iis);
    }
}
 
Example #28
Source Project: incubator-hivemall   Author: apache   File: ObjectUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void readCompressedObject(@Nonnull final byte[] src, final int len,
        @Nonnull final Externalizable dst, @Nonnull final CompressionAlgorithm algo,
        final boolean bin2txt) throws IOException, ClassNotFoundException {
    FastByteArrayInputStream bis = new FastByteArrayInputStream(src, len);
    InputStream in = null;
    InputStream compressedStream = null;
    try {
        in = bin2txt ? new Base91InputStream(bis) : bis;
        compressedStream = CompressionStreamFactory.createInputStream(in, algo);
        readObject(compressedStream, dst);
    } finally {
        IOUtils.closeQuietly(compressedStream);
        IOUtils.closeQuietly(in);
    }
}
 
Example #29
Source Project: ignite   Author: apache   File: GridTopicExternalizableSelfTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSerializationTopicCreatedByString() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');

        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable)topic.topic(A_STRING);

            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
 
Example #30
Source Project: development   Author: servicecatalog   File: InterfaceMapTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGet() {
    InterfaceMap<Object> map = new InterfaceMap<Object>();
    A a = new A();
    B b = new B();
    map.put(a, a);
    map.put(b, b);
    assertSame(a, map.get(Runnable.class));
    assertSame(b, map.get(Externalizable.class));
    assertSame(b, map.get(Comparable.class));
}