Skip to content

Commit

Permalink
GH-3074: read footer using 1 call readFully(byte[8]) instead of 5 calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-Nauwynck committed Nov 23, 2024
1 parent 1e04ec7 commit 0c0dd59
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,18 @@ private static final ParquetMetadata readFooter(
}

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

boolean encryptedFooterMode;
// using JDK >= 9: if (Arrays.equals(MAGIC, 0, MAGIC.length, magicAndLengthBytes, FOOTER_LENGTH_SIZE, FOOTER_LENGTH_SIZE + MAGIC.length)) {
// using JDK <= 8: need extract sub array then compare
byte[] magic = new byte[MAGIC.length];
System.arraycopy(magicAndLengthBytes, FOOTER_LENGTH_SIZE, magic, 0, MAGIC.length);
if (Arrays.equals(MAGIC, magic)) {
encryptedFooterMode = false;
} else if (Arrays.equals(EFMAGIC, magic)) {
Expand Down

0 comments on commit 0c0dd59

Please sign in to comment.