Example usage for java.io ObjectStreamConstants STREAM_MAGIC

List of usage examples for java.io ObjectStreamConstants STREAM_MAGIC

Introduction

In this page you can find the example usage for java.io ObjectStreamConstants STREAM_MAGIC.

Prototype

short STREAM_MAGIC

To view the source code for java.io ObjectStreamConstants STREAM_MAGIC.

Click Source Link

Document

Magic number that is written to the stream header.

Usage

From source file:org.mule.module.redis.RedisUtils.java

public static Serializable fromBytes(final byte[] bytes) {
    if ((bytes == null) || (bytes.length == 0)) {
        return null;
    }//from  w w  w. java2s.  com

    if ((bytes[0] == (byte) ((ObjectStreamConstants.STREAM_MAGIC >>> 8) & 0xFF))) {
        final Object deserialized = SerializationUtils.deserialize(bytes);
        if (deserialized instanceof Serializable) {
            return (Serializable) deserialized;
        } else {
            return bytes;
        }
    } else {
        return SafeEncoder.encode(bytes);
    }
}