当前位置: 首页>>代码示例>>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;未经允许,请勿转载。