public static void verifyBinaryVersionMarker ( Reader reader ) throws IonException { try { int pos = reader . position ( ) ; //reader.sync(); //reader.setPosition(0); byte [ ] bvm = new byte [ BINARY_VERSION_MARKER_SIZE ] ; int len = readFully ( reader , bvm ) ; if ( len < BINARY_VERSION_MARKER_SIZE ) { String message = "Binary data is too short: at least " + BINARY_VERSION_MARKER_SIZE + " bytes are required, but only " + len + " were found." ; throw new IonException ( message ) ; } if ( ! isIonBinary ( bvm ) ) { StringBuilder buf = new StringBuilder ( ) ; buf . append ( "Binary data has unrecognized header" ) ; for ( int i = 0 ; i < bvm . length ; i ++ ) { int b = bvm [ i ] & 0xFF ; buf . append ( " 0x" ) ; buf . append ( Integer . toHexString ( b ) . toUpperCase ( ) ) ; } throw new IonException ( buf . toString ( ) ) ; } //reader.setPosition(0); // cas 19 apr 2008 reader . setPosition ( pos ) ; // cas 5 may 2009 :) } catch ( IOException e ) { throw new IonException ( e ) ; } }
Verifies that a reader starts with a valid Ion cookie throwing an exception if it does not .