Search in sources :

Example 1 with OwlProperty

use of org.apache.rya.reasoning.OwlProperty in project incubator-rya by apache.

the class SchemaWritable method readFields.

@Override
public void readFields(DataInput in) throws IOException {
    int size = in.readInt();
    if (size < 1)
        throw new Error("De-serializtion failed, count is less than one.");
    byte[] bytes = new byte[size];
    in.readFully(bytes);
    // ObjectInputStream stream = new ObjectInputStream(new ByteArrayInputStream(bytes));
    try (// 
    final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        final ValidatingObjectInputStream vois = new ValidatingObjectInputStream(bais)) // this is how you find classes that you missed in the vois.accept() list, below.
    // { @Override protected void invalidClassNameFound(String className) throws java.io.InvalidClassException {
    // System.out.println("vois.accept(" + className + ".class, ");};};
    {
        // this is a (hopefully) complete list of classes involved in a Schema to be serialized.
        // if a useful class is missing, throws an InvalidClassException.
        // 
        vois.accept(// 
        java.util.ArrayList.class, // 
        org.apache.rya.reasoning.OwlProperty.class, // 
        java.util.HashSet.class, // 
        org.apache.rya.reasoning.OwlClass.class, // 
        org.openrdf.model.impl.URIImpl.class, org.openrdf.model.impl.BNodeImpl.class);
        try {
            Iterable<?> propList = (Iterable<?>) vois.readObject();
            Iterable<?> classList = (Iterable<?>) vois.readObject();
            for (Object p : propList) {
                OwlProperty prop = (OwlProperty) p;
                properties.put(prop.getURI(), prop);
            }
            for (Object c : classList) {
                OwlClass owlClass = (OwlClass) c;
                classes.put(owlClass.getURI(), owlClass);
            }
        } catch (ClassNotFoundException e) {
            throw new Error("While reading a schema object.");
        }
    }
}
Also used : OwlProperty(org.apache.rya.reasoning.OwlProperty) OwlClass(org.apache.rya.reasoning.OwlClass) ValidatingObjectInputStream(org.apache.commons.io.serialization.ValidatingObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with OwlProperty

use of org.apache.rya.reasoning.OwlProperty in project incubator-rya by apache.

the class SchemaWritable method write.

@Override
public void write(DataOutput out) throws IOException {
    ArrayList<OwlProperty> propList = new ArrayList<>(properties.values());
    ArrayList<OwlClass> classList = new ArrayList<>(classes.values());
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    ObjectOutputStream stream = new ObjectOutputStream(bytes);
    stream.writeObject(propList);
    stream.writeObject(classList);
    byte[] arr = bytes.toByteArray();
    stream.close();
    out.writeInt(arr.length);
    out.write(arr);
}
Also used : OwlProperty(org.apache.rya.reasoning.OwlProperty) OwlClass(org.apache.rya.reasoning.OwlClass) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

OwlClass (org.apache.rya.reasoning.OwlClass)2 OwlProperty (org.apache.rya.reasoning.OwlProperty)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ArrayList (java.util.ArrayList)1 ValidatingObjectInputStream (org.apache.commons.io.serialization.ValidatingObjectInputStream)1