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:com.splicemachine.orc.predicate.SpliceORCPredicate.java
public static SpliceORCPredicate deserialize(String base64String) throws IOException { return (SpliceORCPredicate) SerializationUtils.deserialize(Base64.decodeBase64(base64String)); }
From source file:com.iveely.computing.api.StreamChannel.java
@Override public void invoke(StreamPacket packet) { OutputExecutor outputExecutor;/* www . j a v a2s .c o m*/ if (executor instanceof OutputExecutor) { outputExecutor = (OutputExecutor) executor; } else { return; } int streamType = packet.getType().ordinal(); if (streamType == StreamType.DATASENDING.ordinal()) { byte[] data = packet.getData(); DataTuple tuple = (DataTuple) SerializationUtils.deserialize(data); outputExecutor.invoke(tuple); } else if (streamType == StreamType.END.ordinal()) { outputExecutor.end(); } }
From source file:com.gargoylesoftware.htmlunit.WebClient2Test.java
/** * Background tasks that have been registered before the serialization should * wake up and run normally after the deserialization. * Until now (2.7-SNAPSHOT 17.09.09) HtmlUnit has probably never supported it. * This is currently not requested and this test is just to document the current status. * @throws Exception if an error occurs//from w ww . ja v a 2 s. co m */ @Test @NotYetImplemented public void serialization_withJSBackgroundTasks() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function foo() {\n" + " if (window.name == 'hello') {\n" + " alert('exiting');\n" + " clearInterval(intervalId);\n" + " }\n" + " }\n" + " var intervalId = setInterval(foo, 10);\n" + "</script></head>\n" + "<body></body></html>"; final HtmlPage page = loadPageWithAlerts(html); // verify that 1 background job exists assertEquals(1, page.getEnclosingWindow().getJobManager().getJobCount()); final byte[] bytes = SerializationUtils.serialize(page); page.getWebClient().close(); // deserialize page and verify that 1 background job exists final HtmlPage clonedPage = (HtmlPage) SerializationUtils.deserialize(bytes); assertEquals(1, clonedPage.getEnclosingWindow().getJobManager().getJobCount()); // configure a new CollectingAlertHandler (in fact it has surely already one and we could get and cast it) final List<String> collectedAlerts = Collections.synchronizedList(new ArrayList<String>()); final AlertHandler alertHandler = new CollectingAlertHandler(collectedAlerts); clonedPage.getWebClient().setAlertHandler(alertHandler); // make some change in the page on which background script reacts clonedPage.getEnclosingWindow().setName("hello"); clonedPage.getWebClient().waitForBackgroundJavaScriptStartingBefore(100); assertEquals(0, clonedPage.getEnclosingWindow().getJobManager().getJobCount()); final String[] expectedAlerts = { "exiting" }; assertEquals(expectedAlerts, collectedAlerts); }
From source file:io.pravega.controller.store.stream.ZKStreamMetadataStore.java
@Override public CompletableFuture<Boolean> takeBucketOwnership(int bucket, String processId, Executor executor) { Preconditions.checkArgument(bucket < bucketCount); // try creating an ephemeral node String bucketPath = ZKPaths.makePath(ZKStoreHelper.BUCKET_OWNERSHIP_PATH, String.valueOf(bucket)); return storeHelper.createEphemeralZNode(bucketPath, SerializationUtils.serialize(processId)) .thenCompose(created -> { if (!created) { // Note: data may disappear by the time we do a getData. Let exception be thrown from here // so that caller may retry. return storeHelper.getData(bucketPath).thenApply( data -> (SerializationUtils.deserialize(data.getData())).equals(processId)); } else { return CompletableFuture.completedFuture(true); }/* w ww.j a v a 2 s. co m*/ }); }
From source file:gobblin.runtime.spec_catalog.FlowCatalog.java
@Override public Spec deserialize(byte[] spec) { return SerializationUtils.deserialize(spec); }
From source file:com.splicemachine.derby.impl.sql.execute.operations.scanner.TableScannerBuilder.java
public static TableScannerBuilder getTableScannerBuilderFromBase64String(String base64String) throws IOException, StandardException { if (base64String == null) throw new IOException("tableScanner base64 String is null"); return (TableScannerBuilder) SerializationUtils.deserialize(Base64.decodeBase64(base64String)); }
From source file:com.jkoolcloud.tnt4j.utils.Utils.java
/** * Serialize a given object into a byte array * * @param bytes// ww w . j a v a 2 s . c o m * containing serializable object * * @return object */ public static Object deserialize(byte[] bytes) { return SerializationUtils.deserialize(bytes); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPageTest.java
/** * @throws Exception if the test fails/*from ww w. ja va 2 s . com*/ */ @Test public void serialization() throws Exception { // The document.all and form.elements calls are important because they trigger the creation // of HTMLCollections, which have caused serialization problems in the past (see bug 1951047). final String content = "<html><body>\n" + "<div id='myId'>Hello there!</div>\n" + "<script>" + " var x = document.all;" + " window.onload=function(){alert('foo')};" // this tests 3103703 // we don't store the jobs are pending at the moment of serialization + " var aktiv = window.setInterval('foo()', 1000);\n" + " var i = 0;\n" + " function foo() {\n" + " i = i + 1;\n" + " if (i >= 10)\n" + " window.clearInterval(aktiv);\n" + " }" + "</script>\n" + "<form name='f' id='f'></form>\n" + "<script>var y = document.getElementById('f').elements;</script>\n" + "</body></html>"; // waiting for the alerts creates some more js objects associated with the page // this tests 3103703 final List<String> expectedAlerts = new LinkedList<>(); expectedAlerts.add("foo"); final HtmlPage page1 = loadPage(content, expectedAlerts); final byte[] bytes = SerializationUtils.serialize(page1); final HtmlPage page2 = (HtmlPage) SerializationUtils.deserialize(bytes); final Iterator<HtmlElement> iterator1 = page1.getHtmlElementDescendants().iterator(); final Iterator<HtmlElement> iterator2 = page2.getHtmlElementDescendants().iterator(); while (iterator1.hasNext()) { assertTrue(iterator2.hasNext()); final HtmlElement element1 = iterator1.next(); final HtmlElement element2 = iterator2.next(); assertEquals(element1.getNodeName(), element2.getNodeName()); } assertFalse(iterator2.hasNext()); assertEquals("Hello there!", page2.getHtmlElementById("myId").getFirstChild().getNodeValue()); }
From source file:net.spfbl.core.Analise.java
public static void load() { long time = System.currentTimeMillis(); File file = new File("./data/analise.set"); if (file.exists()) { try {// www.j av a2 s. c om TreeSet<Analise> set; FileInputStream fileInputStream = new FileInputStream(file); try { set = SerializationUtils.deserialize(fileInputStream); } finally { fileInputStream.close(); } for (Analise analise : set) { try { if (analise.semaphoreSet == null) { analise.semaphoreSet = new Semaphore(1); } analise.ipSet.addAll(analise.processSet); analise.processSet.clear(); add(analise); } catch (Exception ex) { Server.logError(ex); } } Server.logLoad(time, file); } catch (Exception ex) { Server.logError(ex); } } time = System.currentTimeMillis(); file = new File("./data/cluster.map"); if (file.exists()) { try { TreeMap<String, Short[]> map; FileInputStream fileInputStream = new FileInputStream(file); try { map = SerializationUtils.deserialize(fileInputStream); } finally { fileInputStream.close(); } for (String token : map.keySet()) { Short[] value = map.get(token); if (token.contains("#") || token.contains(".H.")) { String hostname = token.replace("#", "0"); hostname = hostname.replace(".H.", ".0a."); if (Domain.isHostname(hostname)) { clusterMap.put(token, value); } } else if (Owner.isOwnerCPF(token.substring(1))) { String ownerID = Owner.normalizeID(token.substring(1)); clusterMap.put(ownerID, value); } else if (Owner.isOwnerID(token)) { String ownerID = Owner.normalizeID(token); clusterMap.put(ownerID, value); } else if (Subnet.isValidCIDR(token)) { clusterMap.put(token, value); } else if (Domain.isHostname(token)) { String hostname = Domain.normalizeHostname(token, true); if (Domain.isOfficialTLD(hostname) && !hostname.endsWith(".br")) { clusterMap.put(hostname, value); } } } Server.logLoad(time, file); } catch (Exception ex) { Server.logError(ex); } } }
From source file:net.spfbl.core.Client.java
public static synchronized void load() { long time = System.currentTimeMillis(); File file = new File("./data/client.map"); if (file.exists()) { try {/*from w w w . ja v a2 s . co m*/ HashMap<String, Object> map; FileInputStream fileInputStream = new FileInputStream(file); try { map = SerializationUtils.deserialize(fileInputStream); } finally { fileInputStream.close(); } for (String key : map.keySet()) { Object value = map.get(key); if (value instanceof Client) { Client client = (Client) value; if (client.permission == null) { client.permission = Permission.NONE; client.administrator = false; } else if (client.permission == Permission.ALL) { client.permission = Permission.SPFBL; client.administrator = true; } if (client.limit == 0) { client.limit = 100; } if (client.actionBLOCK == null) { client.actionBLOCK = Action.REJECT; } if (client.actionRED == null) { client.actionRED = Action.FLAG; } if (client.actionYELLOW == null) { client.actionYELLOW = Action.DEFER; } if (client.actionGRACE == null) { client.actionGRACE = Action.DEFER; } if (client.personality == null) { client.personality = Personality.RATIONAL; } MAP.put(key, client); } } Server.logLoad(time, file); } catch (Exception ex) { Server.logError(ex); } } }