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