List of usage examples for org.springframework.util SerializationUtils serialize
@Nullable public static byte[] serialize(@Nullable Object object)
From source file:org.owasp.webgoat.session.UserTracker.java
@SneakyThrows private void save() { File file = new File(webgoatHome, user + ".progress"); FileCopyUtils.copy(SerializationUtils.serialize(this.storage), file); }
From source file:com.baidu.rigel.biplatform.ma.ds.service.impl.DataSourceServiceImpl.java
/** * {@inheritDoc}//from w ww. ja v a2s . c om */ @Override public synchronized DataSourceDefine saveOrUpdateDataSource(DataSourceDefine ds, String securityKey) throws DataSourceOperationException { checkDataSourceDefine(ds, securityKey); try { // ?????????? DataSourceDefine oldDs = getDsDefine(ds.getId()); String oldDsFileName = null; if (oldDs != null && !oldDs.getName().equals(ds.getName())) { // ???? oldDsFileName = getDsFileName(oldDs); if (this.isNameExist(ds.getName())) { throw new DataSourceOperationException("name already exist : " + ds.getName()); } } String fileName = getDsFileName(ds); boolean rmOperResult = false; if (oldDsFileName != null) { // ???????? rmOperResult = fileService.rm(oldDsFileName); } if (oldDsFileName == null || rmOperResult) { // ?? fileService.write(fileName, SerializationUtils.serialize(ds)); } } catch (Exception e) { // ? ? logger.error(e.getMessage(), e); throw new DataSourceOperationException("Error Happend for save or update datasource :" + e); } return ds; }
From source file:com.zxy.commons.cache.RedisCache.java
/** * {@inheritDoc}/*from w ww . j a va 2 s. c om*/ */ @Override public ValueWrapper putIfAbsent(Object key, Object value) { return redisTemplate.execute(new RedisCallback<ValueWrapper>() { public ValueWrapper doInRedis(RedisConnection connection) throws DataAccessException { byte[] keyb = SerializationUtils.serialize(key); byte[] valueb = SerializationUtils.serialize(value); connection.setNX(keyb, valueb); if (expires > 0) { connection.expire(keyb, expires); } return new SimpleValueWrapper(value); } }); }
From source file:com.zxy.commons.cache.RedisCache.java
@Override public void evict(Object key) { redisTemplate.execute(new RedisCallback<Long>() { public Long doInRedis(RedisConnection connection) throws DataAccessException { return connection.del(SerializationUtils.serialize(key)); }/* w w w . j a va2s . co m*/ }); }
From source file:fr.mby.saml2.sp.opensaml.core.OpenSaml20IdpConnectorTest.java
@Test public void testBuildQueryAuthnRequest() throws Exception { final Map<String, String[]> parametersMap = new HashMap<String, String[]>(); final String[] paramMapValue = new String[] { "value42" }; parametersMap.put("key42", paramMapValue); final QueryAuthnRequest query = this.idpConnector.buildQueryAuthnRequest(parametersMap); Assert.assertNotNull("Query cannot be null !", query); Assert.assertNotNull("QueryAuthnRequest's parameters map cannot be null !", query.getParametersMap()); Assert.assertArrayEquals("Bad param values in QueryAuthnRequest !", paramMapValue, query.getParametersMap().get("key42")); Assert.assertNotNull("QueryAuthnRequest's Id cannot be null !", query.getId()); Assert.assertNotNull("QueryAuthnRequest's IdPConnectorBuilder cannot be null !", query.getIdpConnectorBuilder()); // Test Serialization final byte[] serialized = SerializationUtils.serialize(query); final QueryAuthnRequest deserializedQuery = (QueryAuthnRequest) SerializationUtils.deserialize(serialized); Assert.assertEquals("Serialization / Deserialization problem !", query.getId(), deserializedQuery.getId()); Assert.assertNotNull("Serialization / Deserialization problem !", deserializedQuery.getIdpConnectorBuilder()); Assert.assertEquals("Serialization / Deserialization problem !", query.getIdpConnectorBuilder(), deserializedQuery.getIdpConnectorBuilder()); Assert.assertArrayEquals("Serialization / Deserialization problem !", paramMapValue, deserializedQuery.getParametersMap().get("key42")); }
From source file:com.rabbitmq.client.impl.SocketFrameHandler.java
public void writeFrame(Frame frame) throws IOException { if (frame != null) { log.debug("writeFrame: addr(" + this.getAddress() + ":" + this.getPort() + "))]: " + frame + ": " + new String(frame.getPayload())); }//from ww w. jav a 2 s.c om if (this.getPort() == RMQ_INSIDE) { RmqUdpFrame rmqUdpFrame = new RmqUdpFrame(++index, frame.channel, frame.type, frame.getPayload()); byte[] payload = SerializationUtils.serialize(rmqUdpFrame); log.info("rmq.frame.index(" + rmqUdpFrame.getIndex() + ").type(" + frame.type + ").channel(" + frame.channel + ").payload(" + frame.getPayload().length + ")"); try { unicastSendingMessageHandler.handleMessageInternal(new GenericMessage<byte[]>(payload)); Thread.sleep(WAIT_MILLIS); } catch (InterruptedException e) { e.printStackTrace(); } } synchronized (_outputStream) { frame.writeTo(_outputStream); } }
From source file:fr.mby.saml2.sp.opensaml.core.OpenSaml20IdpConnectorTest.java
@Test public void testBuildQuerySloResponse() throws Exception { final QuerySloResponse query = this.idpConnector.buildQuerySloResponse(this.sloRequestId); Assert.assertNotNull("Query cannot be null !", query); Assert.assertNotNull("QuerySloResponse's Id !", query.getId()); Assert.assertEquals("QuerySloResponse's InResponseTo Id !", this.sloRequestId, query.getInResponseToId()); // Test Serialization final byte[] serialized = SerializationUtils.serialize(query); final QuerySloResponse deserializedQuery = (QuerySloResponse) SerializationUtils.deserialize(serialized); Assert.assertEquals("Serialization / Deserialization problem !", query.getId(), deserializedQuery.getId()); Assert.assertEquals("Serialization / Deserialization problem !", query.getInResponseToId(), deserializedQuery.getInResponseToId()); }
From source file:fr.mby.saml2.sp.opensaml.core.OpenSaml20IdpConnectorTest.java
@Test public void testBuildQuerySloRequest() throws Exception { final QuerySloRequest query = this.idpConnector.buildQuerySloRequest(); Assert.assertNotNull("Query cannot be null !", query); Assert.assertNotNull("QuerySloResponse's Id !", query.getId()); Assert.assertNotNull("QueryAuthnRequest's IdPConnectorBuilder cannot be null !", query.getIdpConnectorBuilder()); // Test Serialization final byte[] serialized = SerializationUtils.serialize(query); final QuerySloRequest deserializedQuery = (QuerySloRequest) SerializationUtils.deserialize(serialized); Assert.assertEquals("Serialization / Deserialization problem !", query.getId(), deserializedQuery.getId()); Assert.assertNotNull("Serialization / Deserialization problem !", deserializedQuery.getIdpConnectorBuilder()); Assert.assertEquals("Serialization / Deserialization problem !", query.getIdpConnectorBuilder(), deserializedQuery.getIdpConnectorBuilder()); }
From source file:com.flipkart.phantom.runtime.impl.server.netty.handler.command.CommandInterpreter.java
/** * Writes the specified TaskResult data to the Outputstream following the Command protocol * @param outputStream the Outputstream to write result data to * @param result the TaskResult to write * @throws Exception in case of any errors *//*from ww w . j a v a 2 s . c o m*/ public void writeCommandExecutionResponse(OutputStream outputStream, TaskResult result) throws Exception { //Don't write anything if the result is null if (result == null) { return; } String message = result.getMessage(); boolean success = result.isSuccess(); int resultDatalength = result.getLength(); String metaContents = (message == null ? (success ? SUCCESS : ERROR) : message); metaContents += (resultDatalength == 0 ? LINE_FEED : (DEFAULT_DELIM + NULL_STRING + resultDatalength + NULL_STRING + LINE_FEED)); // write the meta contents outputStream.write(metaContents.getBytes()); // now write the result data if (result.isDataArray()) { for (Object object : result.getDataArray()) { if (object != null) { if (object instanceof byte[]) { outputStream.write((byte[]) object); } else { outputStream.write(SerializationUtils.serialize(object)); } } } } else { byte[] metaData = result.getMetadata(); if (metaData != null && (metaData.length > 0)) { outputStream.write(metaData); } Object data = result.getData(); if (data != null) { if (data instanceof byte[]) { byte[] byteData = (byte[]) data; if (byteData.length > 0) { outputStream.write(byteData); } } else { outputStream.write(SerializationUtils.serialize(data)); } } } }