Java Code Examples for org.apache.flink.core.memory.DataOutputViewStreamWrapper#close()

The following examples show how to use org.apache.flink.core.memory.DataOutputViewStreamWrapper#close() . 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: StringValueSerializationTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static void testSerialization(String[] values) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
	DataOutputViewStreamWrapper serializer = new DataOutputViewStreamWrapper(baos);
	
	for (String value : values) {
		StringValue sv = new StringValue(value);
		sv.write(serializer);
	}
	
	serializer.close();
	baos.close();
	
	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	DataInputViewStreamWrapper deserializer = new DataInputViewStreamWrapper(bais);
	
	int num = 0;
	while (bais.available() > 0) {
		StringValue deser = new StringValue();
		deser.read(deserializer);
		
		assertEquals("DeserializedString differs from original string.", values[num], deser.getValue());
		num++;
	}
	
	assertEquals("Wrong number of deserialized values", values.length, num);
}
 
Example 2
Source File: IterationEventWithAggregators.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	int num = this.aggNames.length;
	out.writeInt(num);

	ByteArrayOutputStream boas = new ByteArrayOutputStream();
	DataOutputViewStreamWrapper bufferStream = new DataOutputViewStreamWrapper(boas);

	for (int i = 0; i < num; i++) {
		// aggregator name and type
		out.writeUTF(this.aggNames[i]);
		out.writeUTF(this.aggregates[i].getClass().getName());

		// aggregator value indirect as a byte array
		this.aggregates[i].write(bufferStream);
		bufferStream.flush();
		byte[] bytes = boas.toByteArray();
		out.writeInt(bytes.length);
		out.write(bytes);
		boas.reset();
	}
	bufferStream.close();
	boas.close();
}
 
Example 3
Source File: StringValueSerializationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public static void testSerialization(String[] values) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
	DataOutputViewStreamWrapper serializer = new DataOutputViewStreamWrapper(baos);
	
	for (String value : values) {
		StringValue sv = new StringValue(value);
		sv.write(serializer);
	}
	
	serializer.close();
	baos.close();
	
	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	DataInputViewStreamWrapper deserializer = new DataInputViewStreamWrapper(bais);
	
	int num = 0;
	while (bais.available() > 0) {
		StringValue deser = new StringValue();
		deser.read(deserializer);
		
		assertEquals("DeserializedString differs from original string.", values[num], deser.getValue());
		num++;
	}
	
	assertEquals("Wrong number of deserialized values", values.length, num);
}
 
Example 4
Source File: IterationEventWithAggregators.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	int num = this.aggNames.length;
	out.writeInt(num);

	ByteArrayOutputStream boas = new ByteArrayOutputStream();
	DataOutputViewStreamWrapper bufferStream = new DataOutputViewStreamWrapper(boas);

	for (int i = 0; i < num; i++) {
		// aggregator name and type
		out.writeUTF(this.aggNames[i]);
		out.writeUTF(this.aggregates[i].getClass().getName());

		// aggregator value indirect as a byte array
		this.aggregates[i].write(bufferStream);
		bufferStream.flush();
		byte[] bytes = boas.toByteArray();
		out.writeInt(bytes.length);
		out.write(bytes);
		boas.reset();
	}
	bufferStream.close();
	boas.close();
}
 
Example 5
Source File: RheemFileOutputFormat.java    From rheem with Apache License 2.0 6 votes vote down vote up
@Override
public void close() throws IOException {
    try {
        this.writer.close();
        DataOutputViewStreamWrapper o = this.outView;
        if (o != null) {
            o.close();
        }
    }
    finally {
        final FSDataOutputStream s = this.stream;
        if (s != null) {
            this.stream = null;
            s.close();
        }
    }
}
 
Example 6
Source File: StringValueSerializationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public static void testSerialization(String[] values) throws IOException {
	ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
	DataOutputViewStreamWrapper serializer = new DataOutputViewStreamWrapper(baos);
	
	for (String value : values) {
		StringValue sv = new StringValue(value);
		sv.write(serializer);
	}
	
	serializer.close();
	baos.close();
	
	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
	DataInputViewStreamWrapper deserializer = new DataInputViewStreamWrapper(bais);
	
	int num = 0;
	while (bais.available() > 0) {
		StringValue deser = new StringValue();
		deser.read(deserializer);
		
		assertEquals("DeserializedString differs from original string.", values[num], deser.getValue());
		num++;
	}
	
	assertEquals("Wrong number of deserialized values", values.length, num);
}
 
Example 7
Source File: IterationEventWithAggregators.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void write(DataOutputView out) throws IOException {
	int num = this.aggNames.length;
	out.writeInt(num);

	ByteArrayOutputStream boas = new ByteArrayOutputStream();
	DataOutputViewStreamWrapper bufferStream = new DataOutputViewStreamWrapper(boas);

	for (int i = 0; i < num; i++) {
		// aggregator name and type
		out.writeUTF(this.aggNames[i]);
		out.writeUTF(this.aggregates[i].getClass().getName());

		// aggregator value indirect as a byte array
		this.aggregates[i].write(bufferStream);
		bufferStream.flush();
		byte[] bytes = boas.toByteArray();
		out.writeInt(bytes.length);
		out.write(bytes);
		boas.reset();
	}
	bufferStream.close();
	boas.close();
}
 
Example 8
Source File: BinaryOutputFormat.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
	try {
		DataOutputViewStreamWrapper o = this.outView;
		if (o != null) {
			o.close();
		}
	}
	finally {
		super.close();
	}
}
 
Example 9
Source File: BinaryOutputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
	try {
		DataOutputViewStreamWrapper o = this.outView;
		if (o != null) {
			o.close();
		}
	}
	finally {
		super.close();
	}
}
 
Example 10
Source File: AbstractSiddhiOperator.java    From flink-siddhi with Apache License 2.0 5 votes vote down vote up
private void checkpointRecordQueueState() throws Exception {
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final DataOutputViewStreamWrapper dataOutputView = new DataOutputViewStreamWrapper(byteArrayOutputStream);
    try {
        snapshotQueueState(this.priorityQueue, dataOutputView);
        this.queuedRecordsState.clear();
        this.queuedRecordsState.add(byteArrayOutputStream.toByteArray());
    } finally {
        dataOutputView.close();
        byteArrayOutputStream.close();
    }
}
 
Example 11
Source File: AbstractSiddhiOperator.java    From bahir-flink with Apache License 2.0 5 votes vote down vote up
private void checkpointRecordQueueState() throws Exception {
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final DataOutputViewStreamWrapper dataOutputView = new DataOutputViewStreamWrapper(byteArrayOutputStream);
    try {
        snapshotQueueState(this.priorityQueue, dataOutputView);
        this.queuedRecordsState.clear();
        this.queuedRecordsState.add(byteArrayOutputStream.toByteArray());
    } finally {
        dataOutputView.close();
        byteArrayOutputStream.close();
    }
}
 
Example 12
Source File: BinaryOutputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void close() throws IOException {
	try {
		DataOutputViewStreamWrapper o = this.outView;
		if (o != null) {
			o.close();
		}
	}
	finally {
		super.close();
	}
}