-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathCloseableByteArrayOutputStream.java
More file actions
35 lines (31 loc) · 1.03 KB
/
CloseableByteArrayOutputStream.java
File metadata and controls
35 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Copyright 2013-2026 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.compiler;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.CompletableFuture;
/**
* ByteArrayOutputStream that completes a {@link CompletableFuture} when closed.
* The future ties into the JDK compiler's asynchronous behaviour so callers can
* wait for compiler output.
*/
public class CloseableByteArrayOutputStream extends ByteArrayOutputStream {
/**
* Future completed once the stream is closed, signalling closure.
*/
private final CompletableFuture<?> closeFuture = new CompletableFuture<>();
@Override
public void close() {
closeFuture.complete(null);
}
/**
* Return the future that completes when {@link #close()} is called. Callers
* may block on this to synchronise with the compiler's asynchronous
* behaviour.
*
* @return future signalling stream closure
*/
public CompletableFuture<?> closeFuture() {
return closeFuture;
}
}