Package com.cloudera.flume.conf.avro

Examples of com.cloudera.flume.conf.avro.AvroFlumeNodeMap


   * Converts a nodemap into an Avro-serialized byte array
   */
  static protected byte[] serializeNodeMap(ListMultimap<String, String> nodeMap)
      throws IOException {
    DatumWriter<AvroFlumeNodeMap> datumWriter = new SpecificDatumWriter<AvroFlumeNodeMap>();
    AvroFlumeNodeMap avromap = new AvroFlumeNodeMap();

    Map<CharSequence, List<CharSequence>> map = new HashMap<CharSequence, List<CharSequence>>();
    for (Entry<String, Collection<String>> e : nodeMap.asMap().entrySet()) {
      String name = e.getKey();
      GenericArray<CharSequence> out = new GenericData.Array<CharSequence>(e
          .getValue().size(), Schema.createArray(Schema.create(Type.STRING)));

      for (String s : e.getValue()) {
        out.add(new String(s));
      }

      map.put(name, out);
    }

    avromap.nodemap = map;

    datumWriter.setSchema(avromap.getSchema());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataFileWriter<AvroFlumeNodeMap> fileWriter = new DataFileWriter<AvroFlumeNodeMap>(
        datumWriter);
    fileWriter.create(avromap.getSchema(), baos);
    fileWriter.append(avromap);
    fileWriter.close();

    return baos.toByteArray();
  }
View Full Code Here


  static protected List<Pair<String, List<String>>> deserializeNodeMap(
      byte[] data) throws IOException {
    DatumReader<AvroFlumeNodeMap> reader = new SpecificDatumReader<AvroFlumeNodeMap>();
    DataFileStream<AvroFlumeNodeMap> fileStream = new DataFileStream<AvroFlumeNodeMap>(
        new ByteArrayInputStream(data), reader);
    AvroFlumeNodeMap cfgmap = fileStream.next();
    fileStream.close();

    List<Pair<String, List<String>>> ret = new ArrayList<Pair<String, List<String>>>();

    for (Entry<CharSequence, List<CharSequence>> e : cfgmap.nodemap.entrySet()) {
View Full Code Here

   * Converts a nodemap into an Avro-serialized byte array
   */
  static protected byte[] serializeNodeMap(ListMultimap<String, String> nodeMap)
      throws IOException {
    DatumWriter<AvroFlumeNodeMap> datumWriter = new SpecificDatumWriter<AvroFlumeNodeMap>();
    AvroFlumeNodeMap avromap = new AvroFlumeNodeMap();

    Map<CharSequence, List<CharSequence>> map = new HashMap<CharSequence, List<CharSequence>>();
    for (Entry<String, Collection<String>> e : nodeMap.asMap().entrySet()) {
      String name = e.getKey();
      GenericArray<CharSequence> out = new GenericData.Array<CharSequence>(e
          .getValue().size(), Schema.createArray(Schema.create(Type.STRING)));

      for (String s : e.getValue()) {
        out.add(new String(s));
      }

      map.put(name, out);
    }

    avromap.nodemap = map;

    datumWriter.setSchema(avromap.getSchema());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataFileWriter<AvroFlumeNodeMap> fileWriter = new DataFileWriter<AvroFlumeNodeMap>(
        datumWriter);
    fileWriter.create(avromap.getSchema(), baos);
    fileWriter.append(avromap);
    fileWriter.close();

    return baos.toByteArray();
  }
View Full Code Here

  static protected List<Pair<String, List<String>>> deserializeNodeMap(
      byte[] data) throws IOException {
    DatumReader<AvroFlumeNodeMap> reader = new SpecificDatumReader<AvroFlumeNodeMap>();
    DataFileStream<AvroFlumeNodeMap> fileStream = new DataFileStream<AvroFlumeNodeMap>(
        new ByteArrayInputStream(data), reader);
    AvroFlumeNodeMap cfgmap = fileStream.next();
    fileStream.close();

    List<Pair<String, List<String>>> ret = new ArrayList<Pair<String, List<String>>>();

    for (Entry<CharSequence, List<CharSequence>> e : cfgmap.nodemap.entrySet()) {
View Full Code Here

TOP

Related Classes of com.cloudera.flume.conf.avro.AvroFlumeNodeMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.