{@inheritDoc}

@see jcifs.Encodable#encode(byte[], int)
969337
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        dst[ dstIndex ] = (byte) ( this.replaceIfExists ? 1 : 0 );
        dstIndex += 8; // 7 Reserved
        dstIndex += 8; // RootDirectory = 0

        byte[] nameBytes = this.fileName.getBytes(StandardCharsets.UTF_16LE);

        SMBUtil.writeInt4(nameBytes.length, dst, dstIndex);
        dstIndex += 4;

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

        return dstIndex - start;
    }
689942
public void encodeNBitUnsignedInteger(int b, int n) throws IOException {
		if (b < 0 || n < 0) {
			throw new IllegalArgumentException(
					"Negative value as unsigned integer!");
		}
		assert (b >= 0);
		assert (n >= 0);

		if (n == 0) {
			// 0 bytes
		} else if (n < 9) {
			// 1 byte
			encode(b & 0xff);
		} else if (n < 17) {
			// 2 bytes
			encode(b & 0x00ff);
			encode((b & 0xff00) >> 8);
		} else if (n < 25) {
			// 3 bytes
			encode(b & 0x0000ff);
			encode((b & 0x00ff00) >> 8);
			encode((b & 0xff0000) >> 16);
		} else if (n < 33) {
			// 4 bytes
			encode(b & 0x000000ff);
			encode((b & 0x0000ff00) >> 8);
			encode((b & 0x00ff0000) >> 16);
			encode((b & 0xff000000) >> 24);
		} else {
			throw new RuntimeException(
					"Currently not more than 4 Bytes allowed for NBitUnsignedInteger!");
		}
	}
686148
@Override
    protected final void encode(final ChannelHandlerContext ctx, final JNRPEResponse msg, final ByteBuf out) {
        out.writeBytes(msg.toByteArray());
    }
767378
public void encode(DerOutputStream out, byte tag) throws IOException {
        byte[] bytes = id.toByteArray();
        int excessBits = bytes.length*8 - id.length();

        out.write(tag);
        out.putLength(bytes.length + 1);

        out.write(excessBits);
        out.write(bytes);
    }
661319
@Override
  public byte[] encode(final T writable) {
    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
         final DataOutputStream dos = new DataOutputStream(bos)) {
      writable.write(dos);
      return bos.toByteArray();
    } catch (final IOException ex) {
      LOG.log(Level.SEVERE, "Cannot encode object " + writable, ex);
      throw new RemoteRuntimeException(ex);
    }
  }
303449
public static byte[] encode(byte[] in) {
        return org.apache.commons.codec.binary.Base64.encodeBase64(in);
    }
787755
@Override
	public ByteArray encodeAsByteArray() throws IOException {
		final int size = messages.size();
		if(size == 0) return ByteArray.EMPTY_BYTE_ARRAY;

		AoByteArrayOutputStream bout = new AoByteArrayOutputStream();
		try {
			try (DataOutputStream out = new DataOutputStream(bout)) {
				out.writeInt(size);
				int count = 0;
				for(Message message : messages) {
					count++;
					ByteArray byteArray = message.encodeAsByteArray();
					final int capacity = byteArray.size;
					out.writeByte(message.getMessageType().getTypeByte());
					out.writeInt(capacity);
					out.write(byteArray.array, 0, capacity);
				}
				if(count != size) throw new ConcurrentModificationException();
			}
		} finally {
			bout.close();
		}
		return new ByteArray(bout.getInternalByteArray(), bout.size());
	}
316289
public static String encodeB(byte[] bytes) {
		StringBuilder sb = new StringBuilder();

		int idx = 0;
		final int end = bytes.length;
		for (; idx < end - 2; idx += 3) {
			int data = (bytes[idx] & 0xff) << 16 | (bytes[idx + 1] & 0xff) << 8 | bytes[idx + 2] & 0xff;
			sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]);
			sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]);
			sb.append((char) BASE64_TABLE[data >> 6 & 0x3f]);
			sb.append((char) BASE64_TABLE[data & 0x3f]);
		}

		if (idx == end - 2) {
			int data = (bytes[idx] & 0xff) << 16 | (bytes[idx + 1] & 0xff) << 8;
			sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]);
			sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]);
			sb.append((char) BASE64_TABLE[data >> 6 & 0x3f]);
			sb.append((char) BASE64_PAD);

		} else if (idx == end - 1) {
			int data = (bytes[idx] & 0xff) << 16;
			sb.append((char) BASE64_TABLE[data >> 18 & 0x3f]);
			sb.append((char) BASE64_TABLE[data >> 12 & 0x3f]);
			sb.append((char) BASE64_PAD);
			sb.append((char) BASE64_PAD);
		}

		return sb.toString();
	}
293281
private static void encodeCopy(ByteBuf out, int offset, int length) {
        while (length >= 68) {
            encodeCopyWithOffset(out, offset, 64);
            length -= 64;
        }

        if (length > 64) {
            encodeCopyWithOffset(out, offset, 60);
            length -= 60;
        }

        encodeCopyWithOffset(out, offset, length);
    }
234570
public void encodeType(byte[] frame, int[] limits) {
    setByte(frame, limits, (byte)PRIMITIVE);
    setByte(frame, limits, (byte)typeCode);
  }
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;
    }
535001
@Override
    public int encode ( byte[] dst, int dstIndex ) {
        int start = dstIndex;

        SMBUtil.writeInt2(this.hashAlgos != null ? this.hashAlgos.length : 0, dst, dstIndex);
        SMBUtil.writeInt2(this.salt != null ? this.salt.length : 0, dst, dstIndex + 2);
        dstIndex += 4;

        if ( this.hashAlgos != null ) {
            for ( int hashAlgo : this.hashAlgos ) {
                SMBUtil.writeInt2(hashAlgo, dst, dstIndex);
                dstIndex += 2;
            }
        }

        if ( this.salt != null ) {
            System.arraycopy(this.salt, 0, dst, dstIndex, this.salt.length);
            dstIndex += this.salt.length;
        }

        return dstIndex - start;
    }
324795
public static String encodeBytes(byte[] source, int off, int len) {
        return encodeBytes(source, off, len, NO_OPTIONS);
    }
1346238
@Deprecated
    public static byte[] encodeToBytes(byte[] bytes)
    {
        try {
            char[] chars = Base64.encode(bytes);
            String string = new String(chars);
            return string.getBytes(DEFAULT_ENCODING);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
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;
  }
947929
private byte[] encode(byte[] input) throws EncoderException
    {
        if (encoder != null)
        {
            return encoder.encode(input);
        }
        else
        {
            return DEFAULT_CODER.encode(input);
        }
    }
32483
public static byte[] encodeInt(int i) {
		byte[] raw = new byte[4];
		raw[0] = (byte) (i >> 24);
		raw[1] = (byte) (i >> 16);
		raw[2] = (byte) (i >> 8);
		raw[3] = (byte) (i);
		return raw;
	}