{@inheritDoc}

@see jcifs.Encodable#encode(byte[], int)
344828
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt8(this.timeout, dst, dstIndex);
        dstIndex += 8;
        SMBUtil.writeInt4(this.nameBytes.length, dst, dstIndex);
        dstIndex += 4;

        dst[ dstIndex ] = (byte) ( this.timeoutSpecified ? 0x1 : 0x0 );
        dstIndex++;
        dstIndex++; // Padding

        System.arraycopy(this.nameBytes, 0, dst, dstIndex, this.nameBytes.length);
        dstIndex += this.nameBytes.length;

        return dstIndex - start;
    }
499875
public final String encode(byte[] bytes, int off, int len) {
    checkNotNull(bytes);
    checkPositionIndexes(off, off + len, bytes.length);
    CharOutput result = stringBuilderOutput(maxEncodedSize(len));
    ByteOutput byteOutput = encodingStream(result);
    try {
      for (int i = 0; i < len; i++) {
        byteOutput.write(bytes[off + i]);
      }
      byteOutput.close();
    } catch (IOException impossible) {
      throw new AssertionError("impossible");
    }
    return result.toString();
  }
1327775
public final ByteArrayOutputStream encode() throws IOException
    {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        buffer.write(type);
        buffer.write(clientId);
        buffer.write(clientDestId);
        encode(buffer);

        return buffer;
    }
264601
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;

        SMBUtil.writeInt4(this.capabilities, dst, dstIndex);
        dstIndex += 4;

        System.arraycopy(this.clientGuid, 0, dst, dstIndex, 16);
        dstIndex += 16;

        SMBUtil.writeInt2(this.securityMode, dst, dstIndex);
        dstIndex += 2;
        SMBUtil.writeInt2(this.dialects.length, dst, dstIndex);
        dstIndex += 2;

        for ( int dialect : this.dialects ) {
            SMBUtil.writeInt2(dialect, dst, dstIndex);
            dstIndex += 2;
        }

        return dstIndex - start;
    }
52542
@Override
    protected void encode(ByteArrayOutputStream buffer) throws IOException
    {
        buffer.write(UtilConversion.shortToByteArray(entityId));
        final Collection<M> keys = actions.keySet();

        // Fill the data
        buffer.write((byte) keys.size());
        for (final M key : keys)
        {
            encode(buffer, key);
        }
    }
1372136
public static byte[] encode(byte[] ba, int offset, long v) {
    ba[offset + 0] = (byte) (v >>> 56);
    ba[offset + 1] = (byte) (v >>> 48);
    ba[offset + 2] = (byte) (v >>> 40);
    ba[offset + 3] = (byte) (v >>> 32);
    ba[offset + 4] = (byte) (v >>> 24);
    ba[offset + 5] = (byte) (v >>> 16);
    ba[offset + 6] = (byte) (v >>> 8);
    ba[offset + 7] = (byte) (v >>> 0);
    return ba;
  }
815825
private static void encodeInteger(ByteBuf out, int mask, int n, long i) {
        assert n >= 0 && n <= 8 : "N: " + n;
        int nbits = 0xFF >>> (8 - n);
        if (i < nbits) {
            out.writeByte((int) (mask | i));
        } else {
            out.writeByte(mask | nbits);
            long length = i - nbits;
            for (; (length & ~0x7F) != 0; length >>>= 7) {
                out.writeByte((int) ((length & 0x7F) | 0x80));
            }
            out.writeByte((int) length);
        }
    }
297892
@Override
	public ByteArray encodeAsByteArray() {
		if(message.isEmpty()) return ByteArray.EMPTY_BYTE_ARRAY;

		return new ByteArray(message.getBytes(CHARSET));
	}
835505
public byte[] encode() {
        byte[] bytes;
        switch (sizeOf(value)) {
            case 1:
                return new byte[]{(byte) value};
            case 3:
                bytes = new byte[3];
                bytes[0] = (byte) 253;
                Utils.uint16ToByteArrayLE((int) value, bytes, 1);
                return bytes;
            case 5:
                bytes = new byte[5];
                bytes[0] = (byte) 254;
                Utils.uint32ToByteArrayLE(value, bytes, 1);
                return bytes;
            default:
                bytes = new byte[9];
                bytes[0] = (byte) 255;
                Utils.int64ToByteArrayLE(value, bytes, 1);
                return bytes;
        }
    }
683937
private static byte[] writeInt(int value) throws IOException {
        byte[] b = new byte[4];

        b[0] = (byte) (value & 0x000000FF);
        b[1] = (byte) ((value & 0x0000FF00) >> 8);
        b[2] = (byte) ((value & 0x00FF0000) >> 16);
        b[3] = (byte) ((value & 0xFF000000) >> 24);

        return b;
    }
8283
public static ByteBuffer encode(byte[] input) {
		int pos = input.length + input.length / 3;
		if (pos < 64) pos = 64;
		byte[] out = new byte[pos];
		pos = 0;
		int lineCount = 0;
		for (int i = 0; i < input.length; ++i) {
			byte b = input[i];
			if ((b >= 33 && b <= 60) || (b >= 62 && b <= 126) || ((b == 9 || b == 32) && lineCount < 73 && i < input.length - 1)) {
				if (lineCount == 73) {
					if (pos >= out.length - 4)
						out = increaseBuffer(out, pos);
					out[pos++] = '=';
					out[pos++] = '\r';
					out[pos++] = '\n';
					lineCount = 0;
				} else
					if (pos >= out.length - 1)
						out = increaseBuffer(out, pos);
				out[pos++] = b;
				lineCount++;
				continue;
			}
			// need to encode
			if (lineCount >= 73 - (i < input.length - 1 ? 1 : 0)) {
				if (pos >= out.length - 7)
					out = increaseBuffer(out, pos);
				out[pos++] = '=';
				out[pos++] = '\r';
				out[pos++] = '\n';
				lineCount = 0;
			}
			if (pos >= out.length - 3)
				out = increaseBuffer(out, pos);
			out[pos++] = '=';
			out[pos++] = (byte)StringUtil.encodeHexaDigit((b & 0xF0) >> 4);
			out[pos++] = (byte)StringUtil.encodeHexaDigit(b & 0xF);
			lineCount += 3;
		}
		return ByteBuffer.wrap(out, 0, pos);
	}
689299
public static String encode(byte[] data, int size)
    {
        if (size % 4 != 0) {
            return null;
        }
        StringBuilder builder = new StringBuilder();
        int byteNbr = 0;
        long value = 0;
        while (byteNbr < size) {
            //  Accumulate value in base 256 (binary)
            int d = data[byteNbr++] & 0xff;
            value = value * 256 + d;
            if (byteNbr % 4 == 0) {
                //  Output value in base 85
                int divisor = 85 * 85 * 85 * 85;
                while (divisor != 0) {
                    int index = (int) (value / divisor % 85);
                    builder.append(encoder.charAt(index));
                    divisor /= 85;
                }
                value = 0;
            }
        }
        assert (builder.length() == size * 5 / 4);
        return builder.toString();
    }
203653
public static String encode(byte[] in) {
        if (in == null) {
            return null;
        }
        return encode(in, 0, in.length);
    }
315892
public void encode(ByteBuffer aBuffer, OutputStream aStream)
        throws IOException {
        byte [] buf = getBytes(aBuffer);
        encode(buf, aStream);
    }
202542
public static byte[] encode(final byte[] data) throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        DeflaterOutputStream deflateOut = null;
        try {
            deflateOut = new DeflaterOutputStream(byteOut);
            deflateOut.write(data);
            deflateOut.close();
            byteOut.close();
            return byteOut.toByteArray();
        } finally {
            deflateOut.close();
            byteOut.close();
        }
    }
1368737
public static void encodeSingle(final byte[] input, final int inoff,
                                    final byte[] output, final int outoff) {

        if (input == null) {
            throw new NullPointerException("input");
        }

        if (inoff < 0) {
            throw new IllegalArgumentException("inoff(" + inoff + ") < 0");
        }

        if (inoff >= input.length) {
            throw new IllegalArgumentException(
                "inoff(" + inoff + ") >= input.length(" + input.length + ")");
        }

        encodeSingle(input[inoff], output, outoff);
    }
327216
public static String encodeBytes( byte[] source, int off, int len )
    {
        return encodeBytes( source, off, len, true );
    }