RemoteControlWriter.java

    1/*******************************************************************************
    2 * Copyright (c) 2009, 2010 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 * 
   22 * @author Marc R. Hoffmann
   23 * @version 0.4.1.20101007204400
   24 */
   25public class RemoteControlWriter extends ExecutionDataWriter implements
   26        IRemoteCommandVisitor {
   27
   28    /** Block identifier to confirm successful command execution. */
   29    public static final byte BLOCK_CMDOK = 0x20;
   30
   31    /** Block identifier for dump command */
   32    public static final byte BLOCK_CMDDUMP = 0x40;
   33
   34    /**
   35     * Creates a new writer based on the given output stream.
   36     * 
   37     * @param output
   38     *            stream to write commands to
   39     * @throws IOException
   40     *             if the header can't be written
   41     */
   42    public RemoteControlWriter(final OutputStream output) throws IOException {
   43        super(output);
   44    }
   45
   46    /**
   47     * Sends a confirmation that a commands has been successfully executed and
   48     * the response is completed.
   49     */
   50    public void sendCmdOk() {
   51        try {
   52            out.writeByte(RemoteControlWriter.BLOCK_CMDOK);
   53        } catch (final IOException e) {
   54            throw new RuntimeException(e);
   55        }
   56    }
   57
   58    public void visitDumpCommand(final boolean dump, final boolean reset) {
   59        try {
   60            out.writeByte(RemoteControlWriter.BLOCK_CMDDUMP);
   61            out.writeBoolean(dump);
   62            out.writeBoolean(reset);
   63        } catch (final IOException e) {
   64            throw new RuntimeException(e);
   65        }
   66    }
   67
   68}