List of usage examples for org.apache.commons.lang3 SerializationUtils deserialize
public static <T> T deserialize(final byte[] objectData)
Deserializes a single Object from an array of bytes.
From source file:org.lightjason.agentspeak.action.buildin.crypto.CDecrypt.java
@Override public final IFuzzyValue<Boolean> execute(final IContext p_context, final boolean p_parallel, final List<ITerm> p_argument, final List<ITerm> p_return, final List<ITerm> p_annotation) { final Key l_key = p_argument.get(0).raw(); final EAlgorithm l_algorithm = EAlgorithm.from(l_key.getAlgorithm()); return CFuzzyValue.from(p_argument.subList(1, p_argument.size()).stream() .map(i -> Base64.getDecoder().decode(i.<String>raw())).allMatch(i -> { try { p_return.add(CRawTerm.from( SerializationUtils.deserialize(l_algorithm.getDecryptCipher(l_key).doFinal(i)))); return true; } catch (final NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException l_exception) { return false; }//w w w.j a v a2 s . c om })); }
From source file:org.lightjason.agentspeak.action.builtin.crypto.CDecrypt.java
/** * decrypt/*from w w w . j a va 2s .com*/ * * @param p_algorithm algorithm * @param p_key key * @param p_dataset base64 encoded dataset * @param p_return return argument * @return successful execution */ private static boolean decrypt(@Nonnull final EAlgorithm p_algorithm, @Nonnull final Key p_key, @Nonnull final String p_dataset, @Nonnull final List<ITerm> p_return) { try { p_return.add(CRawTerm.from(SerializationUtils.deserialize( p_algorithm.getDecryptCipher(p_key).doFinal(Base64.getDecoder().decode(p_dataset))))); return true; } catch (final IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException l_exception) { return false; } }
From source file:org.nickelproject.nickel.objectStore.CachingObjectStore.java
@Inject public CachingObjectStore(final BlobStore bStore, final CacheBuilderSpec cacheBuilderSpec) { this.blobStore = bStore; this.cache = CacheBuilder.from(cacheBuilderSpec).weigher(new Weigher<BlobRef, Pair<Integer, Object>>() { @Override//from w w w . jav a 2s. c o m public int weigh(final BlobRef key, final Pair<Integer, Object> value) { return value.getA(); } }).build(new CacheLoader<BlobRef, Pair<Integer, Object>>() { @Override public Pair<Integer, Object> load(final BlobRef key) throws Exception { final byte[] bytes = blobStore.get(key); if (bytes == null) { throw new RuntimeException("Unable to load for key: " + key); } else { return Pair.of(bytes.length, SerializationUtils.deserialize(bytes)); } } }); }
From source file:org.nickelproject.nickel.objectStore.Util.java
public static Object objectFromStream(final InputStream stream) { return SerializationUtils.deserialize(stream); }
From source file:org.obsidianbox.obsidian.message.builtin.DownloadLinkMessage.java
@Override public void decode(Game game, ByteBuf buf) throws Exception { if (game.getSide().isServer()) { throw new IOException("Server is not allowed to receive links!"); }/*from w ww . j a v a2s. c o m*/ addonIdentifier = ByteBufUtils.readUTF8String(buf); byte[] data = new byte[buf.readableBytes()]; buf.readBytes(data); url = (URL) SerializationUtils.deserialize(data); }
From source file:org.omnaest.utils.beans.copier.PreparedBeanCopierTest.java
@Test @SuppressWarnings("unchecked") public void testDeepClonePropertiesSerializable() { ////from w w w . j ava 2 s.c o m final ByteArrayContainer byteArrayContainer = new ByteArrayContainer(); SerializationUtils.serialize(this.preparedBeanCopier, byteArrayContainer.getOutputStream()); PreparedBeanCopier<ITestBeanFrom, ITestBeanTo> preparedBeanCopierClone = (PreparedBeanCopier<ITestBeanFrom, ITestBeanTo>) SerializationUtils .deserialize(byteArrayContainer.getInputStream()); // ITestBeanTo clone = preparedBeanCopierClone.deepCloneProperties(this.testBeanFrom); assertTestBeanClone(clone); }
From source file:org.omnaest.utils.structure.container.ByteArrayContainer.java
/** * Deserializes the content into an element * //from ww w .ja v a2s .c o m * @see #copyFromAsSerialized(Serializable) * @return new element instance */ @SuppressWarnings("unchecked") public <S extends Serializable> S toDeserializedElement() { return this.content != null ? (S) SerializationUtils.deserialize(this.content) : null; }
From source file:org.omnaest.utils.table.impl.persistence.SimpleFileBasedTablePersistence.java
/** * @see SimpleFileBasedTablePersistence/*ww w .ja v a2s . co m*/ * @param file * {@link File} * @param exceptionHandler * {@link ExceptionHandlerSerializable} */ public SimpleFileBasedTablePersistence(File file, ExceptionHandlerSerializable exceptionHandler) { super(); this.file = file; this.exceptionHandler = exceptionHandler; if (file != null && file.exists()) { try { final byte[] byteArray = FileUtils.readFileToByteArray(file); @SuppressWarnings("unchecked") final List<E[]> deserializedList = (List<E[]>) SerializationUtils.deserialize(byteArray); if (deserializedList != null) { this.elementsList.addAll(deserializedList); } } catch (Exception e) { if (this.exceptionHandler != null) { this.exceptionHandler.handleException(e); } } } }
From source file:org.opendaylight.controller.cluster.datastore.admin.ClusterAdminRpcServiceTest.java
@Test public void testBackupDatastore() throws Exception { MemberNode node = MemberNode.builder(memberNodes).akkaConfig("Member1") .moduleShardsConfig("module-shards-member1.conf").waitForShardLeader("cars", "people") .testName("testBackupDatastore").build(); String fileName = "target/testBackupDatastore"; new File(fileName).delete(); ClusterAdminRpcService service = new ClusterAdminRpcService(node.configDataStore(), node.operDataStore()); RpcResult<Void> rpcResult = service .backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()) .get(5, TimeUnit.SECONDS); verifySuccessfulRpcResult(rpcResult); try (FileInputStream fis = new FileInputStream(fileName)) { List<DatastoreSnapshot> snapshots = SerializationUtils.deserialize(fis); assertEquals("DatastoreSnapshot size", 2, snapshots.size()); ImmutableMap<String, DatastoreSnapshot> map = ImmutableMap.of(snapshots.get(0).getType(), snapshots.get(0), snapshots.get(1).getType(), snapshots.get(1)); verifyDatastoreSnapshot(node.configDataStore().getActorContext().getDataStoreName(), map.get(node.configDataStore().getActorContext().getDataStoreName()), "cars", "people"); } finally {//from w w w.ja v a 2 s.c o m new File(fileName).delete(); } // Test failure by killing a shard. node.configDataStore().getActorContext().getShardManager().tell( node.datastoreContextBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), ActorRef.noSender()); ActorRef carsShardActor = node.configDataStore().getActorContext().findLocalShard("cars").get(); node.kit().watch(carsShardActor); carsShardActor.tell(PoisonPill.getInstance(), ActorRef.noSender()); node.kit().expectTerminated(carsShardActor); rpcResult = service.backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()).get(5, TimeUnit.SECONDS); assertEquals("isSuccessful", false, rpcResult.isSuccessful()); assertEquals("getErrors", 1, rpcResult.getErrors().size()); }
From source file:org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransactionSerializer.java
@Override public Object fromBinaryJava(final byte[] bytes, final Class<?> clazz) { return SerializationUtils.deserialize(bytes); }