Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#getBytes()

The following examples show how to use org.jboss.netty.buffer.ChannelBuffer#getBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositeChannelBuffer.java    From simple-netty-source with Apache License 2.0 6 votes vote down vote up
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
    if (index > capacity() - length || dstIndex > dst.capacity() - length) {
        throw new IndexOutOfBoundsException("Too many bytes to be read - Needs "
                + (index + length) + " or " + (dstIndex + length) + ", maximum is "
                + capacity() + " or " + dst.capacity());
    }
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index must be >= 0");
    }
    if (length == 0) {
        return;
    }
    int i = componentId(index);
    while (length > 0) {
        ChannelBuffer s = components[i];
        int adjustment = indices[i];
        int localLength = Math.min(length, s.capacity() - (index - adjustment));
        s.getBytes(index - adjustment, dst, dstIndex, localLength);
        index += localLength;
        dstIndex += localLength;
        length -= localLength;
        i ++;
    }
}
 
Example 2
Source File: CompositeChannelBuffer.java    From simple-netty-source with Apache License 2.0 6 votes vote down vote up
public void getBytes(int index, OutputStream out, int length)
        throws IOException {
    if (index > capacity() - length) {
        throw new IndexOutOfBoundsException("Too many bytes to be read - needs "
                + (index + length) + ", maximum of " + capacity());
    }
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index must be >= 0");
    }
    if (length == 0) {
        return;
    }
    int i = componentId(index);
    while (length > 0) {
        ChannelBuffer s = components[i];
        int adjustment = indices[i];
        int localLength = Math.min(length, s.capacity() - (index - adjustment));
        s.getBytes(index - adjustment, out, localLength);
        index += localLength;
        length -= localLength;
        i ++;
    }
}
 
Example 3
Source File: CompositeChannelBuffer.java    From simple-netty-source with Apache License 2.0 6 votes vote down vote up
private void copyTo(int index, int length, int componentId, ChannelBuffer dst) {
    int dstIndex = 0;
    int i = componentId;

    while (length > 0) {
        ChannelBuffer s = components[i];
        int adjustment = indices[i];
        int localLength = Math.min(length, s.capacity() - (index - adjustment));
        s.getBytes(index - adjustment, dst, dstIndex, localLength);
        index += localLength;
        dstIndex += localLength;
        length -= localLength;
        i ++;
    }

    dst.writerIndex(dst.capacity());
}
 
Example 4
Source File: RaopRtpAudioDecryptionHandler.java    From Android-Airplay-Server with MIT License 5 votes vote down vote up
@Override
protected synchronized Object decode(final ChannelHandlerContext ctx, final Channel channel, final Object msg)
	throws Exception {
	
	//check the message type
	if (msg instanceof RaopRtpPacket.Audio) {
		final RaopRtpPacket.Audio audioPacket = (RaopRtpPacket.Audio)msg;
		final ChannelBuffer audioPayload = audioPacket.getPayload();

		/* Cipher is restarted for every packet. We simply overwrite the
		 * encrypted data with the corresponding plain text
		 */
		aesCipher.init(Cipher.DECRYPT_MODE, m_aesKey, m_aesIv);
		
		for(int i = 0; (i + 16) <= audioPayload.capacity(); i += 16) {
			byte[] block = new byte[16];//buffer for decrypting the data
			//copy the bytes to the buffer
			audioPayload.getBytes(i, block);
			//decrypt the 16 bytes block
			block = aesCipher.update(block);
			//set it back to the channel
			audioPayload.setBytes(i, block);
		}
	}

	return msg;
}
 
Example 5
Source File: CompositeChannelBuffer.java    From simple-netty-source with Apache License 2.0 5 votes vote down vote up
public void getBytes(int index, byte[] dst, int dstIndex, int length) {
    if (index > capacity() - length || dstIndex > dst.length - length) {
        throw new IndexOutOfBoundsException("Too many bytes to read - Needs "
                + (index + length) + ", maximum is " + capacity() + " or "
                + dst.length);
    }
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index must be >= 0");
    }
    if (length == 0) {
        return;
    }

    int componentId = componentId(index);

    int i = componentId;
    while (length > 0) {
        ChannelBuffer s = components[i];
        int adjustment = indices[i];
        int localLength = Math.min(length, s.capacity() - (index - adjustment));
        s.getBytes(index - adjustment, dst, dstIndex, localLength);
        index += localLength;
        dstIndex += localLength;
        length -= localLength;
        i ++;
    }
}
 
Example 6
Source File: CompositeChannelBuffer.java    From simple-netty-source with Apache License 2.0 5 votes vote down vote up
public void getBytes(int index, ByteBuffer dst) {
    int componentId = componentId(index);
    int limit = dst.limit();
    int length = dst.remaining();
    if (index > capacity() - length) {
        throw new IndexOutOfBoundsException("Too many bytes to be read - Needs "
                + (index + length) + ", maximum is " + capacity());
    }
    if (index < 0) {
        throw new IndexOutOfBoundsException("Index must be >= 0");
    }
    int i = componentId;
    try {
        while (length > 0) {
            ChannelBuffer s = components[i];
            int adjustment = indices[i];
            int localLength = Math.min(length, s.capacity() - (index - adjustment));
            dst.limit(dst.position() + localLength);
            s.getBytes(index - adjustment, dst);
            index += localLength;
            length -= localLength;
            i ++;
        }
    } finally {
        dst.limit(limit);
    }
}
 
Example 7
Source File: HeapChannelBuffer.java    From simple-netty-source with Apache License 2.0 5 votes vote down vote up
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
    if (src instanceof HeapChannelBuffer) {
        setBytes(index, ((HeapChannelBuffer) src).array, srcIndex, length);
    } else {
        src.getBytes(srcIndex, array, index, length);
    }
}