use of io.georocket.storage.XMLChunkMeta in project georocket by georocket.
the class XMLSplitter method makeResult.
/**
* Create a new chunk starting from the marked position and ending on the
* given position. Reset the mark afterwards and advance the window to the
* end position. Return a {@link io.georocket.input.Splitter.Result} object
* with the new chunk and its metadata.
* @param pos the end position
* @return the {@link io.georocket.input.Splitter.Result} object
*/
protected Result<XMLChunkMeta> makeResult(int pos) {
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
// append the full stack of start elements (backwards)
List<XMLStartElement> chunkParents = new ArrayList<>();
startElements.descendingIterator().forEachRemaining(e -> {
chunkParents.add(e);
sb.append(e + "\n");
});
// get chunk start in bytes
int chunkStart = sb.toString().getBytes(StandardCharsets.UTF_8).length;
// append current element
byte[] bytes = window.getBytes(mark, pos);
sb.append(new String(bytes, StandardCharsets.UTF_8));
window.advanceTo(pos);
mark = -1;
// get chunk end in bytes
int chunkEnd = chunkStart + bytes.length;
// append the full stack of end elements
startElements.iterator().forEachRemaining(e -> sb.append("\n</" + e.getName() + ">"));
XMLChunkMeta meta = new XMLChunkMeta(chunkParents, chunkStart, chunkEnd);
return new Result<XMLChunkMeta>(sb.toString(), meta);
}
Aggregations