예제 #1
0
 /**
  * @param model Input Model
  * @param lang See {@link com.hp.hpl.jena.rdf.model.Model#read(java.io.InputStream, String,
  *     String)}
  * @param out Serialized model
  * @throws JenaException
  */
 public static void serializeModel(Model model, String lang, OutputStream out)
     throws JenaException {
   if (model == null)
     throw new IllegalArgumentException(
         Messages.getServerString("model.util.model.null")); // $NON-NLS-1$
   if (out == null)
     throw new IllegalArgumentException(
         Messages.getServerString("model.util.outputstream.null")); // $NON-NLS-1$
   // Avoid 'WARN com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter - Namespace prefix 'j.1' is
   // reserved by Jena.'
   for (String prefix : new HashSet<String>(model.getNsPrefixMap().keySet())) {
     model.removeNsPrefix(prefix);
   }
   model.write(out, lang);
 }
예제 #2
0
  /**
   * @param bytes Serialized RDF/XML model
   * @param lang See {@link com.hp.hpl.jena.rdf.model.Model#read(java.io.InputStream, String,
   *     String)}
   * @return Deserialized RDF model
   * @throws JenaException
   */
  public static Model deserializeModel(byte[] bytes, String lang) throws JenaException {
    if (bytes == null)
      throw new IllegalArgumentException(
          Messages.getServerString("model.util.bytes.null")); // $NON-NLS-1$

    return deserializeModel(new ByteArrayInputStream(bytes), lang);
  }
예제 #3
0
  /**
   * @param in Serialized RDF model
   * @param lang See {@link com.hp.hpl.jena.rdf.model.Model#read(java.io.InputStream, String,
   *     String)}
   * @return Deserialized RDF model
   * @throws JenaException
   */
  public static Model deserializeModel(InputStream in, String lang) throws JenaException {
    if (in == null)
      throw new IllegalArgumentException(
          Messages.getServerString("model.util.inputstream.null")); // $NON-NLS-1$

    Model model = ModelUtil.createDefaultModel();

    try {
      model.read(in, null, lang);
    } catch (Throwable t) {
      // Temp ignore - TODO ignore empty stream specifically
      return model;
    }

    return model;
  }