當前位置: 首頁>>代碼示例>>Java>>正文


Java IOUtil.serialize方法代碼示例

本文整理匯總了Java中com.neverwinterdp.util.IOUtil.serialize方法的典型用法代碼示例。如果您正苦於以下問題:Java IOUtil.serialize方法的具體用法?Java IOUtil.serialize怎麽用?Java IOUtil.serialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.neverwinterdp.util.IOUtil的用法示例。


在下文中一共展示了IOUtil.serialize方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSerializable

import com.neverwinterdp.util.IOUtil; //導入方法依賴的package包/類
@Test
public void testSerializable() throws Exception {
  QDigest qdigest = new QDigest(COMPRESSION_FACTOR);
  Random rand = new Random() ;
  for(int i = 0; i < 10000; i++) {
    qdigest.offer(rand.nextInt((i + 1))) ;
  }
  qdigest.optimize() ;
  byte[] data = IOUtil.serialize(qdigest) ;
  QDigest qdigestClone = (QDigest) IOUtil.deserialize(data) ;
  System.out.println("Serialization Size: " + data.length)  ;
  
  byte[] customSerializedData = QDigest.serialize(qdigest) ;
  System.out.println("Custom Serialization Size: " + customSerializedData.length)  ;
  
  QDigest customqDigestClone = QDigest.deserialize(customSerializedData) ;
  assertEquals(qdigest.toString(), customqDigestClone.toString()) ;
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:19,代碼來源:QDigestUnitTest.java

示例2: testPerformance

import com.neverwinterdp.util.IOUtil; //導入方法依賴的package包/類
@Test
public void testPerformance() throws Exception {
  MetricRegistry mRegistry = new MetricRegistry() ;
  WirePayload payload = createWirePayload() ;
  System.out.println("ProtoBuf Size:   " + payload.toByteArray().length);
  System.out.println("Serializable Size: " + IOUtil.serialize(payload).length);
  for(int i = 0; i < 1000000; i++) {
    Timer.Context protoBufSerCtx = mRegistry.timer("protobuf", "serialize").time() ;
    byte[] protobufData = payload.toByteArray() ;
    protoBufSerCtx .close();
    
    Timer.Context protobufDeserCtx = mRegistry.timer("protobuf", "deserialize").time() ;
    WirePayload deserPayload = WirePayload.parseFrom(protobufData) ;
    protobufDeserCtx.close();
    
    Timer.Context javaSerCtx = mRegistry.timer("java", "serialize").time() ;
    byte[] javaData = IOUtil.serialize(payload) ;
    javaSerCtx .close();
    
    Timer.Context javaDeserCtx = mRegistry.timer("java", "deserialize").time() ;
    deserPayload = (WirePayload)IOUtil.deserialize(javaData) ;
    javaDeserCtx.close();
  }
  new MetricPrinter().print(mRegistry) ;
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:26,代碼來源:SerializationPerformanceTest.java

示例3: testUpdate

import com.neverwinterdp.util.IOUtil; //導入方法依賴的package包/類
@Test
public void testUpdate() throws Exception {
  long start = System.currentTimeMillis() ;
  Timer timer = new Timer() ;
  com.codahale.metrics.Timer codahaleTimer = new com.codahale.metrics.Timer() ;
  Random rand = new Random() ;
  int LOOP = 1000;
  for(int i = 0; i < LOOP; i++) {
    long duration = rand.nextInt(100) ;
    if(i > LOOP/5) duration = rand.nextInt(20) ;
    Thread.sleep(duration);
    timer.update(duration, TimeUnit.MICROSECONDS);
    codahaleTimer.update(duration, TimeUnit.MICROSECONDS);
  }
  byte[] data = IOUtil.serialize(timer) ;
  Timer serialization = (Timer)IOUtil.deserialize(data) ;
  String json = JSONSerializer.INSTANCE.toString(timer) ;
  //Timer  jsonSerialization = JSONSerializer.INSTANCE.fromString(json, Timer.class) ;
  TimerPrinter printer = new TimerPrinter() ;
  printer.print("NeverwinterDP", timer);
  printer.print("Serialization", serialization);
  //printer.print("JSON Serialization", jsonSerialization);
  printer.print("Codahale", codahaleTimer);
  printer.flush(); 
  
  System.out.println("In " + (System.currentTimeMillis() - start) + "ms");
  System.out.println("Timer java serialization size: " + data.length);
  System.out.println("Timer json serialization size: " + json.getBytes().length);
  System.out.println(json);
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:31,代碼來源:TimerUnitTest.java

示例4: testBasic

import com.neverwinterdp.util.IOUtil; //導入方法依賴的package包/類
@Test
public void testBasic() throws Exception {
  Random rand = new Random() ;
  MetricRegistry registry = new MetricRegistry("basic") ;
  registry.getPluginManager().add(new MetricPluginDummy());
  Timer timer1 = registry.getTimer("timer") ;
  assertNotNull(timer1) ;
  Timer timer2 = registry.getTimer("timer") ;
  assertEquals(timer1, timer2) ;
  for(int i = 0; i < 10000; i++) {
    timer1.update(rand.nextInt(i + 1), TimeUnit.NANOSECONDS);
  }
  
  Counter counter1 = registry.getCounter("counter") ;
  for(int i = 0; i < 100; i++) {
    counter1.incr() ;
  }
  Counter counter2 = registry.getCounter("counter") ;
  assertNotNull(counter1) ;
  assertEquals(counter1, counter2) ;
  
  byte[] data = IOUtil.serialize(registry) ;
  MetricRegistry registryClone = (MetricRegistry)IOUtil.deserialize(data) ;
  Assert.assertEquals(0, registryClone.getPluginManager().size());
  System.out.println("MetricRegistry serialization size: " + data.length);

  System.out.println("Timer serialization size: " + IOUtil.serialize(timer1).length);
  System.out.println("QDigest serialization size: " + IOUtil.serialize(timer1.getHistogram().getQDigest()).length);
  MetricPrinter mPrinter = new MetricPrinter() ;
  mPrinter.print(registry);
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:32,代碼來源:MetricRegistryUnitTest.java

示例5: toBytes

import com.neverwinterdp.util.IOUtil; //導入方法依賴的package包/類
public byte[] toBytes(T object) {
  try {
    return IOUtil.serialize(object);
  } catch (IOException e) {
    throw new RuntimeException(e) ;
  }
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:8,代碼來源:JavaSerializer.java

示例6: toBinData

import com.neverwinterdp.util.IOUtil; //導入方法依賴的package包/類
@Override
protected byte[] toBinData(Message message) {
  try {
    return IOUtil.serialize(message) ;
  } catch (IOException e) {
    throw new RuntimeException(e) ;
  }
}
 
開發者ID:DemandCube,項目名稱:Sparkngin,代碼行數:9,代碼來源:JBinaryHttpSparknginClient.java


注:本文中的com.neverwinterdp.util.IOUtil.serialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。