Search in sources :

Example 1 with TextSerializationFactory

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;
}
Also used : TextSerializationFactory(org.locationtech.geogig.storage.text.TextSerializationFactory) ObjectId(org.locationtech.geogig.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) File(java.io.File) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 2 with TextSerializationFactory

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();
}
Also used : TextSerializationFactory(org.locationtech.geogig.storage.text.TextSerializationFactory) RevObject(org.locationtech.geogig.api.RevObject) FeatureInfo(org.locationtech.geogig.api.FeatureInfo) RevFeature(org.locationtech.geogig.api.RevFeature) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with TextSerializationFactory

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();
}
Also used : TextSerializationFactory(org.locationtech.geogig.storage.text.TextSerializationFactory) RevObject(org.locationtech.geogig.api.RevObject) FeatureInfo(org.locationtech.geogig.api.FeatureInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 4 with TextSerializationFactory

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();
}
Also used : TextSerializationFactory(org.locationtech.geogig.storage.text.TextSerializationFactory) RevObject(org.locationtech.geogig.api.RevObject) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 TextSerializationFactory (org.locationtech.geogig.storage.text.TextSerializationFactory)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 RevObject (org.locationtech.geogig.api.RevObject)3 FeatureInfo (org.locationtech.geogig.api.FeatureInfo)2 RevFeature (org.locationtech.geogig.api.RevFeature)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 RevCommit (org.locationtech.geogig.api.RevCommit)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1