public boolean isValidSyntax()

in ldap/model/src/main/java/org/apache/directory/api/ldap/model/schema/syntaxCheckers/JpegSyntaxChecker.java [103:182]


    public boolean isValidSyntax( Object value )
    {
        if ( value == null )
        {
            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, "null" ) );
            }
            
            return false;
        }

        // The value must be a byte array
        if ( !( value instanceof byte[] ) )
        {
            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
            }
            
            return false;
        }

        byte[] bytes = ( byte[] ) value;

        // The header must be at least 11 bytes long
        if ( bytes.length < 11 )
        {
            if ( LOG.isDebugEnabled() )
            {
                LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
            }
            
            return false;
        }

        // SOI or APP0 or APP1 format
        if ( ( bytes[0] == ( byte ) 0x00FF )
            && ( bytes[1] == ( byte ) 0x00D8 )
            && ( bytes[2] == ( byte ) 0x00FF ) )
        {
            // JFIF format
            if ( ( bytes[3] == ( byte ) 0x00E0 )
                && ( bytes[6] == 'J' )
                && ( bytes[7] == 'F' )
                && ( bytes[8] == 'I' )
                && ( bytes[9] == 'F' )
                && ( bytes[10] == 0x00 ) )
            {
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
                }
                
                return true;
            }
        // EXIF Format
            else if ( ( bytes[3] == ( byte ) 0x00E1 ) 
                    && ( bytes[6] == 'E' )
                    && ( bytes[7] == 'x' )
                    && ( bytes[8] == 'i' )
                    && ( bytes[9] == 'f' )
                    && ( bytes[10] == 0x00 ) )
            {
                if ( LOG.isDebugEnabled() )
                {
                    LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, value ) );
                }

                return true;
            }
        }

        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, value ) );
        }
        
        return false;
    }