yihua commented on code in PR #10241: URL: https://github.com/apache/hudi/pull/10241#discussion_r1421044291
########## hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlockReader.java: ########## @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.hudi.io.hfile; + +import org.apache.hadoop.fs.FSDataInputStream; + +import java.io.IOException; + +/** + * A reader to read one or more HFile blocks based on the start and end offsets. + */ +public class HFileBlockReader { + private final HFileContext context; + private final byte[] byteBuff; + private int offset; + + /** + * Instantiates the {@link HFileBlockReader}. + * + * @param context HFile context. + * @param stream Input data. + * @param startOffset Start offset to read from. + * @param endOffset End offset to stop at. + * @throws IOException + */ + public HFileBlockReader(HFileContext context, + FSDataInputStream stream, + long startOffset, + long endOffset) throws IOException { + this.context = context; + this.offset = 0; + stream.seek(startOffset); + this.byteBuff = new byte[(int) (endOffset - startOffset)]; + stream.readFully(byteBuff); + } + + /** + * Reads the next block based on the expected block type. + * + * @param expectedBlockType Expected block type. + * @return {@link HFileBlock} instance matching the expected block type. + * @throws IOException if the type of next block does not match the expeced type. + */ + public HFileBlock nextBlock(HFileBlockType expectedBlockType) throws IOException { + if (offset >= byteBuff.length) { + return null; Review Comment: All nulls are removed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
