private Header parseHeader ( InputStream stream ) throws IOException , ClassNotFoundException { DataInputStream dis = new DataInputStream ( stream ) ; // Check if the stream starts with the expected header String header = dis . readUTF ( ) ; if ( ! header . equals ( HEADER ) ) { throw new IllegalArgumentException ( "Could not restore normalizer: invalid header. If this normalizer was saved with a opType-specific " + "strategy like StandardizeSerializerStrategy, use that class to restore it as well." ) ; } // The next byte is an integer indicating the version int version = dis . readInt ( ) ; // Right now, we only support version 1 if ( version != 1 ) { throw new IllegalArgumentException ( "Could not restore normalizer: invalid version (" + version + ")" ) ; } // The next value is a string indicating the normalizer opType NormalizerType type = NormalizerType . valueOf ( dis . readUTF ( ) ) ; if ( type . equals ( NormalizerType . CUSTOM ) ) { // For custom serializers, the next value is a string with the class opName String strategyClassName = dis . readUTF ( ) ; //noinspection unchecked return new Header ( type , ( Class < ? extends NormalizerSerializerStrategy > ) Class . forName ( strategyClassName ) ) ; } else { return new Header ( type , null ) ; } }
Parse the data header