-
Notifications
You must be signed in to change notification settings - Fork 1.7k
AVRO-3482: Reuse MAGIC in DataFileReader #1639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,7 @@ private Header() { | |
| */ | ||
| public DataFileStream(InputStream in, DatumReader<D> reader) throws IOException { | ||
| this.reader = reader; | ||
| initialize(in); | ||
| initialize(in, null); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -97,18 +97,30 @@ protected DataFileStream(DatumReader<D> reader) throws IOException { | |
| this.reader = reader; | ||
| } | ||
|
|
||
| /** Initialize the stream by reading from its head. */ | ||
| void initialize(InputStream in) throws IOException { | ||
| this.header = new Header(); | ||
| this.vin = DecoderFactory.get().binaryDecoder(in, vin); | ||
| byte[] readMagic() throws IOException { | ||
| if (this.vin == null) { | ||
| throw new IOException("InputStream is not initialized"); | ||
| } | ||
| byte[] magic = new byte[DataFileConstants.MAGIC.length]; | ||
| try { | ||
| vin.readFixed(magic); // read magic | ||
| } catch (IOException e) { | ||
| throw new IOException("Not an Avro data file.", e); | ||
rbalamohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return magic; | ||
| } | ||
|
|
||
| void validateMagic(byte[] magic) throws InvalidAvroMagicException { | ||
| if (!Arrays.equals(DataFileConstants.MAGIC, magic)) | ||
| throw new InvalidAvroMagicException("Not an Avro data file."); | ||
| } | ||
|
|
||
| /** Initialize the stream by reading from its head. */ | ||
| void initialize(InputStream in, byte[] magic) throws IOException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry I should have been more complete last time. Can we make these two
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DataFileReader extends this class and making it "private" would cause issue in accessing this method from DataFileReader. |
||
| this.header = new Header(); | ||
| this.vin = DecoderFactory.get().binaryDecoder(in, vin); | ||
| magic = (magic == null) ? readMagic() : magic; | ||
| validateMagic(magic); | ||
|
|
||
| long l = vin.readMapStart(); // read meta data | ||
| if (l > 0) { | ||
|
|
@@ -134,7 +146,7 @@ void initialize(InputStream in) throws IOException { | |
| } | ||
|
|
||
| /** Initialize the stream without reading from it. */ | ||
| void initialize(InputStream in, Header header) throws IOException { | ||
| void initialize(Header header) throws IOException { | ||
| this.header = header; | ||
| this.codec = resolveCodec(); | ||
| reader.setSchema(header.schema); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.