use of org.locationtech.geogig.storage.text.TextSerializationFactory in project GeoGig by boundlessgeo.
the class RebaseOp method readSquashCommit.
/**
* Return the commit that is the squashed version of all the commits to apply, reading it from
* the 'squash' file. If the file does not exist (that is, we are not in the middle of a rebase
* with squash operation), returns null
*
* @return
*/
private RevCommit readSquashCommit() {
File file = new File(getRebaseFolder(), "squash");
if (!file.exists()) {
return null;
}
List<String> lines;
try {
lines = Files.readLines(file, Charsets.UTF_8);
} catch (IOException e) {
throw new IllegalStateException("Cannot create squash commit info file");
}
ObjectId id = ObjectId.valueOf(lines.get(0).split("\t")[1].trim());
String commitString = Joiner.on("\n").join(lines.subList(1, lines.size()));
ByteArrayInputStream stream = new ByteArrayInputStream(commitString.getBytes(Charsets.UTF_8));
ObjectReader<RevCommit> reader = new TextSerializationFactory().createCommitReader();
RevCommit revCommit = reader.read(id, stream);
return revCommit;
}
use of org.locationtech.geogig.storage.text.TextSerializationFactory in project GeoGig by boundlessgeo.
the class Patch method toString.
/**
* This method is not intended to serialize the patch, as it misses some needed information. To
* serialize the patch, use the {@link PatchSerializer} class instead. Use this method to show
* patch content in a human-readable format
*/
@Override
public String toString() {
TextSerializationFactory factory = new TextSerializationFactory();
StringBuilder sb = new StringBuilder();
for (FeatureInfo feature : addedFeatures) {
String path = feature.getPath();
sb.append("A\t" + path + "\t" + feature.getFeatureType().getId() + "\n");
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature());
try {
writer.write(revFeature, output);
} catch (IOException e) {
}
sb.append(output.toString());
sb.append('\n');
}
for (FeatureInfo feature : removedFeatures) {
String path = feature.getPath();
sb.append("R\t" + path + "\t" + feature.getFeatureType().getId() + "\n");
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature());
try {
writer.write(revFeature, output);
} catch (IOException e) {
}
sb.append(output.toString());
sb.append('\n');
}
for (FeatureDiff diff : modifiedFeatures) {
sb.append("M\t" + diff.getPath() + /*
* + "\t" + diff.getOldFeatureType().getId().toString()
* + "\t" + diff.getNewFeatureType().getId().toString()
*/
"\n");
sb.append(diff.toString() + "\n");
}
for (FeatureTypeDiff diff : alteredTrees) {
sb.append(featureTypeDiffAsString(diff) + "\n");
}
return sb.toString();
}
use of org.locationtech.geogig.storage.text.TextSerializationFactory in project GeoGig by boundlessgeo.
the class PatchSerializer method write.
public static void write(Writer w, Patch patch) throws IOException {
StringBuilder sb = new StringBuilder();
List<RevFeatureType> featureTypes = patch.getFeatureTypes();
for (RevFeatureType featureType : featureTypes) {
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURETYPE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
writer.write(featureType, output);
sb.append(output.toString());
sb.append('\n');
}
TextSerializationFactory factory = new TextSerializationFactory();
for (FeatureInfo feature : patch.getAddedFeatures()) {
String path = feature.getPath();
sb.append("A\t" + path + "\t" + feature.getFeatureType().getId() + "\n");
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature());
try {
writer.write(revFeature, output);
} catch (IOException e) {
}
sb.append(output.toString());
sb.append('\n');
}
for (FeatureInfo feature : patch.getRemovedFeatures()) {
String path = feature.getPath();
sb.append("R\t" + path + "\t" + feature.getFeatureType().getId() + "\n");
ObjectWriter<RevObject> writer = factory.createObjectWriter(TYPE.FEATURE);
ByteArrayOutputStream output = new ByteArrayOutputStream();
RevFeature revFeature = RevFeatureBuilder.build(feature.getFeature());
try {
writer.write(revFeature, output);
} catch (IOException e) {
}
sb.append(output.toString());
sb.append('\n');
}
for (FeatureDiff diff : patch.getModifiedFeatures()) {
sb.append("M\t" + diff.getPath() + "\t" + diff.getOldFeatureType().getId().toString() + "\t" + diff.getNewFeatureType().getId().toString() + "\n");
sb.append(diff.asText() + "\n");
}
for (FeatureTypeDiff diff : patch.getAlteredTrees()) {
sb.append(diff.toString() + "\n");
}
w.write(sb.toString());
w.flush();
}
use of org.locationtech.geogig.storage.text.TextSerializationFactory in project GeoGig by boundlessgeo.
the class CatObject method _call.
@Override
protected CharSequence _call() {
Preconditions.checkState(object != null);
RevObject revObject = object.get();
TextSerializationFactory factory = new TextSerializationFactory();
ObjectWriter<RevObject> writer = factory.createObjectWriter(revObject.getType());
ByteArrayOutputStream output = new ByteArrayOutputStream();
String s = "id\t" + revObject.getId().toString() + "\n";
OutputStreamWriter streamWriter = new OutputStreamWriter(output, Charsets.UTF_8);
try {
streamWriter.write(s);
streamWriter.flush();
writer.write(revObject, output);
} catch (IOException e) {
throw new IllegalStateException("Cannot print object: " + revObject.getId().toString(), e);
}
return output.toString();
}
Aggregations