Example usage for org.apache.hadoop.typedbytes TypedBytesInput readType

List of usage examples for org.apache.hadoop.typedbytes TypedBytesInput readType

Introduction

In this page you can find the example usage for org.apache.hadoop.typedbytes TypedBytesInput readType.

Prototype

public Type readType() throws IOException 

Source Link

Document

Reads a type byte and returns the corresponding Type .

Usage

From source file:fm.last.pigtail.storage.TypedBytesSequenceFileLoader.java

License:Apache License

@Override
public String bytesToCharArray(byte[] b) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(bais);
    TypedBytesInput tbin = TypedBytesInput.get(dis);
    if (tbin.readType() != org.apache.hadoop.typedbytes.Type.STRING) {
        throw new FrontendException("Type code does not correspond to string.");
    }//from   www .  j a  va  2  s.  c  o  m
    return tbin.readString();
}

From source file:fm.last.pigtail.storage.TypedBytesSequenceFileLoader.java

License:Apache License

@Override
public Double bytesToDouble(byte[] b) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(bais);
    TypedBytesInput tbin = TypedBytesInput.get(dis);
    if (tbin.readType() != org.apache.hadoop.typedbytes.Type.DOUBLE) {
        throw new FrontendException("Type code does not correspond to double.");
    }/*from  ww  w  .jav a2s.c  o  m*/
    return tbin.readDouble();
}

From source file:fm.last.pigtail.storage.TypedBytesSequenceFileLoader.java

License:Apache License

@Override
public Float bytesToFloat(byte[] b) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(bais);
    TypedBytesInput tbin = TypedBytesInput.get(dis);
    if (tbin.readType() != org.apache.hadoop.typedbytes.Type.FLOAT) {
        throw new FrontendException("Type code does not correspond to float.");
    }//w w  w  .  j  av  a  2  s  .co  m
    return tbin.readFloat();
}

From source file:fm.last.pigtail.storage.TypedBytesSequenceFileLoader.java

License:Apache License

@Override
public Integer bytesToInteger(byte[] b) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(bais);
    TypedBytesInput tbin = TypedBytesInput.get(dis);
    if (tbin.readType() != org.apache.hadoop.typedbytes.Type.INT) {
        throw new FrontendException("Type code does not correspond to int.");
    }//from ww  w  .  j av a2  s.  co m
    return tbin.readInt();
}

From source file:fm.last.pigtail.storage.TypedBytesSequenceFileLoader.java

License:Apache License

@Override
public Long bytesToLong(byte[] b) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(bais);
    TypedBytesInput tbin = TypedBytesInput.get(dis);
    if (tbin.readType() != org.apache.hadoop.typedbytes.Type.LONG) {
        throw new FrontendException("Type code does not correspond to long.");
    }/*from ww w. j  a  v a2  s . c o  m*/
    return tbin.readLong();
}

From source file:fm.last.pigtail.storage.TypedBytesSequenceFileLoader.java

License:Apache License

@Override
public Map<String, Object> bytesToMap(byte[] b) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(bais);
    TypedBytesInput tbin = TypedBytesInput.get(dis);
    if (tbin.readType() != org.apache.hadoop.typedbytes.Type.MAP) {
        throw new FrontendException("Type code does not correspond to map.");
    }/*from  w  w w  .j  a  va  2s .c  o m*/
    Map<String, Object> result = new HashMap<String, Object>();
    for (Object item : tbin.readMap().entrySet()) {
        Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) item;
        result.put(entry.getKey().toString(), entry.getValue());
    }
    return result;
}

From source file:fm.last.pigtail.storage.TypedBytesSequenceFileLoader.java

License:Apache License

@Override
public Tuple bytesToTuple(byte[] b) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataInputStream dis = new DataInputStream(bais);
    TypedBytesInput tbin = TypedBytesInput.get(dis);
    if (tbin.readType() != org.apache.hadoop.typedbytes.Type.VECTOR) {
        throw new FrontendException("Type code does not correspond to vector.");
    }//from  ww w  .java 2  s .co  m
    Tuple result = tupleFactory.newTuple();
    for (Object item : tbin.readVector()) {
        result.append(item);
    }
    return result;
}