本文整理匯總了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();
}
示例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();
}
}
示例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());
}
示例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());
}