本文整理汇总了Java中example.avro.User类的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
User类属于example.avro包,在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: deserUserCompile
import example.avro.User; //导入依赖的package包/类
public void deserUserCompile(){
// Deserialize Users from disk
DatumReader<User> userDatumReader = new SpecificDatumReader<User>(User.class);
DataFileReader<User> dataFileReader = null;
User user = null;
try {
dataFileReader = new DataFileReader<User>(
new File("/Users/a/Desktop/tmp/users.avro"),
userDatumReader);
while (dataFileReader.hasNext()) {
// Reuse user object by passing it to next(). This saves us from
// allocating and garbage collecting many objects for files with
// many items.
user = dataFileReader.next(user);
System.out.println(user);
}
} catch (IOException e) {
e.printStackTrace();
}
}
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:21,代码来源:TestAvro.java
示例2: genericEncoderV1SpecificDecoderV1
import example.avro.User; //导入依赖的package包/类
@Test
public void genericEncoderV1SpecificDecoderV1() throws Exception{
Schema schema = load("users_v1.schema");
SchemaRegistryClient client = mock(SchemaRegistryClient.class);
AvroCodec codec = new AvroCodec();
codec.setSchemaRegistryClient(client);
when(client.register(any())).thenReturn(1);
when(client.fetch(eq(1))).thenReturn(schema);
GenericRecord record = new GenericData.Record(schema);
record.put("name","joe");
record.put("favoriteNumber",42);
record.put("favoriteColor","blue");
byte[] results = codec.encode(record);
User decoded = codec.decode(results,User.class);
Assert.assertEquals(record.get("name").toString(),decoded.getName().toString());
}
开发者ID:viniciusccarvalho,项目名称:schema-evolution-samples,代码行数:18,代码来源:AvroCodecTests.java
示例3: addUserCompile
import example.avro.User; //导入依赖的package包/类
public void addUserCompile(){
User user1 = new User();
user1.setName("王light");
user1.setFavoriteNumber(66);
user1.setFavoriteColor("浅蓝色");
// Alternate constructor
User user2 = new User("魏Sunny", 88, "red");
// Construct via builder
User user3 = User.newBuilder()
.setName("王Sam")
.setFavoriteColor("blue")
.setFavoriteNumber(2011)
.build();
DatumWriter<User> userDatumWriter = new SpecificDatumWriter<User>(User.class);
DataFileWriter<User> dataFileWriter = new DataFileWriter<User>(userDatumWriter);
try {
dataFileWriter.create(user1.getSchema(), new File("/Users/a/Desktop/tmp/users.avro"));
dataFileWriter.append(user1);
dataFileWriter.append(user2);
dataFileWriter.append(user3);
dataFileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
开发者ID:lrtdc,项目名称:book_ldrtc,代码行数:29,代码来源:TestAvro.java
示例4: specificEncoderV1GenericDecoderV1
import example.avro.User; //导入依赖的package包/类
@Test
public void specificEncoderV1GenericDecoderV1() throws Exception{
Schema schema = load("users_v1.schema");
SchemaRegistryClient client = mock(SchemaRegistryClient.class);
AvroCodec codec = new AvroCodec();
codec.setSchemaRegistryClient(client);
when(client.register(any())).thenReturn(1);
when(client.fetch(eq(1))).thenReturn(schema);
User user = User.newBuilder().setName("joe").setFavoriteColor("blue").setFavoriteNumber(42).build();
byte[] results = codec.encode(user);
GenericRecord decoded = codec.decode(results,GenericRecord.class);
Assert.assertEquals(user.getName().toString(),decoded.get("name").toString());
}
开发者ID:viniciusccarvalho,项目名称:schema-evolution-samples,代码行数:14,代码来源:AvroCodecTests.java
示例5: schemaResolveTest
import example.avro.User; //导入依赖的package包/类
@Test
public void schemaResolveTest() throws Exception {
User user = new User();
Class aClass = user.getClass();
Schema schema = ((GenericRecord)aClass.newInstance()).getSchema();
System.out.println(schema);
}
开发者ID:viniciusccarvalho,项目名称:schema-evolution-samples,代码行数:8,代码来源:AvroCodecTests.java
示例6: kafkaListenerContainerFactory
import example.avro.User; //导入依赖的package包/类
@Bean
public ConcurrentKafkaListenerContainerFactory<String, User> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, User> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
return factory;
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:9,代码来源:ReceiverConfig.java
示例7: testDeserialize
import example.avro.User; //导入依赖的package包/类
@Test
public void testDeserialize() {
User user = User.newBuilder().setName("John Doe").setFavoriteColor("green")
.setFavoriteNumber(null).build();
byte[] data = DatatypeConverter.parseHexBinary("104A6F686E20446F6502000A677265656E");
AvroDeserializer<User> avroDeserializer = new AvroDeserializer<>(User.class);
assertThat(avroDeserializer.deserialize("avro-bijection.t", data)).isEqualTo(user);
avroDeserializer.close();
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:12,代码来源:AvroDeserializerTest.java
示例8: testSerialize
import example.avro.User; //导入依赖的package包/类
@Test
public void testSerialize() {
User user = User.newBuilder().setName("John Doe").setFavoriteColor("green")
.setFavoriteNumber(null).build();
AvroSerializer<User> avroSerializer = new AvroSerializer<>();
assertThat(avroSerializer.serialize("avro-bijection.t", user))
.isEqualTo(DatatypeConverter.parseHexBinary("104A6F686E20446F6502000A677265656E"));
avroSerializer.close();
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:12,代码来源:AvroSerializerTest.java
示例9: testReceiver
import example.avro.User; //导入依赖的package包/类
@Test
public void testReceiver() throws Exception {
User user = User.newBuilder().setName("John Doe").setFavoriteColor("blue")
.setFavoriteNumber(null).build();
sender.send(user);
receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
assertThat(receiver.getLatch().getCount()).isEqualTo(0);
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:10,代码来源:SpringKafkaApplicationTest.java
示例10: testDeserialize
import example.avro.User; //导入依赖的package包/类
@Test
public void testDeserialize() {
User user = User.newBuilder().setName("John Doe").setFavoriteColor("green")
.setFavoriteNumber(null).build();
byte[] data = DatatypeConverter.parseHexBinary("104A6F686E20446F6502000A677265656E");
AvroDeserializer<User> avroDeserializer = new AvroDeserializer<>(User.class);
assertThat(avroDeserializer.deserialize("avro.t", data)).isEqualTo(user);
avroDeserializer.close();
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:13,代码来源:AvroDeserializerTest.java
示例11: testSerialize
import example.avro.User; //导入依赖的package包/类
@Test
public void testSerialize() {
User user = User.newBuilder().setName("John Doe").setFavoriteColor("green")
.setFavoriteNumber(null).build();
AvroSerializer<User> avroSerializer = new AvroSerializer<>();
assertThat(avroSerializer.serialize("avro.t", user))
.isEqualTo(DatatypeConverter.parseHexBinary("104A6F686E20446F6502000A677265656E"));
avroSerializer.close();
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:12,代码来源:AvroSerializerTest.java
示例12: testReceiver
import example.avro.User; //导入依赖的package包/类
@Test
public void testReceiver() throws Exception {
User user = User.newBuilder().setName("John Doe").setFavoriteColor("green")
.setFavoriteNumber(null).build();
sender.send(user);
receiver.getLatch().await(10000, TimeUnit.MILLISECONDS);
assertThat(receiver.getLatch().getCount()).isEqualTo(0);
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:10,代码来源:SpringKafkaApplicationTest.java
示例13: sourceWriteSameVersion
import example.avro.User; //导入依赖的package包/类
@Test
public void sourceWriteSameVersion() throws Exception {
User specificRecord = new User();
specificRecord.setName("joe");
Schema v1 = new Schema.Parser().parse(AvroMessageConverterSerializationTests.class
.getClassLoader().getResourceAsStream("schemas/user.avsc"));
GenericRecord genericRecord = new GenericData.Record(v1);
genericRecord.put("name", "joe");
SchemaRegistryClient client = new DefaultSchemaRegistryClient();
AvroSchemaRegistryClientMessageConverter converter = new AvroSchemaRegistryClientMessageConverter(
client, new NoOpCacheManager());
converter.setSubjectNamingStrategy(new DefaultSubjectNamingStrategy());
converter.setDynamicSchemaGenerationEnabled(false);
converter.afterPropertiesSet();
Message specificMessage = converter.toMessage(specificRecord,
new MutableMessageHeaders(Collections.<String, Object> emptyMap()),
MimeTypeUtils.parseMimeType("application/*+avro"));
SchemaReference specificRef = extractSchemaReference(MimeTypeUtils.parseMimeType(
specificMessage.getHeaders().get("contentType").toString()));
Message genericMessage = converter.toMessage(genericRecord,
new MutableMessageHeaders(Collections.<String, Object> emptyMap()),
MimeTypeUtils.parseMimeType("application/*+avro"));
SchemaReference genericRef = extractSchemaReference(MimeTypeUtils.parseMimeType(
genericMessage.getHeaders().get("contentType").toString()));
Assert.assertEquals(genericRef, specificRef);
Assert.assertEquals(1, genericRef.getVersion());
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:32,代码来源:AvroMessageConverterSerializationTests.java
示例14: testOriginalContentTypeHeaderOnly
import example.avro.User; //导入依赖的package包/类
@Test
public void testOriginalContentTypeHeaderOnly() throws Exception {
User specificRecord = new User();
specificRecord.setName("joe");
Schema v1 = new Schema.Parser().parse(AvroMessageConverterSerializationTests.class
.getClassLoader().getResourceAsStream("schemas/user.avsc"));
GenericRecord genericRecord = new GenericData.Record(v1);
genericRecord.put("name", "joe");
SchemaRegistryClient client = new DefaultSchemaRegistryClient();
client.register("user", "avro", v1.toString());
AvroSchemaRegistryClientMessageConverter converter = new AvroSchemaRegistryClientMessageConverter(
client, new NoOpCacheManager());
converter.setDynamicSchemaGenerationEnabled(false);
converter.afterPropertiesSet();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DatumWriter<User> writer = new SpecificDatumWriter<>(User.class);
Encoder encoder = EncoderFactory.get().binaryEncoder(baos, null);
writer.write(specificRecord, encoder);
encoder.flush();
Message source = MessageBuilder.withPayload(baos.toByteArray())
.setHeader(MessageHeaders.CONTENT_TYPE,
MimeTypeUtils.APPLICATION_OCTET_STREAM)
.setHeader(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE,
"application/vnd.user.v1+avro")
.build();
Object converted = converter.fromMessage(source, User.class);
Assert.assertNotNull(converted);
Assert.assertEquals(specificRecord.getName().toString(),
((User) converted).getName().toString());
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:32,代码来源:AvroMessageConverterSerializationTests.java
示例15: main
import example.avro.User; //导入依赖的package包/类
public static void main(String[] args) {
Schema schema = User.SCHEMA$;
Injection<GenericRecord, byte[]> recordInjection = GenericAvroCodecs.toBinary(schema);
User user= new User("1",1,"");
byte[] bytes = recordInjection.apply(user);
GenericRecord record = recordInjection.invert(bytes).get();
Object name = record.get("name");
System.out.println(record);
}
开发者ID:spafka,项目名称:spark_deep,代码行数:17,代码来源:AvroUseAvsc.java
示例16: send
import example.avro.User; //导入依赖的package包/类
public void send(User user) {
LOGGER.info("sending user='{}'", user.toString());
kafkaTemplate.send(avroBijectionTopic, user);
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:5,代码来源:Sender.java
示例17: producerFactory
import example.avro.User; //导入依赖的package包/类
@Bean
public ProducerFactory<String, User> producerFactory() {
return new DefaultKafkaProducerFactory<>(producerConfigs());
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:5,代码来源:SenderConfig.java
示例18: kafkaTemplate
import example.avro.User; //导入依赖的package包/类
@Bean
public KafkaTemplate<String, User> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:5,代码来源:SenderConfig.java
示例19: consumerFactory
import example.avro.User; //导入依赖的package包/类
@Bean
public ConsumerFactory<String, User> consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new StringDeserializer(),
new AvroDeserializer<>(User.class));
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:6,代码来源:ReceiverConfig.java
示例20: receive
import example.avro.User; //导入依赖的package包/类
@KafkaListener(topics = "${kafka.topic.avro-bijection}")
public void receive(User user) {
LOGGER.info("received user='{}'", user.toString());
latch.countDown();
}
开发者ID:code-not-found,项目名称:spring-kafka,代码行数:6,代码来源:Receiver.java
注:本文中的example.avro.User类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论