Java Code Examples for org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl#EObjectOutputStream

The following examples show how to use org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl#EObjectOutputStream . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceStorageWritable.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void writeContents(StorageAwareResource storageAwareResource, OutputStream outputStream)
		throws IOException {
	BinaryResourceImpl.EObjectOutputStream out = new BinaryResourceImpl.EObjectOutputStream(outputStream,
			Collections.emptyMap()) {
		@Override
		public void writeURI(URI uri, String fragment) throws IOException {
			URI fullURI = uri.appendFragment(fragment);
			URI portableURI = storageAwareResource.getPortableURIs().toPortableURI(storageAwareResource, fullURI);
			URI uriToWrite = portableURI == null ? fullURI : portableURI;
			super.writeURI(uriToWrite.trimFragment(), uriToWrite.fragment());
		}

		@Override
		public void saveEObject(InternalEObject internalEObject, BinaryResourceImpl.EObjectOutputStream.Check check)
				throws IOException {
			beforeSaveEObject(internalEObject, this);
			super.saveEObject(internalEObject, check);
			handleSaveEObject(internalEObject, this);
		}
	};
	try {
		out.saveResource(storageAwareResource);
	} finally {
		out.flush();
	}
}
 
Example 2
Source File: QualifiedNameTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testDeserializeAsLowerCase() throws IOException {
	QualifiedName upperCase = QualifiedName.create("A", "B");
	QualifiedName lowerCase = upperCase.toLowerCase();
	
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	EObjectOutputStream out = new BinaryResourceImpl.EObjectOutputStream(bos, Collections.emptyMap());
	upperCase.writeToStream(out);
	lowerCase.writeToStream(out);
	out.flush();
	
	EObjectInputStream in = new BinaryResourceImpl.EObjectInputStream(new ByteArrayInputStream(bos.toByteArray()), Collections.emptyMap());
	QualifiedName readUpperCase = QualifiedName.createFromStream(in);
	QualifiedName readLowerCase = QualifiedName.createFromStream(in);
	assertEquals(QualifiedName.class.getName(), readUpperCase.getClass().getName());
	assertEquals(QualifiedName.class.getName() + "$QualifiedNameLowerCase", readLowerCase.getClass().getName());
	assertEquals(upperCase, readUpperCase);
	assertEquals(lowerCase, readLowerCase);
}
 
Example 3
Source File: BatchLinkableResourceStorageWritable.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Object beforeSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream writable) throws IOException {
  JvmType _xblockexpression = null;
  {
    super.beforeSaveEObject(object, writable);
    JvmType _xifexpression = null;
    if ((object instanceof XComputedTypeReference)) {
      _xifexpression = ((XComputedTypeReference)object).getType();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 4
Source File: BatchLinkableResourceStorageWritable.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void handleSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream out) throws IOException {
  super.handleSaveEObject(object, out);
  DocumentationAdapter documentationAdapter = null;
  JvmIdentifiableMetaData metaDataAdapter = null;
  EList<Adapter> _eAdapters = object.eAdapters();
  for (final Adapter adapter : _eAdapters) {
    {
      if ((adapter instanceof DocumentationAdapter)) {
        documentationAdapter = ((DocumentationAdapter)adapter);
      }
      if ((adapter instanceof JvmIdentifiableMetaData)) {
        metaDataAdapter = ((JvmIdentifiableMetaData)adapter);
      }
    }
  }
  if ((documentationAdapter != null)) {
    out.writeBoolean(true);
    out.writeString(documentationAdapter.getDocumentation());
  } else {
    out.writeBoolean(false);
  }
  if ((metaDataAdapter != null)) {
    out.writeBoolean(true);
    out.writeBoolean(metaDataAdapter.isSynthetic());
  } else {
    out.writeBoolean(false);
  }
}
 
Example 5
Source File: ResourceStorageWritable.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected Object beforeSaveEObject(InternalEObject object, BinaryResourceImpl.EObjectOutputStream writable)
		throws IOException {
	return null;
}
 
Example 6
Source File: ResourceStorageWritable.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void handleSaveEObject(InternalEObject object, BinaryResourceImpl.EObjectOutputStream out)
		throws IOException {
}