Java Code Examples for org.apache.hadoop.hbase.util.Bytes#SIZEOF_FLOAT

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#SIZEOF_FLOAT . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: canal-1.1.3   File: PhTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static int encodeFloat(float v, byte[] b, int o) {
    checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
    int i = Float.floatToIntBits(v);
    i = (i ^ ((i >> Integer.SIZE - 1) | Integer.MIN_VALUE)) + 1;
    Bytes.putInt(b, o, i);
    return Bytes.SIZEOF_FLOAT;
}
 
Example 2
Source Project: canal-1.1.3   File: PhTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static int encodeUnsignedFloat(float v, byte[] b, int o) {
    checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
    if (v < 0) {
        throw new RuntimeException();
    }
    Bytes.putFloat(b, o, v);
    return Bytes.SIZEOF_FLOAT;
}
 
Example 3
Source Project: phoenix   File: PUnsignedFloat.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int encodeFloat(float v, byte[] b, int o) {
  checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
  if (v < 0) {
    throw newIllegalDataException();
  }
  Bytes.putFloat(b, o, v);
  return Bytes.SIZEOF_FLOAT;
}
 
Example 4
Source Project: canal   File: PhTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static int encodeUnsignedFloat(float v, byte[] b, int o) {
    checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
    if (v < 0) {
        throw new RuntimeException();
    }
    Bytes.putFloat(b, o, v);
    return Bytes.SIZEOF_FLOAT;
}
 
Example 5
Source Project: canal   File: PhTypeUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static int encodeFloat(float v, byte[] b, int o) {
    checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
    int i = Float.floatToIntBits(v);
    i = (i ^ ((i >> Integer.SIZE - 1) | Integer.MIN_VALUE)) + 1;
    Bytes.putInt(b, o, i);
    return Bytes.SIZEOF_FLOAT;
}
 
Example 6
Source Project: spork   File: HBaseBinaryConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Float bytesToFloat(byte[] b) throws IOException {
    if (Bytes.SIZEOF_FLOAT > b.length){
        return Bytes.toFloat(Bytes.padHead(b, Bytes.SIZEOF_FLOAT - b.length));
    } else {
        return Bytes.toFloat(Bytes.head(b, Bytes.SIZEOF_FLOAT));
    }
}
 
Example 7
Source Project: phoenix   File: PUnsignedFloat.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int encodeFloat(float v, byte[] b, int o) {
  checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
  if (v < 0) {
    throw newIllegalDataException();
  }
  Bytes.putFloat(b, o, v);
  return Bytes.SIZEOF_FLOAT;
}
 
Example 8
Source Project: phoenix   File: PFloat.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int encodeFloat(float v, byte[] b, int o) {
  checkForSufficientLength(b, o, Bytes.SIZEOF_FLOAT);
  int i = Float.floatToIntBits(v);
  i = (i ^ ((i >> Integer.SIZE - 1) | Integer.MIN_VALUE)) + 1;
  Bytes.putInt(b, o, i);
  return Bytes.SIZEOF_FLOAT;
}
 
Example 9
Source Project: canal-1.1.3   File: PhTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static byte[] toBytes(Object v, PhType phType) {
    if (v == null) return null;
    byte[] b = null;
    if (phType == PhType.DEFAULT) {
        PhType phType1 = PhType.getType(v.getClass());
        if (phType1 != null && phType1 != PhType.DEFAULT) {
            toBytes(v, phType1);
        }
    } else if (phType == PhType.INTEGER) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_INT) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeUnsignedInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.BIGINT) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_LONG) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeUnsignedShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeUnsignedByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeUnsignedFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeUnsignedDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.BOOLEAN) {
        if ((Boolean) v) {
            b = new byte[] { 1 };
        } else {
            b = new byte[] { 0 };
        }
    } else if (phType == PhType.TIME || phType == PhType.DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeDate(v, b, 0);
    } else if (phType == PhType.TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeTimestamp(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIME || phType == PhType.UNSIGNED_DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedDate(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeUnsignedTimestamp(v, b, 0);
    } else if (phType == PhType.VARBINARY) {
        b = (byte[]) v;
    } else if (phType == PhType.VARCHAR) {
        b = Bytes.toBytes(v.toString());
    } else if (phType == PhType.DECIMAL) {
        if (v instanceof BigDecimal) {
            b = encodeDecimal(v);
        } else if (v instanceof Number) {
            b = encodeDecimal(new BigDecimal(v.toString()));
        }
    }
    return b;
}
 
Example 10
Source Project: phoenix   File: PUnsignedFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_FLOAT;
}
 
Example 11
Source Project: phoenix   File: PUnsignedFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
  byte[] b = new byte[Bytes.SIZEOF_FLOAT];
  toBytes(object, b, 0);
  return b;
}
 
Example 12
Source Project: phoenix   File: PFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_FLOAT;
}
 
Example 13
Source Project: phoenix   File: PFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
  byte[] b = new byte[Bytes.SIZEOF_FLOAT];
  toBytes(object, b, 0);
  return b;
}
 
Example 14
Source Project: canal   File: PhTypeUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static byte[] toBytes(Object v, PhType phType) {
    if (v == null) return null;
    byte[] b = null;
    if (phType == PhType.DEFAULT) {
        PhType phType1 = PhType.getType(v.getClass());
        if (phType1 != null && phType1 != PhType.DEFAULT) {
            toBytes(v, phType1);
        }
    } else if (phType == PhType.INTEGER) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_INT) {
        b = new byte[Bytes.SIZEOF_INT];
        encodeUnsignedInt(((Number) v).intValue(), b, 0);
    } else if (phType == PhType.BIGINT) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_LONG) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedLong(((Number) v).longValue(), b, 0);
    } else if (phType == PhType.SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_SMALLINT) {
        b = new byte[Bytes.SIZEOF_SHORT];
        encodeUnsignedShort(((Number) v).shortValue(), b, 0);
    } else if (phType == PhType.TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_TINYINT) {
        b = new byte[Bytes.SIZEOF_BYTE];
        encodeUnsignedByte(((Number) v).byteValue(), b, 0);
    } else if (phType == PhType.FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_FLOAT) {
        b = new byte[Bytes.SIZEOF_FLOAT];
        encodeUnsignedFloat(((Number) v).floatValue(), b, 0);
    } else if (phType == PhType.DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.UNSIGNED_DOUBLE) {
        b = new byte[Bytes.SIZEOF_DOUBLE];
        encodeUnsignedDouble(((Number) v).doubleValue(), b, 0);
    } else if (phType == PhType.BOOLEAN) {
        if ((Boolean) v) {
            b = new byte[] { 1 };
        } else {
            b = new byte[] { 0 };
        }
    } else if (phType == PhType.TIME || phType == PhType.DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeDate(v, b, 0);
    } else if (phType == PhType.TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeTimestamp(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIME || phType == PhType.UNSIGNED_DATE) {
        b = new byte[Bytes.SIZEOF_LONG];
        encodeUnsignedDate(v, b, 0);
    } else if (phType == PhType.UNSIGNED_TIMESTAMP) {
        b = new byte[Bytes.SIZEOF_LONG + Bytes.SIZEOF_INT];
        encodeUnsignedTimestamp(v, b, 0);
    } else if (phType == PhType.VARBINARY) {
        b = (byte[]) v;
    } else if (phType == PhType.VARCHAR) {
        b = Bytes.toBytes(v.toString());
    } else if (phType == PhType.DECIMAL) {
        if (v instanceof BigDecimal) {
            b = encodeDecimal(v);
        } else if (v instanceof Number) {
            b = encodeDecimal(new BigDecimal(v.toString()));
        }
    }
    return b;
}
 
Example 15
Source Project: phoenix   File: PUnsignedFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_FLOAT;
}
 
Example 16
Source Project: phoenix   File: PUnsignedFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
  byte[] b = new byte[Bytes.SIZEOF_FLOAT];
  toBytes(object, b, 0);
  return b;
}
 
Example 17
Source Project: phoenix   File: PFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Integer getByteSize() {
  return Bytes.SIZEOF_FLOAT;
}
 
Example 18
Source Project: phoenix   File: PFloat.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public byte[] toBytes(Object object) {
  byte[] b = new byte[Bytes.SIZEOF_FLOAT];
  toBytes(object, b, 0);
  return b;
}
 
Example 19
public static Boolean decodeBoolFromNumber( byte[] rawEncoded ) {
  if ( rawEncoded.length == Bytes.SIZEOF_BYTE ) {
    byte val = rawEncoded[ 0 ];
    if ( val == 0 || val == 1 ) {
      return new Boolean( val == 1 );
    }
  }

  if ( rawEncoded.length == Bytes.SIZEOF_SHORT ) {
    short tempShort = Bytes.toShort( rawEncoded );

    if ( tempShort == 0 || tempShort == 1 ) {
      return new Boolean( tempShort == 1 );
    }
  }

  if ( rawEncoded.length == Bytes.SIZEOF_INT || rawEncoded.length == Bytes.SIZEOF_FLOAT ) {
    int tempInt = Bytes.toInt( rawEncoded );
    if ( tempInt == 1 || tempInt == 0 ) {
      return new Boolean( tempInt == 1 );
    }

    float tempFloat = Bytes.toFloat( rawEncoded );
    if ( tempFloat == 0.0f || tempFloat == 1.0f ) {
      return new Boolean( tempFloat == 1.0f );
    }
  }

  if ( rawEncoded.length == Bytes.SIZEOF_LONG || rawEncoded.length == Bytes.SIZEOF_DOUBLE ) {
    long tempLong = Bytes.toLong( rawEncoded );
    if ( tempLong == 0L || tempLong == 1L ) {
      return new Boolean( tempLong == 1L );
    }

    double tempDouble = Bytes.toDouble( rawEncoded );
    if ( tempDouble == 0.0 || tempDouble == 1.0 ) {
      return new Boolean( tempDouble == 1.0 );
    }
  }

  // not identifiable from a number
  return null;
}
 
Example 20
public int getSizeOfFloat() {
  return Bytes.SIZEOF_FLOAT;
}