Example #1
0
 public void read() {
   openRead();
   try {
     while (true) {
       ByteSearchSection section = reader.readSectionStart(root.section);
       if (section.notEmpty()) {
         section = root.readNode(section);
         reader.movePast(section);
       }
     }
   } catch (EOCException ex) {
   }
   closeRead();
 }
Example #2
0
 @Override
 protected void readNode(ByteSearchSection section) {
   if (nodevalues == null) nodevalues = new ArrayList<NodeValue>();
   nodevalue = new NodeValue();
   for (Node f : orderedfields) {
     ByteSearchSection pos = findSection(section, f.section);
     // log.info("%s %b %s %s", f.label, pos.found(), f.section.toString(), pos.reportString());
     if (pos.found()) {
       f.readNode(pos);
       section.movePast(pos);
     }
   }
   if (nodevalue.size() > 0) nodevalues.add(nodevalue);
 }
Example #3
0
 @Override
 public Integer value(ByteSearchSection section) {
   if (section.notEmpty()) {
     try {
       return Integer.parseInt(stringValue(section));
     } catch (NumberFormatException ex) {
       log.fatalexception(
           ex,
           "value() offset %d section %s",
           StructuredTextFile.this.datafile.getOffset(),
           section.reportString());
     }
   }
   return 0;
 }
Example #4
0
 public void openRead() {
   checkFirstUse();
   if (datafile != null) {
     if (reader == null) {
       reader = datafile.rwbuffer;
     }
     datafile.openRead();
     if (hasHeader) {
       ByteSearchSection section = reader.readSectionStart(root.section);
       if (section.notEmpty()) {
         root.readHeader(section);
         reader.movePast(section);
       }
     }
   }
 }
Example #5
0
 @Override
 public JsonObject value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return gson.fromJson(this.stringValue(section), JsonObject.class);
   } else {
     return new JsonObject();
   }
 }
Example #6
0
 @Override
 public Long128 value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return new Long128(stringValue(section));
   } else {
     return null;
   }
 }
Example #7
0
 @Override
 public Long value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return Long.parseLong(stringValue(section));
   } else {
     return 0l;
   }
 }
Example #8
0
 @Override
 public String[] value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return stringValue(section).split(",");
   } else {
     return new String[0];
   }
 }
Example #9
0
 @Override
 public Double value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return Double.parseDouble(stringValue(section));
   } else {
     return 0.0;
   }
 }
Example #10
0
 @Override
 public Boolean value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return Boolean.parseBoolean(this.stringValue(section));
   } else {
     return false;
   }
 }
Example #11
0
 @Override
 public double[] value(ByteSearchSection section) {
   double[] result = ArrayTools.emptyDoubleArray;
   if (section.notEmpty()) {
     String stringvalue = stringValue(section);
     if (stringvalue.length() > 0) {
       try {
         String part[] = stringvalue.split(",");
         result = new double[part.length];
         for (int i = 0; i < part.length; i++) {
           result[i] = Double.parseDouble(part[i]);
         }
       } catch (NumberFormatException ex) {
         log.fatalexception(
             ex,
             "value() offset %d section %s",
             StructuredTextFile.this.datafile.getOffset(),
             section.reportString());
       }
     }
   }
   return result;
 }
Example #12
0
 @Override
 public ArrayList<T> value(ByteSearchSection section) {
   if (section.notEmpty()) {
     String stringValue = this.stringValue(section);
     // log.info("JsonArray %s", stringValue);
     ArrayList<T> result;
     try {
       result = (ArrayList<T>) gson.fromJson(stringValue, genericType);
     } catch (JsonSyntaxException ex) {
       log.info("failing %s", stringValue);
       throw ex;
     }
     return result;
   } else {
     return new ArrayList<T>();
   }
 }
Example #13
0
 protected String stringValue(ByteSearchSection section) {
   return section.toFullTrimmedString();
 }
Example #14
0
 protected ArrayList<ByteSearchSection> findAllSections(
     ByteSearchSection section, ByteSection needle) {
   return section.findAllSections(needle);
 }
Example #15
0
 protected boolean validRecord(ByteSearchSection section) {
   return section.notEmpty();
 }
Example #16
0
 protected ByteSearchSection findSection(ByteSearchSection section, ByteSection needle) {
   return section.findSection(needle);
 }