Code example for ByteBuffer

Methods: getLong, remaining, slice

0
 
    JdbcUUID() {} 
 
    public UUID compose(ByteBuffer bytes)
    { 
        bytes = bytes.slice();
        if (bytes.remaining() < 16)
            return new UUID(0, 0);
        return new UUID(bytes.getLong(), bytes.getLong());
    } 
 
    public String getString(ByteBuffer bytes)
    { 
        if (bytes.remaining() == 0)
        { 
            return ""; 
        } 
        if (bytes.remaining() != 16)
        { 
            throw new MarshalException("UUIDs must be exactly 16 bytes"); 
        } 
 
        return compose(bytes).toString();