public byte[] serialize(String topic, Long data) { if (data == null) return null; return new byte[] { (byte) (data >>> 56), (byte) (data >>> 48), (byte) (data >>> 40), (byte) (data >>> 32), (byte) (data >>> 24), (byte) (data >>> 16), (byte) (data >>> 8), data.byteValue() }; }
public Byte toByte(Long self) { return self.byteValue(); } }
@Override public byte[] encode(Long data) { if (null == data) { return null; } else { return new byte[] { (byte) (data >>> 56), (byte) (data >>> 48), (byte) (data >>> 40), (byte) (data >>> 32), (byte) (data >>> 24), (byte) (data >>> 16), (byte) (data >>> 8), data.byteValue() }; } }
@Override public byte getByte(String name) { return ((Long) decode(TINYINT, getFieldValue(name))).byteValue(); }
private List<Byte> createTinyIntValuesNoNull() { List<Byte> values = new ArrayList<>(); for (int i = 0; i < ROWS; ++i) { values.add(Long.valueOf(random.nextLong()).byteValue()); } return values; } }
@Override public DefaultParameterValue apply( String s ) { String value = s.trim(); if ( value.equalsIgnoreCase( "null" ) ) { return ntByteArray( null ); } else { List<Long> values = parseList( value, Long.class ); byte[] bytes = new byte[values.size()]; for ( int i = 0; i < bytes.length; i++ ) { bytes[i] = values.get( i ).byteValue(); } return ntByteArray( bytes ); } }
private List<Byte> createTinyIntValuesWithNull() { List<Byte> values = new ArrayList<>(); for (int i = 0; i < ROWS; ++i) { if (random.nextBoolean()) { values.add(Long.valueOf(random.nextLong()).byteValue()); } else { values.add(null); } } return values; } }
/** * Get the result of an Object path expression as a byte. * * @param path The Object path. * @return The object matching the Object path. A {@link java.lang.ClassCastException} will be thrown if the object * cannot be casted to the expected type. */ public byte getByte(String path) { //The type returned from Groovy depends on the input, so we need to handle different numerical types. Object value = get(path); if (value instanceof Byte) { return (Byte) value; } else if (value instanceof Long) { return ((Long) value).byteValue(); } else if (value instanceof Integer) { return ((Integer) value).byteValue(); } else { return ObjectConverter.convertObjectTo(value, Byte.class); } }
/** * Get the result of an Object path expression as a byte. * * @param path The Object path. * @return The object matching the Object path. A {@link java.lang.ClassCastException} will be thrown if the object * cannot be casted to the expected type. */ public byte getByte(String path) { //The type returned from Groovy depends on the input, so we need to handle different numerical types. Object value = get(path); if (value instanceof Byte) { return (Byte) value; } else if (value instanceof Long) { return ((Long) value).byteValue(); } else if (value instanceof Integer) { return ((Integer) value).byteValue(); } else { return ObjectConverter.convertObjectTo(value, Byte.class); } }
return (X) Byte.valueOf( value.byteValue() );
return ((Long) nativeValue).byteValue();
return (T) (Byte) l.byteValue(); } else if (targetClass == Short.class) { checkRange(l, Short.MIN_VALUE, Short.MAX_VALUE);
@Test public void testTinyInt() throws Exception { AccumuloRowSerializer serializer = serializerClass.getConstructor().newInstance(); Type type = TINYINT; Byte expected = 123; byte[] data = serializer.encode(type, expected); Byte actual = ((Long) serializer.decode(type, data)).byteValue(); assertEquals(actual, expected); deserializeData(serializer, data); actual = serializer.getByte(COLUMN_NAME); assertEquals(actual, expected); }
return ((Long) value).byteValue();
private byte[] encodeXid(XATransactionId xid, long seq, long priority) { byte[] xidVal = xid.getEncodedXidBytes(); // encode the update DataByteArrayOutputStream outputStream = xid.internalOutputStream(); outputStream.position(1); outputStream.writeLong(seq); outputStream.writeByte(Long.valueOf(priority).byteValue()); return xidVal; }
value = getInputRowMeta().getDate( r, index ); } else if ( clazz.equals( byte.class ) || clazz.equals( Byte.class ) ) { value = getInputRowMeta().getInteger( r, index ).byteValue(); } else if ( clazz.equals( Short.class ) || clazz.equals( short.class ) ) { value = getInputRowMeta().getInteger( r, index ).shortValue();
case ValueMetaInterface.TYPE_INTEGER: if ( length < 3 ) { values[i] = new Byte( valueMeta.getInteger( valueData ).byteValue() ); } else { if ( length < 5 ) {
/** * 字节数组和长整型的转换 */ public final static byte[] longToByte(long number) { long temp = number; byte[] b = new byte[8]; for (int i = 0; i < b.length; i++) { b[i] = new Long(temp & 0xff).byteValue(); // 将最低位保存在最低位 temp = temp >> 8; // 向右移8位 } return b; }
@SuppressWarnings("unchecked") @Override public <T> T convertTo(Serializable value, Class<T> toType) throws PropertyConversionException { if (value == null || Long.class == toType) { return (T) value; } Long v = (Long) value; if (toType == Integer.class) { return (T) new Integer(v.intValue()); } if (toType == String.class) { return (T) v.toString(); } if (toType == Double.class) { return (T) new Double(v.doubleValue()); } if (toType == Float.class) { return (T) new Float(v.floatValue()); } if (toType == Short.class) { return (T) new Short(v.shortValue()); } if (toType == Byte.class) { return (T) new Byte(v.byteValue()); } throw new PropertyConversionException(value.getClass(), toType); }