RemoteControlWriter.java revision 398ee59bebad6835dab57b60157eff16d511709e
1/*******************************************************************************
2 * Copyright (c) 2009, 2015 Mountainminds GmbH & Co. KG and Contributors
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *    Marc R. Hoffmann - initial API and implementation
10 *
11 *******************************************************************************/
12package org.jacoco.core.runtime;
13
14import java.io.IOException;
15import java.io.OutputStream;
16
17import org.jacoco.core.data.ExecutionDataWriter;
18
19/**
20 * {@link ExecutionDataWriter} with commands added for runtime remote control.
21 */
22public class RemoteControlWriter extends ExecutionDataWriter implements
23		IRemoteCommandVisitor {
24
25	/** Block identifier to confirm successful command execution. */
26	public static final byte BLOCK_CMDOK = 0x20;
27
28	/** Block identifier for dump command */
29	public static final byte BLOCK_CMDDUMP = 0x40;
30
31	/**
32	 * Creates a new writer based on the given output stream.
33	 *
34	 * @param output
35	 *            stream to write commands to
36	 * @throws IOException
37	 *             if the header can't be written
38	 */
39	public RemoteControlWriter(final OutputStream output) throws IOException {
40		super(output);
41	}
42
43	/**
44	 * Sends a confirmation that a commands has been successfully executed and
45	 * the response is completed.
46	 *
47	 * @throws IOException
48	 *             in case of problems with the remote connection
49	 */
50	public void sendCmdOk() throws IOException {
51		out.writeByte(RemoteControlWriter.BLOCK_CMDOK);
52	}
53
54	public void visitDumpCommand(final boolean dump, final boolean reset)
55			throws IOException {
56		out.writeByte(RemoteControlWriter.BLOCK_CMDDUMP);
57		out.writeBoolean(dump);
58		out.writeBoolean(reset);
59	}
60
61}
62