本文整理汇总了Java中org.apache.avro.AvroTypeException类的典型用法代码示例。如果您正苦于以下问题:Java AvroTypeException类的具体用法?Java AvroTypeException怎么用?Java AvroTypeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AvroTypeException类属于org.apache.avro包,在下文中一共展示了AvroTypeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readEnum
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Override
public int readEnum() throws IOException {
advance(Symbol.ENUM);
Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
in.getText();
int n = top.findLabel(in.getText());
if (n >= 0) {
in.nextToken();
return n;
}
throw new AvroTypeException("Unknown symbol in enum " + in.getText());
} else {
throw error("fixed");
}
}
示例2: readIndex
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Override
public int readIndex() throws IOException {
advance(Symbol.UNION);
Symbol.Alternative a = (Symbol.Alternative) parser.popSymbol();
String label;
if (in.getCurrentToken() == JsonToken.VALUE_NULL) {
label = "null";
} else if (in.getCurrentToken() == JsonToken.START_OBJECT &&
in.nextToken() == JsonToken.FIELD_NAME) {
label = in.getText();
in.nextToken();
parser.pushSymbol(Symbol.UNION_END);
} else {
throw error("start-union");
}
int n = a.findLabel(label);
if (n < 0)
throw new AvroTypeException("Unknown union branch " + label);
parser.pushSymbol(a.getSymbol(n));
return n;
}
示例3: get
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
public static IParser get( final Object obj ) throws IOException{
Schema.Type schemaType;
try{
schemaType = genericUtil.induce( obj ).getType();
}catch( AvroTypeException e ){
return new AvroNullParser();
}
switch( schemaType ){
case ARRAY:
return new AvroArrayParser( (GenericArray)obj );
case MAP:
return new AvroMapParser( (Map<Object,Object>)obj );
case RECORD:
return new AvroRecordParser( (GenericRecord)obj );
case UNION :
default:
return new AvroNullParser();
}
}
示例4: hasParser
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
public static boolean hasParser( final Object obj ) throws IOException{
Schema.Type schemaType;
try{
schemaType = genericUtil.induce( obj ).getType();
}catch( AvroTypeException e ){
return false;
}
switch( schemaType ){
case ARRAY:
case MAP:
case RECORD:
return true;
case UNION :
default:
return false;
}
}
示例5: transformToRecord
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
private GenericRecord transformToRecord(Map<String, Object> object, Schema schema) throws IOException {
GenericRecord record = new GenericData.Record(schema);
if (validate && object.size() != schema.getFields().size()) {
throw new AvroTypeException("Field count mismatch, expected: " + schema.getFields().size()
+ " actual: " + object.size());
}
for (Schema.Field field : schema.getFields()) {
if (object.containsKey(field.name())) {
record.put(field.name(), transform(object.get(field.name()), field.schema()));
} else {
if (validate) {
throw new AvroTypeException("Field does not found: " + field.name());
}
}
}
return record;
}
示例6: readEnum
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Override
public int readEnum() throws IOException {
advance(Symbol.ENUM);
Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
in.getText();
int n = top.findLabel(in.getText());
if (n >= 0) {
in.nextToken();
return n;
}
throw new AvroTypeException("Unknown symbol in enum " + in.getText());
} else {
throw error("fixed");
}
}
示例7: checkJsonReadWrite
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
/**
* Convert given JSON input string to Avro records, then convert it back to
* JSON and compare it with the original.
*/
private void checkJsonReadWrite(String jsonInput, Schema schema,
boolean shouldThrowParsingException) throws IOException {
try {
List<GenericRecord> outRecords = toRecords(jsonInput, schema,
schema);
String jsonOutput = toJson(outRecords, schema);
assertEquals(jsonInput, jsonOutput);
} catch (AvroTypeException ex) {
if (shouldThrowParsingException) {
return;
} else {
throw new RuntimeException(ex);
}
}
if (shouldThrowParsingException) {
assertTrue(
"This code should not have been reached because of previous "
+ "exception thrown", false);
}
}
示例8: readEnum
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Override
public int readEnum() throws IOException {
advance(Symbol.ENUM);
Symbol.EnumLabelsAction top = (Symbol.EnumLabelsAction) parser.popSymbol();
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
in.getText();
int n = top.findLabel(in.getText());
if (n >= 0) {
in.nextToken();
return n;
}
throw new AvroTypeException("Unknown symbol in enum " + in.getText());
} else {
throw error("fixed");
}
}
示例9: checkFixed
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
private void checkFixed(int size) throws IOException {
advance(Symbol.FIXED);
Symbol.IntCheckAction top = (Symbol.IntCheckAction) parser.popSymbol();
if (size != top.size) {
throw new AvroTypeException(
"Incorrect length for fixed binary: expected " +
top.size + " but received " + size + " bytes.");
}
}
示例10: readFixed
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Override
public void readFixed(byte[] bytes, int start, int len) throws IOException {
checkFixed(len);
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
byte[] result = readByteArray();
in.nextToken();
if (result.length != len) {
throw new AvroTypeException("Expected fixed length " + len
+ ", but got" + result.length);
}
System.arraycopy(result, 0, bytes, start, len);
} else {
throw error("fixed");
}
}
示例11: doSkipFixed
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
private void doSkipFixed(int length) throws IOException {
if (in.getCurrentToken() == JsonToken.VALUE_STRING) {
byte[] result = readByteArray();
in.nextToken();
if (result.length != length) {
throw new AvroTypeException("Expected fixed length " + length
+ ", but got" + result.length);
}
} else {
throw error("fixed");
}
}
示例12: injectDefaultValueIfAvailable
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
private void injectDefaultValueIfAvailable(final JsonParser in, String fieldName) throws IOException {
Field field = findField(schema, fieldName);
if (field == null) {
throw new AvroTypeException("Expected field name not found: " + fieldName);
}
JsonNode defVal = field.defaultValue();
if (defVal == null) {
throw new AvroTypeException("Expected field name not found: " + fieldName);
}
List<JsonElement> result = new ArrayList<>(2);
JsonParser traverse = defVal.traverse();
JsonToken nextToken;
while ((nextToken = traverse.nextToken()) != null) {
if (nextToken.isScalarValue()) {
result.add(new JsonElement(nextToken, traverse.getText()));
} else {
result.add(new JsonElement(nextToken));
}
}
result.add(NULL_JSON_ELEMENT);
if (currentReorderBuffer == null) {
currentReorderBuffer = new ReorderBuffer();
}
currentReorderBuffer.origParser = in;
this.in = makeParser(result);
}
示例13: readerWithInvalidSchema
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Test(expected = AvroTypeException.class)
public void readerWithInvalidSchema() throws Throwable {
Map<String, Object> cfg = new HashMap<String, Object>() {{
put(AvroFileReader.FILE_READER_AVRO_SCHEMA, Schema.create(Schema.Type.STRING).toString());
put(AgnosticFileReader.FILE_READER_AGNOSTIC_EXTENSIONS_AVRO, getFileExtension());
}};
reader = getReader(fs, dataFile, cfg);
readAllData();
}
示例14: readerWithInvalidSchema
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Test(expected = AvroTypeException.class)
public void readerWithInvalidSchema() throws Throwable {
Map<String, Object> cfg = new HashMap<String, Object>() {{
put(AvroFileReader.FILE_READER_AVRO_SCHEMA, Schema.create(Schema.Type.STRING).toString());
}};
reader = getReader(fs, dataFile, cfg);
readAllData();
}
示例15: writeFixed
import org.apache.avro.AvroTypeException; //导入依赖的package包/类
@Override
public void writeFixed(byte[] bytes, int start, int len) throws IOException {
parser.advance(Symbol.FIXED);
Symbol.IntCheckAction top = (Symbol.IntCheckAction) parser.popSymbol();
if (len != top.size) {
throw new AvroTypeException(
"Incorrect length for fixed binary: expected " + top.size + " but received " + len + " bytes.");
}
writeByteArray(bytes, start, len);
}