Example usage for org.apache.hadoop.io.erasurecode.rawcoder RawErasureEncoder encode

List of usage examples for org.apache.hadoop.io.erasurecode.rawcoder RawErasureEncoder encode

Introduction

In this page you can find the example usage for org.apache.hadoop.io.erasurecode.rawcoder RawErasureEncoder encode.

Prototype

public void encode(ECChunk[] inputs, ECChunk[] outputs) throws IOException 

Source Link

Document

Encode with inputs and generates outputs.

Usage

From source file:com.mellanox.erasurecode.rawcoder.RawErasureCoderValidationTest.java

License:Apache License

/**
 * Performs benchmark.//  ww  w .ja  v  a  2s .  c o  m
 *
 * @param opType      The operation to perform. Can be encode or decode
 * @param coderIndex  An index into the coder array
 * @param numData     Number of data blocks
 * @param numCode     Number of code blocks
 * @param chunkSizeB Chunk size in B
 * @param fileReader input file for encode operation
 * @throws IOException
 */
public static void performEncode(RawErasureEncoder encoder, RandomAccessFile fileReader, String inputFile)
        throws IOException {
    boolean isDirect = (Boolean) encoder.getCoderOption(CoderOption.PREFER_DIRECT_BUFFER);
    ByteBuffer[] inputs = allocateBuffers(isDirect, numData);
    ByteBuffer[] outputs = allocateBuffers(isDirect, numCode);
    FileChannel inChannel = fileReader.getChannel();
    FileOutputStream fileOutputStream = new FileOutputStream(
            new File(inputFile + "." + coderIndex + ".encode.code"));
    FileChannel outChannel = fileOutputStream.getChannel();

    // read input file
    while (inChannel.read(inputs) > 0) {

        // memset unfull buffers and reset all input buffers
        resetBuffers(inputs, chunkSizeB);

        // encode
        encoder.encode(inputs, outputs);

        // reset positions
        resetBuffers(inputs);

        resetBuffers(outputs);

        // write to file
        outChannel.write(outputs);

        // reset posion
        resetBuffers(outputs);
    }

    encoder.release();
    fileReader.close();
    fileOutputStream.close();
}