< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.graphio/src/org/graalvm/graphio/GraphOutput.java
Print this page
@@ -26,21 +26,23 @@
import java.io.Closeable;
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;
/**
* Instance of output to dump informations about a compiler compilations.
*
* @param <G> the type of graph this instance handles
* @param <M> the type of methods this instance handles
+ * @since 1.0 a {@link WritableByteChannel} is implemented
*/
-public final class GraphOutput<G, M> implements Closeable {
+public final class GraphOutput<G, M> implements Closeable, WritableByteChannel {
private final GraphProtocol<G, ?, ?, ?, ?, M, ?, ?, ?, ?> printer;
private GraphOutput(GraphProtocol<G, ?, ?, ?, ?, M, ?, ?, ?, ?> p) {
this.printer = p;
}
@@ -105,10 +107,34 @@
public void close() {
printer.close();
}
/**
+ * 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 <G> the type of the (root element of) graph
* @param <N> the type of the nodes
* @param <M> the type of the methods
@@ -119,10 +145,11 @@
private GraphTypes types = DefaultGraphTypes.DEFAULT;
private GraphBlocks<G, ?, N> blocks = DefaultGraphBlocks.empty();
private int major = 4;
private int minor = 0;
+ private boolean embeddedGraphOutput;
Builder(GraphStructure<G, N, ?, ?> structure) {
this.structure = structure;
}
@@ -141,10 +168,26 @@
this.minor = minorVersion;
return this;
}
/**
+ * 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<G, N, M> embedded(boolean embedded) {
+ this.embeddedGraphOutput = embedded;
+ return this;
+ }
+
+ /**
* Associates different implementation of types.
*
* @param graphTypes implementation of types and enum recognition
* @return this builder
*/
@@ -224,11 +267,11 @@
}
private <L, P> GraphOutput<G, M> buildImpl(ElementsAndLocations<M, L, P> e, WritableByteChannel channel) throws IOException {
// @formatter:off
ProtocolImpl<G, N, ?, ?, ?, M, ?, ?, ?, ?> 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
);
// @formatter:on
return new GraphOutput<>(p);
< prev index next >