Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.eyrie.remctl.core;
 
Represents a remctl command token. This token is sent by a client to a server to run a command on the server.
 
public class RemctlCommandToken extends RemctlMessageToken {
    
Whether the keep-alive flag is set on the message.
    boolean keepalive;

    
The arguments of the command.
    private String args[];

    
Construct a command token with the given keep-alive status and command arguments.

Parameters:
keepalive Whether to keep the connection open after completing this command
args Command and arguments
Throws:
RemctlException Invalid argument to constructor
    public RemctlCommandToken(final boolean keepalivefinal String... argsthrows RemctlException {
        super(2);
        this. = keepalive;
        this. = Arrays.copyOf(argsargs.length);
    }

    
Determine the length of this command message token.

Returns:
The length of the wire representation of the data payload of this command token
    @Override
    int length() {
        int size = 1 + 1 + 4;
        for (String arg : this.) {
            size += 4 + arg.length();
        }
        return size;
    }

    
Write the wire representation of this command token to the provided output stream.

Parameters:
output Output stream to which to write the encoded token
Throws:
java.io.IOException On errors writing to the output stream
    @Override
    protected void writeData(final DataOutputStream outputthrows IOException {
        output.writeByte(this. ? 1 : 0);
        output.writeByte(0);
        output.writeInt(this..length);
        for (String arg : this.) {
            // FIXME these calls assume one byte per character, and we should
            // support UTF-8
            output.writeInt(arg.length());
            output.writeBytes(arg);
        }
    }
    @Override
        return .;
    }

    

Returns:
the keepalive
    public boolean isKeepalive() {
        return this.;
    }

    

Parameters:
keepalive the keepalive to set
    public void setKeepalive(final boolean keepalive) {
        this. = keepalive;
    }

    
Return a copy of the arguments used in the command.

Returns:
the args the arguments
    public String[] getArgs() {
        return Arrays.copyOf(this..);
    }
New to GrepCode? Check out our FAQ X