com.alachisoft.ncache.client.internal.command.InitialCommandBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
package com.alachisoft.ncache.client.internal.command;
import com.alachisoft.ncache.client.internal.communication.Connection;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.alachisoft.ncache.runtime.util.HelperFxn;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public abstract class InitialCommandBase extends Command{
@Override
protected void serializeCommand() {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
///Write discarding buffer that socketserver reads
byte[] discardingBuffer = new byte[20];
stream.write(discardingBuffer, 0, discardingBuffer.length);
//Writes a section for acknowledgment buffer.
byte[] acknowledgementBuffer = (getSupportsAacknowledgement() && inquiryEnabled) ? new byte[20] : new byte[0];
stream.write(acknowledgementBuffer, 0, acknowledgementBuffer.length);
// Writes a section for the command size.
byte[] size = new byte[Connection.CmdSizeHolderBytesCount];
stream.write(size, 0, size.length);
//Writes the command.
try {
serializeCommandInternal(stream);
} catch (IOException ignored) {
}
//All buffers acknowledgement/discarded/size will be using byte[] commandBytes
// As stream in java has no way to set its Position
commandBytes = stream.toByteArray();
//lenght calculation of command
int messageLen;
messageLen = stream.size() - (size.length + acknowledgementBuffer.length + discardingBuffer.length);
size = String.valueOf(messageLen).getBytes(StandardCharsets.UTF_8);
//copy length at position filled dummy previously
int offset=acknowledgementBuffer.length + discardingBuffer.length;
System.arraycopy(size, 0, commandBytes, offset, size.length );
}
@Override
public int getAcknowledgementOffset()
{
return 20;
}
}