/*
(non-Javadoc)

@see com.impetus.kundera.property.PropertyAccessor#fromBytes(byte[])
13040
@Override
    public BigDecimal fromBytes(Class targetClass, byte[] bytes)
    {
        if (bytes == null)
        {
            return null;
        }
        int scale = (((bytes[0]) << 24) | ((bytes[1] & 0xff) << 16) | ((bytes[2] & 0xff) << 8) | ((bytes[3] & 0xff)));

        byte[] bibytes = Arrays.copyOfRange(bytes, 4, bytes.length);

        BigInteger bi = new BigInteger(bibytes);

        return new BigDecimal(bi, scale);
    }
184131
@Override
    public Object deserialize(byte[] bytes) throws IOException {
        KryoHolder kryoHolder = null;
        if (bytes == null) throw new RuntimeException("bytes can not be null");
        try {
            kryoHolder = KryoPoolImpl.getInstance().get();
            kryoHolder.input.setBuffer(bytes, 0, bytes.length);//call it ,and then use input object  ,discard any array
            return kryoHolder.kryo.readClassAndObject(kryoHolder.input);
        } catch (RuntimeException e) {
            throw new RuntimeException(e);
		} finally {
			if (kryoHolder != null) {
				KryoPoolImpl.getInstance().offer(kryoHolder);
			}
			// bytes = null; // for gc
		}
    }
1194084
@SuppressWarnings("PMD.AssignmentInOperand")
    private static byte[] asBytes(final InputStream input) throws IOException {
        input.reset();
        try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
            // @checkstyle MagicNumberCheck (1 line)
            final byte[] buffer = new byte[1024];
            int read;
            while ((read = input.read(buffer, 0, buffer.length)) != -1) {
                output.write(buffer, 0, read);
            }
            output.flush();
            return output.toByteArray();
        }
    }
1220145
@Override
    public UniversalIdIntQueueMessage fromBytes(byte[] data) {
        try {
            UniversalIdIntQueueMessage other = BaseUniversalQueueMessage.fromBytes(data,
                    UniversalIdIntQueueMessage.class);
            fromMap(other.toMap());
            return this;
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
1346238
@Deprecated
    public static byte[] encodeToBytes(byte[] bytes)
    {
        try {
            char[] chars = Base64.encode(bytes);
            String string = new String(chars);
            return string.getBytes(DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
716174
@Override
    public byte readByte(final boolean unsigned, final int size) throws IOException {
        return (byte) readInt(unsigned, requireValidSizeByte(unsigned, size));
    }
1225245
public static byte[] readBytes(InputStream is) throws IOException {
        if (is == null) {
            return null;
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        copyStream(is, baos);
        return baos.toByteArray();
    }
787755
@Override
	public ByteArray encodeAsByteArray() throws IOException {
		final int size = messages.size();
		if(size == 0) return ByteArray.EMPTY_BYTE_ARRAY;

		AoByteArrayOutputStream bout = new AoByteArrayOutputStream();
		try {
			try (DataOutputStream out = new DataOutputStream(bout)) {
				out.writeInt(size);
				int count = 0;
				for(Message message : messages) {
					count++;
					ByteArray byteArray = message.encodeAsByteArray();
					final int capacity = byteArray.size;
					out.writeByte(message.getMessageType().getTypeByte());
					out.writeInt(capacity);
					out.write(byteArray.array, 0, capacity);
				}
				if(count != size) throw new ConcurrentModificationException();
			}
		} finally {
			bout.close();
		}
		return new ByteArray(bout.getInternalByteArray(), bout.size());
	}
253987
public static byte[] inputStreamToBytes(InputStream in)
    {
        try
        {
            FastByteArrayOutputStream out = new FastByteArrayOutputStream(16384);
            transfer(in, out);
            return Arrays.copyOf(out.buffer, out.size);
        }
        catch (Exception e)
        {
            return null;
        }
    }
1000422
public static UTF8String fromBytes(byte[] bytes) {
    if (bytes != null) {
      return new UTF8String(bytes, BYTE_ARRAY_OFFSET, bytes.length);
    } else {
      return null;
    }
  }
844625
public static byte[] bytes(InputStream in) throws IOException {
        if(in == null)
            throw new IllegalArgumentException("input stream cannot be null");

        ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
        byte[] bytes = new byte[1024];

        for (int x = in.read(bytes); x != -1; x = in.read(bytes))
            bout.write(bytes, 0, x);

        return bout.toByteArray();
    }
1349315
@Override
    public byte[] toBytes(Object object) throws PropertyAccessException
    {
        return object != null ? fromLong(Double.doubleToRawLongBits((Double) object)) : null;
    }
222079
@Override
    public Character fromBytes(Class targetClass, byte[] data)
    {
        if (data == null || data.length != 2)
        {
            if (log.isWarnEnabled())
            {
                log.warn("Data length is not matching");
            }
            return 0x0;
        }
        return (char) ((0xff & data[0]) << 8 | (0xff & data[1]) << 0);
    }
60010
public JsonNode decode(byte[] bytes) throws Exception {
        JsonNode jsonNode = mapper.fromJson(bytes);
        return jsonNode;
    }
467781
@SuppressWarnings("unchecked")
    public BaseBo fromByteArray(byte[] data) {
        Map<String, Object> dataMap = null;
        try {
            dataMap = data != null ? SerializationUtils.fromByteArray(data, Map.class) : null;
        } catch (Exception e) {
            dataMap = null;
        }
        return fromMap(dataMap);
    }
761303
public T fromSmile(byte[] bytes)
            throws IllegalArgumentException
    {
        try {
            return mapper.readValue(bytes, javaType);
        }
        catch (IOException e) {
            throw new IllegalArgumentException(format("Invalid SMILE bytes for %s", javaType), e);
        }
    }
194714
public static Object fromBytes(byte[] b, Class<?> clazz)
    {

        if (clazz.isAssignableFrom(String.class))
        {
            return Bytes.toString(b);
        }
        else if (clazz.equals(int.class) || clazz.isAssignableFrom(Integer.class))
        {
            return Bytes.toInt(b);
        }
        else if (clazz.equals(long.class) || clazz.isAssignableFrom(Long.class))
        {
            return Bytes.toLong(b);
        }
        else if (clazz.equals(boolean.class) || clazz.isAssignableFrom(Boolean.class))
        {
            return Bytes.toBoolean(b);
        }
        else if (clazz.equals(double.class) || clazz.isAssignableFrom(Double.class))
        {
            return Bytes.toDouble(b);
        }
        else if (clazz.equals(float.class) || clazz.isAssignableFrom(Float.class))
        {
            return Bytes.toFloat(b);
        }
        else if (clazz.equals(short.class) || clazz.isAssignableFrom(Short.class))
        {
            return Bytes.toShort(b);
        }
        else if (clazz.equals(BigDecimal.class))
        {
            return Bytes.toBigDecimal(b);
        }
        else
        {
            return PropertyAccessorFactory.getPropertyAccessor(clazz).fromBytes(clazz, b);
        }
    }