Package ar.util

Examples of ar.util.DelimitedReader


    }     
  }

  /**Write from source text to indicated binary files.**/
  public static void write(File sourceFile, int skip, File target, char[] types) throws Exception {
    DelimitedReader source = new DelimitedReader(sourceFile, skip, DelimitedReader.CSV);
   
   
    int entriesRead = 0;
    try(FileOutputStream file = new FileOutputStream(target)) {
      byte[] header = makeHeader(types);
      file.write(header);

      while(source.hasNext()) {
        String[] entry = source.next();
        if (entry == null) {continue;}
        for (int i=0;i<types.length;i++) {
          if (types[i]=='x') {continue;}
          byte[] value = asBinary(entry[i], types[i]);
          file.write(value);           
View Full Code Here


    //------------------------ Setup Operations -------------------
    //Get a dataset loaded into a data structure.  This is not technically
    //Abstract Rendering, but it is necessary to get anything other than
    //a white box out of this demo
    ArrayList<Indexed> items = new ArrayList<>();
    DelimitedReader reader = new DelimitedReader(new File("../data/circlepoints.csv"), 1, ",");
    System.out.print("Loading example data...");
    while (reader.hasNext()) {
      String[] parts = reader.next();
      if (parts == null) {continue;}
      Double[] vals = new Double[parts.length];
      for (int i=0; i<parts.length; i++) {vals[i] = Double.parseDouble(parts[i]);}
      items.add(new Indexed.ArrayWrapper(vals));
    }
View Full Code Here

    encode(csv, output, schema);
   
    GlyphList<?,?> reference = (GlyphList<?,?>) Util.load(
        new GlyphList<Rectangle2D, Object>(),
        new DelimitedReader(csv),
        new Indexed.Converter(TYPE.X, TYPE.X, TYPE.DOUBLE, TYPE.DOUBLE, TYPE.INT),
        new Indexed.ToRect(.1, 2,3),
        new Indexed.ToValue<>(4));
   
    Glyphset.RandomAccess<Rectangle2D, Color> result = GlyphsetTools.fullLoad(output, new AvroRect<Color>(.1, 2, 3, 4));
View Full Code Here

    DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(schema);

    try (DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<GenericRecord>(datumWriter)) {
      dataFileWriter.create(schema, targetFile);
     
      DelimitedReader reader = new DelimitedReader(sourceFile, 1, "\\s*,\\s*");
      while (reader.hasNext()) {
        final String[] record = reader.next();
        if (record == null) {continue;}
        final GenericRecord r = new GenericData.Record(schema);
        for (int i=0; i<record.length;i++) {r.put(i, Double.valueOf(record[i]));}
        dataFileWriter.append(r);
      }
View Full Code Here

    assertTrue("hbin not found after encode.", hbin.exists());
   
    mm = new MemMapList<Rectangle2D, Integer>(hbin, new Indexed.ToRect(1, 0, 1), new Indexed.ToValue<Integer,Integer>(2));
    ref = (GlyphList<Rectangle2D, Integer>) Util.load(
        new ar.glyphsets.GlyphList<Rectangle2D, Integer>(),
        new DelimitedReader(csv, 1, "\\s*,\\s*"),
        new Indexed.Converter(TYPE.X, TYPE.X, TYPE.DOUBLE, TYPE.DOUBLE, TYPE.INT),
        new Indexed.ToRect(1, 2, 3), new Indexed.ToValue<Integer,Integer>(4));
  }
View Full Code Here

 
  @SuppressWarnings({ "unchecked", "rawtypes" })
  public static <G,T> Glyphset<G,T> autoLoad(File source, double glyphSize, Glyphset<G,T> glyphs) {
    try {
      DelimitedReader r = new DelimitedReader(source, 0, DelimitedReader.CSV);
      String[] line = r.next();
      int skip;
      int xField, yField, colorField, valueField;
      if (isNumber(line[0])) {
        xField =0;
        yField =1;
        colorField = line.length >= 3 ? 2 : -1;
        valueField = line.length >= 4 ? 3 : -1;
        skip =0;
      } else {
        xField = fieldMatch("X", line, 0);
        yField = fieldMatch("Y", line, 1);
        colorField = fieldMatch("C", line, -1);
        valueField = fieldMatch("V", line, -1);
        skip =1;
      }
     
      if (glyphs instanceof MemMapList) {
        MemMapList<G,T> list = new MemMapList<>(source, ((MemMapList<G,T>) glyphs).shaper(), ((MemMapList<G,T>) glyphs).valuer());
        System.out.printf("Setup list of %d entries.\n", list.size());
        return list;
      } else {
        int valField = Math.max(colorField, valueField);
        int max = Math.max(xField, valField);
        max = Math.max(max, yField);
        Converter.TYPE[] types = new Converter.TYPE[max+1];
        Arrays.fill(types, Converter.TYPE.X);
        types[xField] = Converter.TYPE.DOUBLE;
        types[yField] = Converter.TYPE.DOUBLE;
       
        if (colorField >=0) {types[colorField] = Converter.TYPE.COLOR;}
        if (valueField >=0) {types[valueField] = Converter.TYPE.DOUBLE;}
       
        Valuer valuer;
        if (valField >=0) {valuer = new Indexed.ToValue<Indexed,T>(valField);}
        else {valuer = new Valuer.Constant<>(Color.red);}
       
       
        return Util.load(
            (Glyphset<Rectangle2D,T>) glyphs,
            new DelimitedReader(source, skip, DelimitedReader.CSV),
            new Converter(types),
            new Indexed.ToRect(glyphSize, glyphSize, true, xField, yField),
            valuer);
      }
View Full Code Here

TOP

Related Classes of ar.util.DelimitedReader

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.