org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl.EObjectInputStream Java Examples

The following examples show how to use org.eclipse.emf.ecore.resource.impl.BinaryResourceImpl.EObjectInputStream. 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: QualifiedName.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Internal low level factory method.
 * @noreference This method is not intended to be referenced by clients.
 * @since 2.4
 */
public static QualifiedName createFromStream(EObjectInputStream eObjectInputStream) throws IOException{
	int segmentCount = eObjectInputStream.readCompressedInt();
	if (segmentCount == 0) {
		return QualifiedName.EMPTY;
	}
	// lowercase QN serialize a 'null' value at index 0 and
	String firstSegment = eObjectInputStream.readSegmentedString();
	boolean lowerCase = false;
	if (firstSegment == null) {
		lowerCase = true;
		// first was null, read another string which is the actual first segment
		firstSegment = eObjectInputStream.readSegmentedString();
		if(firstSegment == null){
			throw new IllegalStateException("Read unexpected first segment from object stream");
		}
	}

	String[] segments = readSegmentArray(eObjectInputStream, segmentCount, firstSegment);
	if (lowerCase) {
		return new QualifiedNameLowerCase(segments);
	} else {
		return new QualifiedName(segments);
	}
}
 
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: QualifiedName.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private static String[] readSegmentArray(EObjectInputStream from, int count, String first) throws IOException {
	String[] segments = new String[count];
	segments[0] = intern(first);
	for (int i = 1; i < count; i++) {
		String segment = from.readSegmentedString();
		if(segment == null){
			throw new IllegalStateException("Read unexpected segment (#" + i + ") from object stream");
		}
		segments[i] = intern(segment);
	}
	return segments;
}
 
Example #4
Source File: BuilderStateFactoryImpl.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public QualifiedName read(EObjectInputStream eObjectInputStream) throws IOException {
	return QualifiedName.createFromStream(eObjectInputStream);
}
 
Example #5
Source File: BuilderStateFactoryImpl.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public URI read(EObjectInputStream eObjectInputStream) throws IOException {
	return eObjectInputStream.readURI();
}