Skip to content

Commit 4607854

Browse files
GH-3074: read footer using 1 call readFully(byte[8]) instead of 5 calls
1 parent 1e04ec7 commit 4607854

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileReader.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,19 @@ private static final ParquetMetadata readFooter(
585585
}
586586

587587
// Read footer length and magic string - with a single seek
588-
byte[] magic = new byte[MAGIC.length];
589-
long fileMetadataLengthIndex = fileLen - magic.length - FOOTER_LENGTH_SIZE;
588+
long fileMetadataLengthIndex = fileLen - MAGIC.length - FOOTER_LENGTH_SIZE;
590589
LOG.debug("reading footer index at {}", fileMetadataLengthIndex);
591590
f.seek(fileMetadataLengthIndex);
592-
int fileMetadataLength = readIntLittleEndian(f);
593-
f.readFully(magic);
591+
byte[] magicAndLengthBytes = new byte[FOOTER_LENGTH_SIZE + MAGIC.length];
592+
f.readFully(magicAndLengthBytes);
593+
int fileMetadataLength = readIntLittleEndian(magicAndLengthBytes, 0);
594594

595595
boolean encryptedFooterMode;
596+
// using JDK >= 9: if (Arrays.equals(MAGIC, 0, MAGIC.length,
597+
// magicAndLengthBytes, FOOTER_LENGTH_SIZE, FOOTER_LENGTH_SIZE + MAGIC.length)) {
598+
// using JDK <= 8: need extract sub array then compare
599+
byte[] magic = new byte[MAGIC.length];
600+
System.arraycopy(magicAndLengthBytes, FOOTER_LENGTH_SIZE, magic, 0, MAGIC.length);
596601
if (Arrays.equals(MAGIC, magic)) {
597602
encryptedFooterMode = false;
598603
} else if (Arrays.equals(EFMAGIC, magic)) {

0 commit comments

Comments
 (0)