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

The following examples show how to use org.apache.commons.lang3.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: SegmentQueryResultTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void resultValidateTest() {
    long segmentBuildTime = System.currentTimeMillis() - 1000;
    int maxCacheResultSize = 10 * 1024;
    ExecutorService rpcExecutor = Executors.newFixedThreadPool(4);
    SegmentQueryResult.Builder builder = new Builder(8, maxCacheResultSize);
    mockSendRPCTasks(rpcExecutor, 8, builder, 1024);
    CubeSegmentStatistics statistics = new CubeSegmentStatistics();
    statistics.setWrapper("cube1", "20171001000000-20171010000000", 3, 7, 1);
    builder.setCubeSegmentStatistics(statistics);
    SegmentQueryResult segmentQueryResult = builder.build();

    CubeSegmentStatistics desStatistics = SerializationUtils.deserialize(segmentQueryResult
            .getCubeSegmentStatisticsBytes());
    assertEquals("cube1", desStatistics.getCubeName());
}
 
Example 2
Source File: AttributeReleasePolicyTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyServiceAttributeFilterAllowedAttributes() {
    final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
    policy.setAllowedAttributes(Arrays.asList("attr1", "attr3"));
    final Principal p = mock(Principal.class);
    
    final Map<String, Object> map = new HashMap<>();
    map.put("attr1", "value1");
    map.put("attr2", "value2");
    map.put("attr3", Arrays.asList("v3", "v4"));
    
    when(p.getAttributes()).thenReturn(map);
    when(p.getId()).thenReturn("principalId");
    
    final Map<String, Object> attr = policy.getAttributes(p);
    assertEquals(attr.size(), 2);
    assertTrue(attr.containsKey("attr1"));
    assertTrue(attr.containsKey("attr3"));
    
    final byte[] data = SerializationUtils.serialize(policy);
    final ReturnAllowedAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
    assertNotNull(p2);
    assertEquals(p2.getAllowedAttributes(), policy.getAllowedAttributes());
}
 
Example 3
Source File: ShiroRedisSessionDao.java    From jee-universal-bms with Apache License 2.0 6 votes vote down vote up
@Override
protected Session doReadSession(Serializable sessionId) {
    logger.debug("=> read session with ID [{}]", sessionId);
    if(sessionId == null){
        logger.error("session id is null");
        return null;
    }

    // 例如 Redis 调用 flushdb 情况了所有的数据,读到的 session 就是空的
    byte[] value = redisManager.get(this.getByteKey(sessionId));
    if(value != null) {
        Session s = (Session) SerializationUtils.deserialize(value);
        // super.cache(s, s.getId());
        return s;
    }

    return null;
}
 
Example 4
Source File: SegmentQueryResultTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void resultValidateTest() {
    long segmentBuildTime = System.currentTimeMillis() - 1000;
    int maxCacheResultSize = 10 * 1024;
    ExecutorService rpcExecutor = Executors.newFixedThreadPool(4);
    SegmentQueryResult.Builder builder = new Builder(8, maxCacheResultSize);
    mockSendRPCTasks(rpcExecutor, 8, builder, 1024);
    CubeSegmentStatistics statistics = new CubeSegmentStatistics();
    statistics.setWrapper("cube1", "20171001000000-20171010000000", 3, 7, 1);
    builder.setCubeSegmentStatistics(statistics);
    SegmentQueryResult segmentQueryResult = builder.build();

    CubeSegmentStatistics desStatistics = SerializationUtils.deserialize(segmentQueryResult
            .getCubeSegmentStatisticsBytes());
    assertEquals("cube1", desStatistics.getCubeName());
}
 
Example 5
Source File: ModelSerializerTest.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaSerde_2() throws Exception {
    int nIn = 5;
    int nOut = 6;

    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(12345).l1(0.01)
            .list()
            .layer(0, new OutputLayer.Builder().nIn(nIn).nOut(nOut).activation(Activation.SOFTMAX).build())
            .build();

    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();

    DataSet dataSet = trivialDataSet();
    NormalizerStandardize norm = new NormalizerStandardize();
    norm.fit(dataSet);

    val b = SerializationUtils.serialize(net);

    MultiLayerNetwork restored = SerializationUtils.deserialize(b);

    assertEquals(net, restored);
}
 
Example 6
Source File: AttributeReleasePolicyTests.java    From springboot-shiro-cas-mybatis with MIT License 6 votes vote down vote up
@Test
public void verifyServiceAttributeFilterAllAttributes() {
    final ReturnAllAttributeReleasePolicy policy = new ReturnAllAttributeReleasePolicy();
    final Principal p = mock(Principal.class);

    final Map<String, Object> map = new HashMap<>();
    map.put("attr1", "value1");
    map.put("attr2", "value2");
    map.put("attr3", Arrays.asList("v3", "v4"));

    when(p.getAttributes()).thenReturn(map);
    when(p.getId()).thenReturn("principalId");

    final Map<String, Object> attr = policy.getAttributes(p);
    assertEquals(attr.size(), map.size());

    final byte[] data = SerializationUtils.serialize(policy);
    final ReturnAllAttributeReleasePolicy p2 = SerializationUtils.deserialize(data);
    assertNotNull(p2);
}
 
Example 7
Source File: JdkMessageDeserializer.java    From azeroth with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(String topic, byte[] data) {
    if (data == null)
        return null;
    else
        return SerializationUtils.deserialize(data);
}
 
Example 8
Source File: JoinOperation.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public SparkExpressionNode getSparkJoinPredicate() {
   	    if (sparkJoinPredicate != null)
   	        return sparkJoinPredicate;
   	    else {
   	    	if (hasSparkJoinPredicate())
	    sparkJoinPredicate =
	       (SparkExpressionNode) SerializationUtils.
	                          deserialize(Base64.decodeBase64(sparkExpressionTreeAsString));
	return sparkJoinPredicate;
    }
}
 
Example 9
Source File: BlockManagerWorker.java    From nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Respond to a block request by another executor.
 * <p>
 * This method is executed by {edu.snu.nemo.runtime.executor.data.blocktransfer.BlockTransport} thread. \
 * Never execute a blocking call in this method!
 *
 * @param outputContext {@link ByteOutputContext}
 * @throws InvalidProtocolBufferException from errors during parsing context descriptor
 */
public void onOutputContext(final ByteOutputContext outputContext) throws InvalidProtocolBufferException {
  final ByteTransferContextDescriptor descriptor = ByteTransferContextDescriptor.PARSER
      .parseFrom(outputContext.getContextDescriptor());
  final DataStoreProperty.Value blockStore = convertBlockStore(descriptor.getBlockStore());
  final String blockId = descriptor.getBlockId();
  final KeyRange keyRange = SerializationUtils.deserialize(descriptor.getKeyRange().toByteArray());

  backgroundExecutorService.submit(new Runnable() {
    @Override
    public void run() {
      try {
        if (DataStoreProperty.Value.LocalFileStore.equals(blockStore)
            || DataStoreProperty.Value.GlusterFileStore.equals(blockStore)) {
          final FileStore fileStore = (FileStore) getBlockStore(blockStore);
          for (final FileArea fileArea : fileStore.getFileAreas(blockId, keyRange)) {
            outputContext.newOutputStream().writeFileArea(fileArea).close();
          }
        } else {
          final Optional<Iterable<SerializedPartition>> optionalResult = getBlockStore(blockStore)
              .getSerializedPartitions(blockId, keyRange);
          for (final SerializedPartition partition : optionalResult.get()) {
            outputContext.newOutputStream().writeSerializedPartition(partition).close();
          }
        }
        handleUsedData(blockStore, blockId);
        outputContext.close();
      } catch (final IOException | BlockFetchException e) {
        LOG.error("Closing a block request exceptionally", e);
        outputContext.onChannelError(e);
      }
    }
  });
}
 
Example 10
Source File: RemoteFileMetadata.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Opens a existing block metadata in file.
 *
 * @param metaFilePath the path of the file to write metadata.
 * @param <T>          the key type of the block's partitions.
 * @return the created block metadata.
 * @throws IOException if fail to open.
 */
public static <T extends Serializable> RemoteFileMetadata<T> open(final String metaFilePath) throws IOException {
  if (!new File(metaFilePath).isFile()) {
    throw new IOException("File " + metaFilePath + " does not exist!");
  }
  final List<PartitionMetadata<T>> partitionMetadataList = new ArrayList<>();
  try (
    FileInputStream metafileInputStream = new FileInputStream(metaFilePath);
    DataInputStream dataInputStream = new DataInputStream(metafileInputStream)
  ) {
    while (dataInputStream.available() > 0) {
      final int keyLength = dataInputStream.readInt();
      final byte[] desKey = new byte[keyLength];
      if (keyLength != dataInputStream.read(desKey)) {
        throw new IOException("Invalid key length!");
      }

      final PartitionMetadata<T> partitionMetadata = new PartitionMetadata<>(
        SerializationUtils.deserialize(desKey),
        dataInputStream.readInt(),
        dataInputStream.readLong()
      );
      partitionMetadataList.add(partitionMetadata);
    }
  }
  return new RemoteFileMetadata<>(metaFilePath, partitionMetadataList);
}
 
Example 11
Source File: FastDatePrinterTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testLang303() {
    Calendar cal = Calendar.getInstance();
    cal.set(2004, 11, 31);

    DatePrinter format = getInstance(YYYY_MM_DD);
    String output = format.format(cal);

    format = SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) format));
    assertEquals(output, format.format(cal));
}
 
Example 12
Source File: TransactionCommitRequestTest.java    From uphold-sdk-android with MIT License 5 votes vote down vote up
@Test
public void shouldBeSerializableTransactionCommitRequest() {
    TransactionCommitRequest transactionCommitRequest = new TransactionCommitRequest("foobar");
    byte[] serializedTransactionCommitRequestTest = SerializationUtils.serialize(transactionCommitRequest);
    TransactionCommitRequest deserializedTransactionCommitRequestTest = SerializationUtils.deserialize(serializedTransactionCommitRequestTest);

    Assert.assertEquals(transactionCommitRequest.getMessage(), deserializedTransactionCommitRequestTest.getMessage());
}
 
Example 13
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandleDynamicJavascriptSerialization() throws Exception {

    JsFunctionRegistry jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
            (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);

    ServiceProvider sp1 = getTestServiceProvider("js-sp-dynamic-1.xml");

    AuthenticationContext context = getAuthenticationContext(sp1);

    SequenceConfig sequenceConfig = configurationLoader
            .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1);
    context.setSequenceConfig(sequenceConfig);

    byte[] serialized = SerializationUtils.serialize(context);

    AuthenticationContext deseralizedContext = (AuthenticationContext) SerializationUtils.deserialize(serialized);
    assertNotNull(deseralizedContext);

    HttpServletRequest req = mock(HttpServletRequest.class);
    addMockAttributes(req);

    HttpServletResponse resp = mock(HttpServletResponse.class);

    UserCoreUtil.setDomainInThreadLocal("test_domain");

    graphBasedSequenceHandler.handle(req, resp, deseralizedContext);

    List<AuthHistory> authHistories = deseralizedContext.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals(3, authHistories.size());
    assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicMockAuthenticator");
    assertEquals(authHistories.get(1).getAuthenticatorName(), "HwkMockAuthenticator");
    assertEquals(authHistories.get(2).getAuthenticatorName(), "FptMockAuthenticator");
}
 
Example 14
Source File: JavaObjectSerializer.java    From eagle with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(DataInput dataInput) throws IOException {
    int len = dataInput.readInt();
    byte[] bytes = new byte[len];
    dataInput.readFully(bytes);
    return SerializationUtils.deserialize(bytes);
}
 
Example 15
Source File: FastDateParserTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testLang303() throws ParseException {
    DateParser parser = getInstance(YMD_SLASH);
    Calendar cal = Calendar.getInstance();
    cal.set(2004, 11, 31);

    Date date = parser.parse("2004/11/31");

    parser = SerializationUtils.deserialize(SerializationUtils.serialize((Serializable) parser));
    assertEquals(date, parser.parse("2004/11/31"));
}
 
Example 16
Source File: ReserveTest.java    From uphold-sdk-android with MIT License 5 votes vote down vote up
@Test
public void shouldBeSerializable() {
    Reserve reserve = new Reserve();

    byte[] serializedReserve = SerializationUtils.serialize(reserve);
    Reserve deserializedReserve = SerializationUtils.deserialize(serializedReserve);

    Assert.assertTrue(reserve.getClass().equals(deserializedReserve.getClass()));
}
 
Example 17
Source File: MemcachedCacheManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
//TODO implementation here doesn't guarantee the atomicity.
//Without atomicity, this method should not be invoked
public ValueWrapper putIfAbsent(Object key, Object value) {
    byte[] existing = memcachedCache.get(key);
    if (existing == null) {
        memcachedCache.put(key, value);
        return null;
    } else {
        return new SimpleValueWrapper(SerializationUtils.deserialize(existing));
    }
}
 
Example 18
Source File: UpdateTableWriterBuilder.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static UpdateTableWriterBuilder getUpdateTableWriterBuilderFromBase64String(String base64String) throws IOException {
    if (base64String == null)
        throw new IOException("tableScanner base64 String is null");
    return (UpdateTableWriterBuilder) SerializationUtils.deserialize(Base64.decodeBase64(base64String));
}
 
Example 19
Source File: TaskMetric.java    From incubator-nemo with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean processMetricMessage(final String metricField, final byte[] metricValue) {
  LOG.debug("metric {} has just arrived!", metricField);
  switch (metricField) {
    case "taskDuration":
      setTaskDuration(SerializationUtils.deserialize(metricValue));
      break;
    case "schedulingOverhead":
      setSchedulingOverhead(SerializationUtils.deserialize(metricValue));
      break;
    case "serializedReadBytes":
      setSerializedReadBytes(SerializationUtils.deserialize(metricValue));
      break;
    case "encodedReadBytes":
      setEncodedReadBytes(SerializationUtils.deserialize(metricValue));
      break;
    case "boundedSourceReadTime":
      setBoundedSourceReadTime(SerializationUtils.deserialize(metricValue));
      break;
    case "taskOutputBytes":
      setTaskOutputBytes(SerializationUtils.deserialize(metricValue));
      break;
    case "taskDeserializationTime":
      setTaskDeserializationTime(SerializationUtils.deserialize(metricValue));
      break;
    case "stateTransitionEvent":
      final StateTransitionEvent<TaskState.State> newStateTransitionEvent =
        SerializationUtils.deserialize(metricValue);
      addEvent(newStateTransitionEvent);
      break;
    case "scheduleAttempt":
      setScheduleAttempt(SerializationUtils.deserialize(metricValue));
      break;
    case "containerId":
      setContainerId(SerializationUtils.deserialize(metricValue));
      break;
    case "taskCPUTime":
      setTaskCPUTime(SerializationUtils.deserialize(metricValue));
      break;
    case "taskSerializationTime":
      setTaskSerializationTime(SerializationUtils.deserialize(metricValue));
      break;
    case "peakExecutionMemory":
      setPeakExecutionMemory(SerializationUtils.deserialize(metricValue));
      break;
    case "taskSizeRatio":
      setTaskSizeRatio(SerializationUtils.deserialize(metricValue));
      break;
    case "shuffleReadBytes":
      setShuffleReadBytes(SerializationUtils.deserialize(metricValue));
      break;
    case "shuffleReadTime":
      setShuffleReadTime(SerializationUtils.deserialize(metricValue));
      break;
    case "shuffleWriteBytes":
      setShuffleWriteBytes(SerializationUtils.deserialize(metricValue));
      break;
    case "shuffleWriteTime":
      setShuffleWriteTime(SerializationUtils.deserialize(metricValue));
      break;
    default:
      LOG.warn("metricField {} is not supported.", metricField);
      return false;
  }
  return true;
}
 
Example 20
Source File: FileTypeTest.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
private void test(final FileType expected) {
    final byte[] serialized = SerializationUtils.serialize(expected);
    final FileType actualFileType = (FileType) SerializationUtils.deserialize(serialized);
    assertEquals(expected, actualFileType);
}