示例#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();
 }
示例#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);
 }
示例#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;
 }
示例#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);
       }
     }
   }
 }
示例#5
0
 @Override
 public JsonObject value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return gson.fromJson(this.stringValue(section), JsonObject.class);
   } else {
     return new JsonObject();
   }
 }
示例#6
0
 @Override
 public Long128 value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return new Long128(stringValue(section));
   } else {
     return null;
   }
 }
示例#7
0
 @Override
 public Long value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return Long.parseLong(stringValue(section));
   } else {
     return 0l;
   }
 }
示例#8
0
 @Override
 public String[] value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return stringValue(section).split(",");
   } else {
     return new String[0];
   }
 }
示例#9
0
 @Override
 public Double value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return Double.parseDouble(stringValue(section));
   } else {
     return 0.0;
   }
 }
示例#10
0
 @Override
 public Boolean value(ByteSearchSection section) {
   if (section.notEmpty()) {
     return Boolean.parseBoolean(this.stringValue(section));
   } else {
     return false;
   }
 }
示例#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;
 }
示例#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>();
   }
 }
示例#13
0
 protected String stringValue(ByteSearchSection section) {
   return section.toFullTrimmedString();
 }
示例#14
0
 protected ArrayList<ByteSearchSection> findAllSections(
     ByteSearchSection section, ByteSection needle) {
   return section.findAllSections(needle);
 }
示例#15
0
 protected boolean validRecord(ByteSearchSection section) {
   return section.notEmpty();
 }
示例#16
0
 protected ByteSearchSection findSection(ByteSearchSection section, ByteSection needle) {
   return section.findSection(needle);
 }