Java Code Examples for org.apache.commons.lang.SerializationUtils#deserialize()

The following examples show how to use org.apache.commons.lang.SerializationUtils#deserialize() . 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: NemoEventDecoderFactory.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Override
public Object decode() throws IOException {

  final byte isWatermark = (byte) inputStream.read();
  if (isWatermark == -1) {
    // end of the input stream
    throw new EOFException();
  }

  if (isWatermark == 0x00) {
    // this is not a watermark
    return valueDecoder.decode();
  } else if (isWatermark == 0x01) {
    // this is a watermark
    final WatermarkWithIndex watermarkWithIndex =
      (WatermarkWithIndex) SerializationUtils.deserialize(inputStream);
    return watermarkWithIndex;
  } else {
    throw new RuntimeException("Watermark decoding failure: " + isWatermark);
  }
}
 
Example 2
Source File: ParamSupply.java    From onedev with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
public static Class<? extends Serializable> loadBeanClass(String className) {
	if (className.startsWith(PARAM_BEAN_PREFIX)) {
		byte[] bytes;
		try {
			bytes = Hex.decodeHex(className.substring(PARAM_BEAN_PREFIX.length()+1).toCharArray());
		} catch (DecoderException e) {
			throw new RuntimeException(e);
		}
		List<ParamSpec> paramSpecs = (List<ParamSpec>) SerializationUtils.deserialize(bytes);
		return defineBeanClass(paramSpecs);
	} else {
		return null;
	}
}
 
Example 3
Source File: JedisCacheDriver.java    From rebuild with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public V getx(String key) {
	Jedis jedis = null;
	try {
		jedis = jedisPool.getResource();

		byte[] bs = jedis.get(key.getBytes());
		if (bs == null || bs.length == 0) {
			return null;
		}
		
		Object s = SerializationUtils.deserialize(bs);
		// Check type of generic?
		return (V) s;
	} finally {
		IOUtils.closeQuietly(jedis);
	}
}
 
Example 4
Source File: GroupResultDiskBuffer.java    From dble with GNU General Public License v2.0 6 votes vote down vote up
@Override
public RowDataPacket nextRow() {
    RowDataPacket rp = super.nextRow();
    if (rp == null)
        return null;
    else {
        DGRowPacket newRow = new DGRowPacket(orgFieldCount, sumSize);
        for (int index = 0; index < sumSize; index++) {
            byte[] b = rp.getValue(index);
            if (b != null) {
                Object obj = SerializationUtils.deserialize(b);
                newRow.setSumTran(index, obj, b.length);
            }
        }
        for (int index = sumSize; index < this.fieldCount; index++) {
            newRow.add(rp.getValue(index));
        }
        return newRow;
    }
}
 
Example 5
Source File: NodeMonitoring.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the technology service status.
 * 
 * @return the serviceStatus
 */
@Transient
public Map<String, Map<String, Boolean>> getTechnologyServiceStatus() {
	// Get technology status bytes if null return null.
	if (getTechnologyServiceBytes() == null) {
		return null;
	}
	
	// serializing the data.
	return (HashMap<String, Map<String, Boolean>>) SerializationUtils
			.deserialize(getTechnologyServiceBytes());
}
 
Example 6
Source File: NodeMonitoring.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
	 * Method to get Service Status in its raw state i.e. without any check or update.
	 * 
	 * @param technology
	 * @return
	 */
	@Transient
	public HashMap<String, Map<String, Boolean>> getTechnologyGroupedRawServiceStatus(String technology) {
		HashMap<String, Map<String, Boolean>> techServiceMap = new HashMap<String, Map<String, Boolean>>();
		HashMap<String, Map<String, Boolean>> serviceMap = new HashMap<String, Map<String, Boolean>>();
		byte [] techBytes = getTechnologyServiceBytes();
		if (techBytes == null) {
			return serviceMap;
		}

		// deserializing the data.
		techServiceMap = (HashMap<String, Map<String, Boolean>>) SerializationUtils
				.deserialize(techBytes);


		if (technology != null) {
			serviceMap.put(technology, techServiceMap.get(technology)); 
		} else {
			serviceMap.putAll(techServiceMap);
		}
		
/*		
		if (technology == null) {
			Map agentStatus = new HashMap<String, Boolean>();
			agentStatus.put(Constant.Component.Name.AGENT, isAgentDown());
			serviceMap.put(Constant.Component.Name.AGENT, agentStatus);
		}
*/		
		
		// return service status.
		return serviceMap;
	}
 
Example 7
Source File: NodeMonitoring.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the monitoring info.
 * 
 * @return the monitoringInfo
 */
@Transient
public MonitoringInfo getMonitoringInfo() {
	if (getMonitoringInfoBytes() == null) {
		return null;
	}
	return (MonitoringInfo) SerializationUtils
			.deserialize(getMonitoringInfoBytes());
}
 
Example 8
Source File: RemoteApiVersionTest.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerial() {
    SerializationUtils.serialize(RemoteApiVersion.unknown());
    final RemoteApiVersion remoteApiVersion = RemoteApiVersion.create(1, 20);

    final byte[] serialized = SerializationUtils.serialize(remoteApiVersion);
    RemoteApiVersion deserialized = (RemoteApiVersion) SerializationUtils.deserialize(serialized);

    assertThat("Deserialized object mush match source object", deserialized, equalTo(remoteApiVersion));
}
 
Example 9
Source File: DefaultDockerClientConfigTest.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void serializableTest() {
    final byte[] serialized = SerializationUtils.serialize(EXAMPLE_CONFIG);
    final DefaultDockerClientConfig deserialized = (DefaultDockerClientConfig) SerializationUtils.deserialize(serialized);

    assertThat("Deserialized object mush match source object", deserialized, equalTo(EXAMPLE_CONFIG));
}
 
Example 10
Source File: FastDateFormatTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testLang303() {
    Calendar cal = Calendar.getInstance();
    cal.set(2004,11,31);

    FastDateFormat format = FastDateFormat.getInstance("yyyy/MM/dd");
    String output = format.format(cal);

    format = (FastDateFormat) SerializationUtils.deserialize( SerializationUtils.serialize( format ) );
    assertEquals(output, format.format(cal));
}
 
Example 11
Source File: Cluster.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Transient
public ClusterConfig getClusterConfig() {
	if (getConfBytes() == null) {
		return null;
	}
	return (ClusterConfig) SerializationUtils.deserialize(getConfBytes());
}
 
Example 12
Source File: StormParserDriver.java    From metron with Apache License 2.0 5 votes vote down vote up
public ProcessorResult<List<byte[]>> run(Iterable<byte[]> in) {
  ShimParserBolt bolt = new ShimParserBolt(new ArrayList<>());
  byte[] b = SerializationUtils.serialize(bolt);
  ShimParserBolt b2 = (ShimParserBolt) SerializationUtils.deserialize(b);
  OutputCollector collector = mock(OutputCollector.class);
  bolt.prepare(null, null, collector);
  for(byte[] record : in) {
    Tuple tuple = toTuple(record);
    bolt.execute(tuple);
    verify(collector, times(1)).ack(tuple);
  }
  return bolt.getResults();
}
 
Example 13
Source File: NodeMonitoring.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Method to sset graph view data.
 * 
 * @return
 */
@Transient
public HashMap getGraphViewData() {
	// if graphViewData is not null.
	if (this.graphView != null) {
		try {
			return (HashMap) SerializationUtils.deserialize(this
					.getGraphView());
		} catch (Exception e) {
			return new HashMap();
		}
	}
	return new HashMap();
}
 
Example 14
Source File: SpanTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Test
public void span_serializes_and_deserializes_with_no_data_loss() {
    Span span = new Span(
        traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId,
        spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan,
        startTimeNanosForFullyCompleteSpan, durationNanosForFullyCompletedSpan, tags, annotations
    );

    byte[] bytes = SerializationUtils.serialize(span);
    Span deserializedSpan = (Span) SerializationUtils.deserialize(bytes);

    verifySpanDeepEquals(span, deserializedSpan, false);
}
 
Example 15
Source File: SingleRedisConnection.java    From RedisHttpSession with Apache License 2.0 5 votes vote down vote up
@Override
public Object hget(String key, String field) {
    byte[] bytes = jedis.hget(key.getBytes(), field.getBytes());
    if (bytes == null){
        return null;
    } else {
        return SerializationUtils.deserialize(bytes);
    }
}
 
Example 16
Source File: NodeMonitoring.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the technology data.
 * 
 * @return the technologyData
 */
@Transient
public Map<String, TechnologyData> getTechnologyData() {
	if (getTechnologyDataBytes() == null) {
		return null;
	}
	return (Map<String, TechnologyData>) SerializationUtils
			.deserialize(getTechnologyDataBytes());
}
 
Example 17
Source File: KubernetesResource.java    From onedev with MIT License 5 votes vote down vote up
@Path("/report-job-caches")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@POST
public void reportJobCaches(byte[] cacheInstanceBytes) {
	@SuppressWarnings("unchecked")
	Collection<CacheInstance> cacheInstances = (Collection<CacheInstance>) SerializationUtils
			.deserialize(cacheInstanceBytes);
	jobManager.reportJobCaches(getJobToken(), cacheInstances);
}
 
Example 18
Source File: KubernetesResource.java    From onedev with MIT License 5 votes vote down vote up
@Path("/allocate-job-caches")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
   @POST
   public byte[] allocateJobCaches(byte[] cacheAllocationRequestBytes) {
	CacheAllocationRequest allocationRequest = (CacheAllocationRequest) SerializationUtils
			.deserialize(cacheAllocationRequestBytes);
	return SerializationUtils.serialize((Serializable) jobManager.allocateJobCaches(
			getJobToken(), allocationRequest.getCurrentTime(), allocationRequest.getInstances()));
   }
 
Example 19
Source File: TranslationOperation.java    From modernmt with Apache License 2.0 4 votes vote down vote up
@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    byte[] taskBytes = in.readByteArray();
    this.task = (TranslationTask) SerializationUtils.deserialize(taskBytes);
}
 
Example 20
Source File: ClientConnection.java    From PE-HFT-Java with GNU General Public License v3.0 3 votes vote down vote up
public Metric getAllSymbolsList() throws Exception {

		Message responseMsg;
		Message msg = ClientRequestMessageFactory.createTransactionalPortfolioComputeRequest(getTemplateRegistry(), "ALL_SYMBOLS", "", "",
				getOutboundMsgSequenceNumber(), System.currentTimeMillis());

		responseMsg = sendAndAwaitResponse(msg, USER_LAYER_TIMEOUT_SECONDS_ESTIMATE);

		TransmitDataRequest response = ServerResponseMessageParser.parseTransmitDataRequest(responseMsg);
		Metric result = new Metric();

		if (response.getMsgType().contains("OK")) {

			byte data[] = response.getDataFloatByte();

			data = Snappy.uncompress(data, 0, data.length);
			Map<String, String[]> map = (Map<String, String[]>) SerializationUtils.deserialize(data);

			ArrayCache id = new ArrayCache(map.get("id"));
			ArrayCache description = new ArrayCache(map.get("description"));
			ArrayCache exchange = new ArrayCache(map.get("exchange"));

			result.setData("id", id);
			result.setData("description", description);
			result.setData("exchange", exchange);

		} else {

			throw new Exception(response.getMsgBody());
		}

		return result;
	}