@Override public OccurrenceIF makeOccurrence(TopicIF topic, TopicIF occurs_type, Reader value, long length, LocatorIF datatype) { if (topic == null) throw new NullPointerException(MSG_TOPIC_NOT_NULL); if (occurs_type == null) throw new NullPointerException(MSG_OCCURRENCE_TYPE_NOT_NULL); if (value == null) throw new NullPointerException(MSG_OCCURRENCE_VALUE_NOT_NULL); if (datatype == null) throw new NullPointerException(MSG_OCCURRENCE_DATATYPE_NOT_NULL); CrossTopicMapException.check(topic, this.tm); CrossTopicMapException.check(occurs_type, this.tm); OccurrenceIF occurs = new Occurrence(tm); ((Topic)topic).addOccurrence(occurs); occurs.setType(occurs_type); occurs.setReader(value, length, datatype); return occurs; }
@Override public OccurrenceIF makeOccurrence(TopicIF topic, TopicIF occurs_type, Reader value, long length, LocatorIF datatype) { if (topic == null) throw new NullPointerException(MSG_TOPIC_NOT_NULL); if (occurs_type == null) throw new NullPointerException(MSG_OCCURRENCE_TYPE_NOT_NULL); if (value == null) throw new NullPointerException(MSG_OCCURRENCE_VALUE_NOT_NULL); if (datatype == null) throw new NullPointerException(MSG_OCCURRENCE_DATATYPE_NOT_NULL); CrossTopicMapException.check(topic, this.tm); CrossTopicMapException.check(occurs_type, this.tm); OccurrenceIF occurs = new Occurrence(txn); ((Topic)topic).addOccurrence(occurs); occurs.setType(occurs_type); occurs.setReader(value, length, datatype); return occurs; }
/** * INTERNAL: Copies the occurrence value and datatype from the * source topic to the target topic. * * @since 4.0 */ public static void copyOccurrenceData(OccurrenceIF target, OccurrenceIF source) { if (source.getLength() > DataTypes.SIZE_THRESHOLD) { Reader r = source.getReader(); try { target.setReader(r, source.getLength(), source.getDataType()); } catch (Exception e) { try { r.close(); } catch (Exception e2) { } throw new OntopiaRuntimeException(e); } } else { target.setValue(source.getValue(), source.getDataType()); } }
public void _testBinaryReader() throws Exception { // read file and store in occurrence String file = TestFileUtils.getTestInputFile("various", "blob.gif"); Reader ri = new InputStreamReader(new Base64InputStream(new FileInputStream(file), true), "utf-8"); occurrence.setReader(ri, file.length(), DataTypes.TYPE_BINARY); assertTrue("Occurrence datatype is incorrect", Objects.equals(DataTypes.TYPE_BINARY, occurrence.getDataType())); // read and decode occurrence content Reader ro = occurrence.getReader(); assertTrue("Reader value is null", ro != null); InputStream in = new Base64InputStream(new ReaderInputStream(ro, "utf-8"), false); try { OutputStream out = new FileOutputStream("/tmp/blob.gif"); try { IOUtils.copy(in, out); } finally { out.close(); } } finally { in.close(); } }
Reader ri = new FileReader(filein); try { occurrence.setReader(ri, inlen, DataTypes.TYPE_BINARY); } finally { try { ri.close(); } catch (Exception e) { e.printStackTrace(); };
public void testNonURILocator() { try { occurrence.setLocator(new GenericLocator("URG", "l/e")); fail("non URI-locator could be set"); } catch (ConstraintViolationException e) { } try { occurrence.setValue("foo", new GenericLocator("URG", "l/e")); fail("non URI datatype could be set"); } catch (ConstraintViolationException e) { } try { occurrence.setReader(new StringReader("foo"), 3, new GenericLocator("URG", "l/e")); fail("non URI datatype could be set"); } catch (ConstraintViolationException e) { } }