public static CommitLogDescriptor readHeader(DataInput input, EncryptionContext encryptionContext) throws IOException { CRC32 checkcrc = new CRC32(); int version = input.readInt(); updateChecksumInt(checkcrc, version); long id = input.readLong(); updateChecksumInt(checkcrc, (int) (id & 0xFFFFFFFFL)); updateChecksumInt(checkcrc, (int) (id >>> 32)); int parametersLength = 0; if (version >= VERSION_22) { parametersLength = input.readShort() & 0xFFFF; updateChecksumInt(checkcrc, parametersLength); } // This should always succeed as parametersLength cannot be too long even for a // corrupt segment file. byte[] parametersBytes = new byte[parametersLength]; input.readFully(parametersBytes); checkcrc.update(parametersBytes, 0, parametersBytes.length); int crc = input.readInt(); if (crc == (int) checkcrc.getValue()) { Map<?, ?> map = (Map<?, ?>) JSONValue.parse(new String(parametersBytes, StandardCharsets.UTF_8)); return new CommitLogDescriptor(version, id, parseCompression(map), EncryptionContext.createFromMap(map, encryptionContext)); } return null; }
public static CommitLogDescriptor readHeader(DataInput input, EncryptionContext encryptionContext) throws IOException { CRC32 checkcrc = new CRC32(); int version = input.readInt(); updateChecksumInt(checkcrc, version); long id = input.readLong(); updateChecksumInt(checkcrc, (int) (id & 0xFFFFFFFFL)); updateChecksumInt(checkcrc, (int) (id >>> 32)); int parametersLength = 0; if (version >= VERSION_22) { parametersLength = input.readShort() & 0xFFFF; updateChecksumInt(checkcrc, parametersLength); } // This should always succeed as parametersLength cannot be too long even for a // corrupt segment file. byte[] parametersBytes = new byte[parametersLength]; input.readFully(parametersBytes); checkcrc.update(parametersBytes, 0, parametersBytes.length); int crc = input.readInt(); if (crc == (int) checkcrc.getValue()) { Map<?, ?> map = (Map<?, ?>) JSONValue.parse(new String(parametersBytes, StandardCharsets.UTF_8)); return new CommitLogDescriptor(version, id, parseCompression(map), EncryptionContext.createFromMap(map, encryptionContext)); } return null; }
public static CommitLogDescriptor readHeader(DataInput input, EncryptionContext encryptionContext) throws IOException { CRC32 checkcrc = new CRC32(); int version = input.readInt(); updateChecksumInt(checkcrc, version); long id = input.readLong(); updateChecksumInt(checkcrc, (int) (id & 0xFFFFFFFFL)); updateChecksumInt(checkcrc, (int) (id >>> 32)); int parametersLength = 0; if (version >= VERSION_22) { parametersLength = input.readShort() & 0xFFFF; updateChecksumInt(checkcrc, parametersLength); } // This should always succeed as parametersLength cannot be too long even for a // corrupt segment file. byte[] parametersBytes = new byte[parametersLength]; input.readFully(parametersBytes); checkcrc.update(parametersBytes, 0, parametersBytes.length); int crc = input.readInt(); if (crc == (int) checkcrc.getValue()) { Map<?, ?> map = (Map<?, ?>) JSONValue.parse(new String(parametersBytes, StandardCharsets.UTF_8)); return new CommitLogDescriptor(version, id, parseCompression(map), EncryptionContext.createFromMap(map, encryptionContext)); } return null; }