Example usage for org.apache.hadoop.typedbytes TypedBytesWritable getLength

List of usage examples for org.apache.hadoop.typedbytes TypedBytesWritable getLength

Introduction

In this page you can find the example usage for org.apache.hadoop.typedbytes TypedBytesWritable getLength.

Prototype

@Override
public int getLength() 

Source Link

Document

Get the current size of the buffer.

Usage

From source file:com.jfolson.hive.serde.RType.java

License:Apache License

public static boolean isValid(TypedBytesWritable writable) {
    try {//from   w ww  . j ava2 s  . c  o  m
        byte[] bytes = writable.getBytes();
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes, 0, writable.getLength());
        RTypedBytesInput rtbi = RTypedBytesInput.get(new DataInputStream(bais));
        if (bytes == null || bytes.length <= 5) {
            return false;
        }
        RType rtype = rtbi.readType();
        if (rtype == null) {
            return false;
        }
        byte[] obj = rtbi.readRaw(rtype.code);
        if (obj == null) {
            return false;
        }
        int obj_length = obj.length;
        obj = rtbi.readRaw();
        if (obj != null) {
            return false;
        }
        return true;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}

From source file:com.jfolson.hive.serde.RTypedBytesOutput.java

License:Apache License

public void writeTypedBytes(TypedBytesWritable tb) throws IOException {
    //LOG.info("Writing as typedbytes bytes");
    writeRaw(new Buffer(tb.getBytes(), 0, tb.getLength()).get());
}