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 File: ClassUtils.java From kogito-runtimes with Apache License 2.0 | 6 votes |
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 #2
Source File: Amf0ObjectDeserializer.java From riotapi with Apache License 2.0 | 6 votes |
@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 #3
Source File: KafkaUtils.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
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 #4
Source File: ChatActivityFacade.java From QNotified with GNU General Public License v3.0 | 6 votes |
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 #5
Source File: ObjectUtils.java From incubator-hivemall with Apache License 2.0 | 6 votes |
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 #6
Source File: SparkDataSetProcessor.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
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 #7
Source File: Amf3Input.java From flex-blazeds with Apache License 2.0 | 6 votes |
/** * */ 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 #8
Source File: JavaObjectSerializationCompatibility.java From japicmp with Apache License 2.0 | 5 votes |
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 #9
Source File: GridTopicExternalizableSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @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 #10
Source File: JClassUtilsTest.java From jaxb2-basics with BSD 2-Clause "Simplified" License | 5 votes |
@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 #11
Source File: ReflectionFactory.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 #12
Source File: ReflectionFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 #13
Source File: GridTopicExternalizableSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @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 #14
Source File: ReflectionFactory.java From Bytecoder with Apache License 2.0 | 5 votes |
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 File: AbstractJsonWriter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * 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 File: ReflectionFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 File: JndiRequestTest.java From tomee with Apache License 2.0 | 5 votes |
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 #18
Source File: ExternalizableSerializer.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@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 #19
Source File: ExternalizableSerializer.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@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 #20
Source File: ReflectionFactory.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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 File: ReflectionFactory.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 #22
Source File: ObjectUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
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 #23
Source File: ObjectUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
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 #24
Source File: ObjectUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
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 #25
Source File: GridTopicExternalizableSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @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 #26
Source File: InterfaceMapTest.java From development with Apache License 2.0 | 5 votes |
@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)); }
Example #27
Source File: InterfaceMap.java From development with Apache License 2.0 | 5 votes |
private boolean isExcplicitlyRequiredClass(Class<?> i) { Set<Class<?>> requiredClasses = new HashSet<Class<?>>(); requiredClasses.add(EJBTestBase.Caller.class); requiredClasses.add(Comparable.class); requiredClasses.add(Runnable.class); requiredClasses.add(Externalizable.class); requiredClasses.add(javax.enterprise.event.Event.class); requiredClasses.add(org.slf4j.Logger.class); return requiredClasses.contains(i); }
Example #28
Source File: ExternalizableSerializer.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public byte[] serialize(String topic, Externalizable data) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos)){ oos.writeObject(data); oos.flush(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #29
Source File: KafkaStreamer.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public Iterator<String> call(Integer partition, Iterator<T> locatedRowIterator) throws Exception { taskContext = TaskContext.get(); if (taskContext != null && taskContext.attemptNumber() > 0) { LOG.trace("KS.c attempts "+taskContext.attemptNumber()); long entriesInKafka = KafkaUtils.messageCount(bootstrapServers, topicName, partition); LOG.trace("KS.c entries "+entriesInKafka); for (long i = 0; i < entriesInKafka; ++i) { locatedRowIterator.next(); } } Properties props = new Properties(); props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); props.put(ProducerConfig.CLIENT_ID_CONFIG, "spark-producer-dss-ks-"+UUID.randomUUID() ); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, IntegerSerializer.class.getName()); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ExternalizableSerializer.class.getName()); KafkaProducer<Integer, Externalizable> producer = new KafkaProducer<>(props); int count = 0 ; while (locatedRowIterator.hasNext()) { T lr = locatedRowIterator.next(); ProducerRecord<Integer, Externalizable> record = new ProducerRecord(topicName, count++, lr); producer.send(record); LOG.trace("KS.c sent "+partition.intValue()+" "+count+" "+lr); } LOG.trace("KS.c count "+partition.intValue()+" "+count); producer.close(); // TODO Clean up return Arrays.asList("OK").iterator(); }
Example #30
Source File: GridTopicExternalizableSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testSerializationTopicCreatedByIgniteUuidAndUUID() throws Exception { for (Marshaller marsh : getMarshallers()) { info("Test GridTopic externalization [marshaller=" + marsh + ']'); for (GridTopic topic : GridTopic.values()) { Externalizable msgOut = (Externalizable)topic.topic(A_IGNITE_UUID, AN_UUID); assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh)); } } }