--- old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.graphio/src/org/graalvm/graphio/GraphOutput.java 2019-03-12 08:10:24.767891891 +0100 +++ new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.graphio/src/org/graalvm/graphio/GraphOutput.java 2019-03-12 08:10:24.407889561 +0100 @@ -28,6 +28,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.ByteBuffer; import java.nio.channels.WritableByteChannel; import java.util.Collections; import java.util.Map; @@ -37,8 +38,9 @@ * * @param the type of graph this instance handles * @param the type of methods this instance handles + * @since 1.0 a {@link WritableByteChannel} is implemented */ -public final class GraphOutput implements Closeable { +public final class GraphOutput implements Closeable, WritableByteChannel { private final GraphProtocol printer; private GraphOutput(GraphProtocol p) { @@ -107,6 +109,30 @@ } /** + * Checks if the {@link GraphOutput} is open. + * + * @return true if the {@link GraphOutput} is open. + * @since 1.0 + */ + @Override + public boolean isOpen() { + return printer.isOpen(); + } + + /** + * Writes raw bytes into {@link GraphOutput}. + * + * @param src the bytes to write + * @return the number of bytes written, possibly zero + * @throws IOException in case of IO error + * @since 1.0 + */ + @Override + public int write(ByteBuffer src) throws IOException { + return printer.write(src); + } + + /** * Builder to configure and create an instance of {@link GraphOutput}. * * @param the type of the (root element of) graph @@ -121,6 +147,7 @@ private GraphBlocks blocks = DefaultGraphBlocks.empty(); private int major = 4; private int minor = 0; + private boolean embeddedGraphOutput; Builder(GraphStructure structure) { this.structure = structure; @@ -143,6 +170,22 @@ } /** + * Sets {@link GraphOutput} as embedded. The embedded {@link GraphOutput} shares + * {@link WritableByteChannel channel} with another already open non parent + * {@link GraphOutput}. The embedded {@link GraphOutput} flushes data after each + * {@link GraphOutput#print print}, {@link GraphOutput#beginGroup beginGroup} and + * {@link GraphOutput#endGroup endGroup} call. + * + * @param embedded if {@code true} the builder creates an embedded {@link GraphOutput} + * @return this builder + * @since 1.0 + */ + public Builder embedded(boolean embedded) { + this.embeddedGraphOutput = embedded; + return this; + } + + /** * Associates different implementation of types. * * @param graphTypes implementation of types and enum recognition @@ -226,7 +269,7 @@ private GraphOutput buildImpl(ElementsAndLocations e, WritableByteChannel channel) throws IOException { // @formatter:off ProtocolImpl p = new ProtocolImpl<>( - major, minor, structure, types, blocks, + major, minor, embeddedGraphOutput, structure, types, blocks, e == null ? null : e.elements, e == null ? null : e.locations, channel );