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


Java UnsafeByteArrayOutputStream類代碼示例

本文整理匯總了Java中org.apache.giraph.utils.UnsafeByteArrayOutputStream的典型用法代碼示例。如果您正苦於以下問題:Java UnsafeByteArrayOutputStream類的具體用法?Java UnsafeByteArrayOutputStream怎麽用?Java UnsafeByteArrayOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: writeC

import org.apache.giraph.utils.UnsafeByteArrayOutputStream; //導入依賴的package包/類
public void writeC(DataOutput out) throws IOException {
	UnsafeByteArrayOutputStream outStream = new UnsafeByteArrayOutputStream();
	outStream.writeInt(tables.entrySet().size());
	for (Map.Entry<String, Table> entry : tables.entrySet())
	{
		String tableName = entry.getKey();
		Table table = entry.getValue();
		outStream.writeUTF(tableName);
		table.write(outStream);
	}
	outStream.flush();
	//WritableUtils.writeCompressedByteArray(out, outStream.toByteArray());
	LZ4Factory factory = LZ4Factory.fastestInstance();
	LZ4Compressor compressor = factory.fastCompressor();
	byte[] outStreamByteArray = outStream.toByteArray();
	int decompressedLength = outStreamByteArray.length;
	int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
	byte[] compressed = new byte[maxCompressedLength];
	int compressedLength = compressor.compress(outStreamByteArray, 0, decompressedLength, compressed, 0, maxCompressedLength);
	out.writeInt(decompressedLength);
	out.writeInt(compressedLength);
	out.write(compressed, 0, compressedLength);
	outStream.close();
}
 
開發者ID:wmoustafa,項目名稱:granada,代碼行數:25,代碼來源:Database.java

示例2: createExtendedDataOutput

import org.apache.giraph.utils.UnsafeByteArrayOutputStream; //導入依賴的package包/類
/**
 * Create an extended data output (can be subclassed)
 *
 * @return ExtendedDataOutput object
 */
public ExtendedDataOutput createExtendedDataOutput() {
  if (useUnsafeSerialization) {
    return new UnsafeByteArrayOutputStream();
  } else {
    return new ExtendedByteArrayDataOutput();
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:13,代碼來源:ImmutableClassesGiraphConfiguration.java

示例3: testUnsafePartitionSerializationClass

import org.apache.giraph.utils.UnsafeByteArrayOutputStream; //導入依賴的package包/類
@Test
public void testUnsafePartitionSerializationClass() throws IOException {
  conf.setPartitionClass(ByteArrayPartition.class);
  Vertex<IntWritable, IntWritable, NullWritable> v1 =
      conf.createVertex();
  v1.initialize(new IntWritable(1), new IntWritable(1));
  Vertex<IntWritable, IntWritable, NullWritable> v2 = conf.createVertex();
  v2.initialize(new IntWritable(2), new IntWritable(2));
  Vertex<IntWritable, IntWritable, NullWritable> v3 = conf.createVertex();
  v3.initialize(new IntWritable(3), new IntWritable(3));
  Vertex<IntWritable, IntWritable, NullWritable> v4 = conf.createVertex();
  v4.initialize(new IntWritable(4), new IntWritable(4));
  Vertex<IntWritable, IntWritable, NullWritable> v5 = conf.createVertex();
  v5.initialize(new IntWritable(5), new IntWritable(5));
  Vertex<IntWritable, IntWritable, NullWritable> v6 = conf.createVertex();
  v6.initialize(new IntWritable(6), new IntWritable(6));
  Vertex<IntWritable, IntWritable, NullWritable> v7 = conf.createVertex();
  v7.initialize(new IntWritable(7), new IntWritable(7));

  Partition<IntWritable, IntWritable, NullWritable> partition =
      createPartition(conf, 3, v1, v2, v3, v4, v5, v6, v7);
  assertEquals(3, partition.getId());
  assertEquals(0, partition.getEdgeCount());
  assertEquals(7, partition.getVertexCount());
  UnsafeByteArrayOutputStream outputStream = new
      UnsafeByteArrayOutputStream();
  partition.write(outputStream);
  UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(
      outputStream.getByteArray(), 0, outputStream.getPos());
  Partition<IntWritable, IntWritable, NullWritable> deserializatedPartition =
      conf.createPartition(-1, context);
  deserializatedPartition.readFields(inputStream);

  assertEquals(3, deserializatedPartition.getId());
  assertEquals(0, deserializatedPartition.getEdgeCount());
  assertEquals(7, deserializatedPartition.getVertexCount());
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:38,代碼來源:TestPartitionStores.java

示例4: testUnsafePartitionSerializationClass

import org.apache.giraph.utils.UnsafeByteArrayOutputStream; //導入依賴的package包/類
@Test
public void testUnsafePartitionSerializationClass() throws IOException {
  conf.setPartitionClass(ByteArrayPartition.class);
  Vertex<IntWritable, IntWritable, NullWritable, IntWritable> v1 =
      conf.createVertex();
  v1.initialize(new IntWritable(1), new IntWritable(1));
  Vertex<IntWritable, IntWritable, NullWritable, IntWritable> v2 =
      conf.createVertex();
  v2.initialize(new IntWritable(2), new IntWritable(2));
  Vertex<IntWritable, IntWritable, NullWritable, IntWritable> v3 =
      conf.createVertex();
  v3.initialize(new IntWritable(3), new IntWritable(3));
  Vertex<IntWritable, IntWritable, NullWritable, IntWritable> v4 =
      conf.createVertex();
  v4.initialize(new IntWritable(4), new IntWritable(4));
  Vertex<IntWritable, IntWritable, NullWritable, IntWritable> v5 =
      conf.createVertex();
  v5.initialize(new IntWritable(5), new IntWritable(5));
  Vertex<IntWritable, IntWritable, NullWritable, IntWritable> v6 =
      conf.createVertex();
  v6.initialize(new IntWritable(6), new IntWritable(6));
  Vertex<IntWritable, IntWritable, NullWritable, IntWritable> v7 =
      conf.createVertex();
  v7.initialize(new IntWritable(7), new IntWritable(7));

  Partition<IntWritable, IntWritable, NullWritable,
      IntWritable> partition =
      createPartition(conf, 3, v1, v2, v3, v4, v5, v6, v7);
  assertEquals(3, partition.getId());
  assertEquals(0, partition.getEdgeCount());
  assertEquals(7, partition.getVertexCount());
  UnsafeByteArrayOutputStream outputStream = new
      UnsafeByteArrayOutputStream();
  partition.write(outputStream);
  UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(
      outputStream.getByteArray(), 0, outputStream.getPos());
  Partition<IntWritable, IntWritable, NullWritable,
      IntWritable> deserializatedPartition = conf.createPartition(-1,
      context);
  deserializatedPartition.readFields(inputStream);

  assertEquals(3, deserializatedPartition.getId());
  assertEquals(0, deserializatedPartition.getEdgeCount());
  assertEquals(7, deserializatedPartition.getVertexCount());
}
 
開發者ID:zfighter,項目名稱:giraph-research,代碼行數:46,代碼來源:TestPartitionStores.java


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