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

The following examples show how to use org.apache.flink.core.memory.DataInputViewStreamWrapper#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: EventWithAggregatorsTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private IterationEventWithAggregators pipeThroughSerialization(IterationEventWithAggregators event) {
	try {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		event.write(new DataOutputViewStreamWrapper(baos));

		byte[] data = baos.toByteArray();
		baos.close();

		DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(new ByteArrayInputStream(data));
		IterationEventWithAggregators newEvent = event.getClass().newInstance();
		newEvent.read(in);
		in.close();

		return newEvent;
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail("Test threw an exception: " + e.getMessage());
		return null;
	}
}
 
Example 2
Source File: EventWithAggregatorsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private IterationEventWithAggregators pipeThroughSerialization(IterationEventWithAggregators event) {
	try {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		event.write(new DataOutputViewStreamWrapper(baos));

		byte[] data = baos.toByteArray();
		baos.close();

		DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(new ByteArrayInputStream(data));
		IterationEventWithAggregators newEvent = event.getClass().newInstance();
		newEvent.read(in);
		in.close();

		return newEvent;
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail("Test threw an exception: " + e.getMessage());
		return null;
	}
}
 
Example 3
Source File: AbstractSiddhiOperator.java    From flink-siddhi with Apache License 2.0 6 votes vote down vote up
private void restoreState() throws Exception {
    LOGGER.info("Restore siddhi state");
    final Iterator<byte[]> siddhiState = siddhiRuntimeState.get().iterator();
    if (siddhiState.hasNext()) {
        // TODO this.siddhiRuntime.restore(siddhiState.next());
    }

    LOGGER.info("Restore queued records state");
    final Iterator<byte[]> queueState = queuedRecordsState.get().iterator();
    if (queueState.hasNext()) {
        final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(queueState.next());
        final DataInputViewStreamWrapper dataInputView = new DataInputViewStreamWrapper(byteArrayInputStream);
        try {
            this.priorityQueue = restoreQueueState(dataInputView);
        } finally {
            dataInputView.close();
            byteArrayInputStream.close();
        }
    }
}
 
Example 4
Source File: AbstractSiddhiOperator.java    From bahir-flink with Apache License 2.0 6 votes vote down vote up
private void restoreState() throws Exception {
    LOGGER.info("Restore siddhi state");
    final Iterator<byte[]> siddhiState = siddhiRuntimeState.get().iterator();
    if (siddhiState.hasNext()) {
        this.siddhiRuntime.restore(siddhiState.next());
    }

    LOGGER.info("Restore queued records state");
    final Iterator<byte[]> queueState = queuedRecordsState.get().iterator();
    if (queueState.hasNext()) {
        final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(queueState.next());
        final DataInputViewStreamWrapper dataInputView = new DataInputViewStreamWrapper(byteArrayInputStream);
        try {
            this.priorityQueue = restoreQueuerState(dataInputView);
        } finally {
            dataInputView.close();
            byteArrayInputStream.close();
        }
    }
}
 
Example 5
Source File: EventWithAggregatorsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private IterationEventWithAggregators pipeThroughSerialization(IterationEventWithAggregators event) {
	try {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		event.write(new DataOutputViewStreamWrapper(baos));

		byte[] data = baos.toByteArray();
		baos.close();

		DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(new ByteArrayInputStream(data));
		IterationEventWithAggregators newEvent = event.getClass().newInstance();
		newEvent.read(in);
		in.close();

		return newEvent;
	}
	catch (Exception e) {
		System.err.println(e.getMessage());
		e.printStackTrace();
		Assert.fail("Test threw an exception: " + e.getMessage());
		return null;
	}
}