You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by dk...@apache.org on 2018/11/08 17:28:32 UTC
[avro] branch master updated: AVRO-2127: throw more specific
exceptions from DataFileStream#initialize (#323)
This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new c6f772b AVRO-2127: throw more specific exceptions from DataFileStream#initialize (#323)
c6f772b is described below
commit c6f772b408046c61b3269d8aecc5f1684bcad6fb
Author: Vladislav <re...@users.noreply.github.com>
AuthorDate: Thu Nov 8 20:28:27 2018 +0300
AVRO-2127: throw more specific exceptions from DataFileStream#initialize (#323)
* AVRO-2127: throw more specific exceptions from DataFileStream#initialize
* AVRO-2127: throw more specific exceptions from DataFileReader12
---
.../org/apache/avro/InvalidAvroMagicException.java | 26 ++++++++++++++++++++++
.../avro/InvalidNumberEncodingException.java | 26 ++++++++++++++++++++++
.../org/apache/avro/UnknownAvroCodecException.java | 26 ++++++++++++++++++++++
.../java/org/apache/avro/file/DataFileReader.java | 5 +++--
.../org/apache/avro/file/DataFileReader12.java | 6 +++--
.../java/org/apache/avro/file/DataFileStream.java | 3 ++-
.../java/org/apache/avro/io/BinaryDecoder.java | 5 +++--
.../org/apache/avro/io/DirectBinaryDecoder.java | 5 +++--
8 files changed, 93 insertions(+), 9 deletions(-)
diff --git a/lang/java/avro/src/main/java/org/apache/avro/InvalidAvroMagicException.java b/lang/java/avro/src/main/java/org/apache/avro/InvalidAvroMagicException.java
new file mode 100644
index 0000000..6519ad8
--- /dev/null
+++ b/lang/java/avro/src/main/java/org/apache/avro/InvalidAvroMagicException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.avro;
+
+import java.io.IOException;
+
+public class InvalidAvroMagicException extends IOException {
+ public InvalidAvroMagicException(String message) {
+ super(message);
+ }
+}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/InvalidNumberEncodingException.java b/lang/java/avro/src/main/java/org/apache/avro/InvalidNumberEncodingException.java
new file mode 100644
index 0000000..fe5408f
--- /dev/null
+++ b/lang/java/avro/src/main/java/org/apache/avro/InvalidNumberEncodingException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.avro;
+
+import java.io.IOException;
+
+public class InvalidNumberEncodingException extends IOException {
+ public InvalidNumberEncodingException(String message) {
+ super(message);
+ }
+}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/UnknownAvroCodecException.java b/lang/java/avro/src/main/java/org/apache/avro/UnknownAvroCodecException.java
new file mode 100644
index 0000000..abeb69c
--- /dev/null
+++ b/lang/java/avro/src/main/java/org/apache/avro/UnknownAvroCodecException.java
@@ -0,0 +1,26 @@
+/*
+ * 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.avro;
+
+import java.io.IOException;
+
+public class UnknownAvroCodecException extends IOException {
+ public UnknownAvroCodecException(String message) {
+ super(message);
+ }
+}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java
index ba0daa5..0c399a9 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.File;
import java.util.Arrays;
+import org.apache.avro.InvalidAvroMagicException;
import org.apache.avro.io.DecoderFactory;
import org.apache.avro.io.DatumReader;
import static org.apache.avro.file.DataFileConstants.SYNC_SIZE;
@@ -47,7 +48,7 @@ public class DataFileReader<D>
DatumReader<D> reader)
throws IOException {
if (in.length() < MAGIC.length)
- throw new IOException("Not an Avro data file");
+ throw new InvalidAvroMagicException("Not an Avro data file");
// read magic header
byte[] magic = new byte[MAGIC.length];
@@ -60,7 +61,7 @@ public class DataFileReader<D>
if (Arrays.equals(DataFileReader12.MAGIC, magic)) // 1.2 format
return new DataFileReader12<>(in, reader);
- throw new IOException("Not an Avro data file");
+ throw new InvalidAvroMagicException("Not an Avro data file");
}
/**
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java
index e285b08..0c937bf 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileReader12.java
@@ -26,7 +26,9 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import org.apache.avro.InvalidAvroMagicException;
import org.apache.avro.Schema;
+import org.apache.avro.UnknownAvroCodecException;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.DecoderFactory;
import org.apache.avro.io.BinaryDecoder;
@@ -68,7 +70,7 @@ public class DataFileReader12<D> implements FileReader<D>, Closeable {
byte[] magic = new byte[4];
in.read(magic);
if (!Arrays.equals(MAGIC, magic))
- throw new IOException("Not a data file.");
+ throw new InvalidAvroMagicException("Not a data file.");
long length = in.length();
in.seek(length-4);
@@ -91,7 +93,7 @@ public class DataFileReader12<D> implements FileReader<D>, Closeable {
this.count = getMetaLong(COUNT);
String codec = getMetaString(CODEC);
if (codec != null && ! codec.equals(NULL_CODEC)) {
- throw new IOException("Unknown codec: " + codec);
+ throw new UnknownAvroCodecException("Unknown codec: " + codec);
}
this.schema = Schema.parse(getMetaString(SCHEMA));
this.reader = reader;
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
index a7a3561..562158b 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DataFileStream.java
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import org.apache.avro.AvroRuntimeException;
+import org.apache.avro.InvalidAvroMagicException;
import org.apache.avro.Schema;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.DecoderFactory;
@@ -102,7 +103,7 @@ public class DataFileStream<D> implements Iterator<D>, Iterable<D>, Closeable {
throw new IOException("Not an Avro data file.", e);
}
if (!Arrays.equals(DataFileConstants.MAGIC, magic))
- throw new IOException("Not an Avro data file.");
+ throw new InvalidAvroMagicException("Not an Avro data file.");
long l = vin.readMapStart(); // read meta data
if (l > 0) {
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
index 7d996d2..93c147f 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.nio.ByteBuffer;
import org.apache.avro.AvroRuntimeException;
+import org.apache.avro.InvalidNumberEncodingException;
import org.apache.avro.util.Utf8;
/** An {@link Decoder} for binary-format data.
@@ -151,7 +152,7 @@ public class BinaryDecoder extends Decoder {
b = buf[pos + len++] & 0xff;
n ^= (b & 0x7f) << 28;
if (b > 0x7f) {
- throw new IOException("Invalid int encoding");
+ throw new InvalidNumberEncodingException("Invalid int encoding");
}
}
}
@@ -223,7 +224,7 @@ public class BinaryDecoder extends Decoder {
b = buf[pos + len++] & 0xff;
l ^= (b & 0x7fL) << 63;
if (b > 0x7f) {
- throw new IOException("Invalid long encoding");
+ throw new InvalidNumberEncodingException("Invalid long encoding");
}
}
}
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java
index 4577b47..07fcdb1 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/DirectBinaryDecoder.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
+import org.apache.avro.InvalidNumberEncodingException;
import org.apache.avro.util.ByteBufferInputStream;
@@ -110,7 +111,7 @@ class DirectBinaryDecoder extends BinaryDecoder {
}
shift += 7;
} while (shift < 32);
- throw new IOException("Invalid int encoding");
+ throw new InvalidNumberEncodingException("Invalid int encoding");
}
@@ -131,7 +132,7 @@ class DirectBinaryDecoder extends BinaryDecoder {
}
shift += 7;
} while (shift < 64);
- throw new IOException("Invalid long encoding");
+ throw new InvalidNumberEncodingException("Invalid long encoding");
}
private final byte[] buf = new byte[8];