@Test public void getCustomFormatter() { SequenceFileSerializer formatter = SequenceFileSerializerFactory .getSerializer( "org.apache.flume.sink.hdfs.MyCustomSerializer$Builder", new Context()); assertTrue(formatter != null); assertTrue(formatter.getClass().getName(), formatter instanceof MyCustomSerializer); }
@SuppressWarnings("unchecked") static SequenceFileSerializer getSerializer(String formatType, Context context) { Preconditions.checkNotNull(formatType, "serialize type must not be null"); SequenceFileSerializerType type; try { type = SequenceFileSerializerType.valueOf(formatType); } catch (IllegalArgumentException e) { logger.debug("Not in enum, loading builder class: {}", formatType); type = SequenceFileSerializerType.Other; } Class<? extends SequenceFileSerializer.Builder> builderClass = type.getBuilderClass(); if (builderClass == null) { try { Class c = Class.forName(formatType); if (c != null && SequenceFileSerializer.Builder.class.isAssignableFrom(c)) { builderClass = (Class<? extends SequenceFileSerializer.Builder>) c; } else { logger.error("Unable to instantiate Builder from {}", formatType); return null; } } catch (ClassNotFoundException ex) { logger.error("Class not found: " + formatType, ex); return null; } catch (ClassCastException ex) { logger.error("Class does not extend " + SequenceFileSerializer.Builder.class.getCanonicalName() + ": " + formatType, ex); return null; } } SequenceFileSerializer.Builder builder; try { builder = builderClass.newInstance(); } catch (InstantiationException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } catch (IllegalAccessException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } return builder.build(context); }
SequenceFileSerializerFactory { @SuppressWarnings("unchecked") static SequenceFileSerializer getSerializer(String formatType, Context context) { Preconditions.checkNotNull(formatType, "serialize type must not be null"); SequenceFileSerializerType type; try { type = SequenceFileSerializerType.valueOf(formatType); } catch (IllegalArgumentException e) { logger.debug("Not in enum, loading builder class: {}", formatType); type = SequenceFileSerializerType.Other; } Class<? extends SequenceFileSerializer.Builder> builderClass = type.getBuilderClass(); if (builderClass == null) { try { Class c = Class.forName(formatType); if (c != null && SequenceFileSerializer.Builder.class.isAssignableFrom(c)) { builderClass = (Class<? extends SequenceFileSerializer.Builder>) c; } else { logger.error("Unable to instantiate Builder from {}", formatType); return null; } } catch (ClassNotFoundException ex) { logger.error("Class not found: " + formatType, ex); return null; } catch (ClassCastException ex) { logger.error("Class does not extend " + SequenceFileSerializer.Builder.class.getCanonicalName() + ": " + formatType, ex); return null; } } SequenceFileSerializer.Builder builder; try { builder = builderClass.newInstance(); } catch (InstantiationException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } catch (IllegalAccessException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } return builder.build(context); } }
SequenceFileSerializerFactory { @SuppressWarnings("unchecked") static SequenceFileSerializer getSerializer(String formatType, Context context) { Preconditions.checkNotNull(formatType, "serialize type must not be null"); SequenceFileSerializerType type; try { type = SequenceFileSerializerType.valueOf(formatType); } catch (IllegalArgumentException e) { logger.debug("Not in enum, loading builder class: {}", formatType); type = SequenceFileSerializerType.Other; } Class<? extends SequenceFileSerializer.Builder> builderClass = type.getBuilderClass(); if (builderClass == null) { try { Class c = Class.forName(formatType); if (c != null && SequenceFileSerializer.Builder.class.isAssignableFrom(c)) { builderClass = (Class<? extends SequenceFileSerializer.Builder>) c; } else { logger.error("Unable to instantiate Builder from {}", formatType); return null; } } catch (ClassNotFoundException ex) { logger.error("Class not found: " + formatType, ex); return null; } catch (ClassCastException ex) { logger.error("Class does not extend " + SequenceFileSerializer.Builder.class.getCanonicalName() + ": " + formatType, ex); return null; } } SequenceFileSerializer.Builder builder; try { builder = builderClass.newInstance(); } catch (InstantiationException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } catch (IllegalAccessException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } return builder.build(context); }  }
SequenceFileSerializerFactory { @SuppressWarnings("unchecked") static SequenceFileSerializer getSerializer(String formatType, Context context) { Preconditions.checkNotNull(formatType, "serialize type must not be null"); SequenceFileSerializerType type; try { type = SequenceFileSerializerType.valueOf(formatType); } catch (IllegalArgumentException e) { logger.debug("Not in enum, loading builder class: {}", formatType); type = SequenceFileSerializerType.Other; } Class<? extends SequenceFileSerializer.Builder> builderClass = type.getBuilderClass(); if (builderClass == null) { try { Class c = Class.forName(formatType); if (c != null && SequenceFileSerializer.Builder.class.isAssignableFrom(c)) { builderClass = (Class<? extends SequenceFileSerializer.Builder>) c; } else { logger.error("Unable to instantiate Builder from {}", formatType); return null; } } catch (ClassNotFoundException ex) { logger.error("Class not found: " + formatType, ex); return null; } catch (ClassCastException ex) { logger.error("Class does not extend " + SequenceFileSerializer.Builder.class.getCanonicalName() + ": " + formatType, ex); return null; } } SequenceFileSerializer.Builder builder; try { builder = builderClass.newInstance(); } catch (InstantiationException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } catch (IllegalAccessException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } return builder.build(context); }   }
SequenceFileSerializerFactory { @SuppressWarnings("unchecked") static SequenceFileSerializer getSerializer(String formatType, Context context) { Preconditions.checkNotNull(formatType, "serialize type must not be null"); SequenceFileSerializerType type; try { type = SequenceFileSerializerType.valueOf(formatType); } catch (IllegalArgumentException e) { logger.debug("Not in enum, loading builder class: {}", formatType); type = SequenceFileSerializerType.Other; } Class<? extends SequenceFileSerializer.Builder> builderClass = type.getBuilderClass(); if (builderClass == null) { try { Class c = Class.forName(formatType); if (c != null && SequenceFileSerializer.Builder.class.isAssignableFrom(c)) { builderClass = (Class<? extends SequenceFileSerializer.Builder>) c; } else { logger.error("Unable to instantiate Builder from {}", formatType); return null; } } catch (ClassNotFoundException ex) { logger.error("Class not found: " + formatType, ex); return null; } catch (ClassCastException ex) { logger.error("Class does not extend " + SequenceFileSerializer.Builder.class.getCanonicalName() + ": " + formatType, ex); return null; } } SequenceFileSerializer.Builder builder; try { builder = builderClass.newInstance(); } catch (InstantiationException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } catch (IllegalAccessException ex) { logger.error("Cannot instantiate builder: " + formatType, ex); return null; } return builder.build(context); }    }