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

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

Introduction

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

Prototype

@Override
public byte[] getBytes() 

Source Link

Document

Get the data backing the BytesWritable.

Usage

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

License:Apache License

/** Get the type code embedded in the first byte. */
public static RType getType(TypedBytesWritable writable) {
    byte[] bytes = writable.getBytes();
    if (bytes == null || bytes.length == 0) {
        return null;
    }/*from   ww  w.  j  a  va2  s  .  c  o  m*/
    RType type = RType.valueOf((int) bytes[0] & 0xff);
    return type;
}

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

License:Apache License

public static boolean isValid(TypedBytesWritable writable) {
    try {//from   w w  w . jav  a 2  s  .co 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());
}