当前位置: 首页>>代码示例>>Java>>正文


Java AvroTypeException类代码示例

本文整理汇总了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");
	}
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:17,代码来源:ExtendedJsonDecoder.java

示例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;
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:23,代码来源:ExtendedJsonDecoder.java

示例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();
  }
}
 
开发者ID:yahoojapan,项目名称:dataplatform-schema-lib,代码行数:21,代码来源:AvroObjectToParser.java

示例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;
  }
}
 
开发者ID:yahoojapan,项目名称:dataplatform-schema-lib,代码行数:19,代码来源:AvroObjectToParser.java

示例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;
}
 
开发者ID:intropro,项目名称:prairie,代码行数:18,代码来源:AvroFormatWriter.java

示例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");
  }
}
 
开发者ID:openaire,项目名称:iis,代码行数:17,代码来源:HackedJsonDecoder.java

示例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);
	}
}
 
开发者ID:openaire,项目名称:iis,代码行数:25,代码来源:JsonCodersTest.java

示例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");
    }
}
 
开发者ID:whale2,项目名称:iow-hadoop-streaming,代码行数:17,代码来源:IOWJsonDecoder.java

示例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.");
	}
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:10,代码来源:ExtendedJsonDecoder.java

示例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");
	}
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:16,代码来源:ExtendedJsonDecoder.java

示例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");
	}
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:13,代码来源:ExtendedJsonDecoder.java

示例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);
}
 
开发者ID:Celos,项目名称:avro-json-decoder,代码行数:30,代码来源:ExtendedJsonDecoder.java

示例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();
}
 
开发者ID:mmolimar,项目名称:kafka-connect-fs,代码行数:10,代码来源:AvroFileReaderTest.java

示例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();
}
 
开发者ID:mmolimar,项目名称:kafka-connect-fs,代码行数:9,代码来源:AvroFileReaderTest.java

示例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);
}
 
开发者ID:HotelsDotCom,项目名称:jasvorno,代码行数:11,代码来源:JasvornoEncoder.java


注:本文中的org.apache.avro.AvroTypeException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。