Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#setBytes()
The following examples show how to use
org.jboss.netty.buffer.ChannelBuffer#setBytes() .
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 |
public void setBytes(int index, byte[] src, int srcIndex, int length) { int componentId = componentId(index); if (index > capacity() - length || srcIndex > src.length - length) { throw new IndexOutOfBoundsException("Too many bytes to read - needs " + (index + length) + " or " + (srcIndex + length) + ", maximum is " + capacity() + " or " + src.length); } int i = componentId; while (length > 0) { ChannelBuffer s = components[i]; int adjustment = indices[i]; int localLength = Math.min(length, s.capacity() - (index - adjustment)); s.setBytes(index - adjustment, src, srcIndex, localLength); index += localLength; srcIndex += localLength; length -= localLength; i ++; } }
Example 2
Source File: CompositeChannelBuffer.java From simple-netty-source with Apache License 2.0 | 6 votes |
public void setBytes(int index, ByteBuffer src) { int componentId = componentId(index); int limit = src.limit(); int length = src.remaining(); if (index > capacity() - length) { throw new IndexOutOfBoundsException("Too many bytes to be written - Needs " + (index + length) + ", maximum is " + capacity()); } int i = componentId; try { while (length > 0) { ChannelBuffer s = components[i]; int adjustment = indices[i]; int localLength = Math.min(length, s.capacity() - (index - adjustment)); src.limit(src.position() + localLength); s.setBytes(index - adjustment, src); index += localLength; length -= localLength; i ++; } } finally { src.limit(limit); } }
Example 3
Source File: CompositeChannelBuffer.java From simple-netty-source with Apache License 2.0 | 6 votes |
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) { int componentId = componentId(index); if (index > capacity() - length || srcIndex > src.capacity() - length) { throw new IndexOutOfBoundsException("Too many bytes to be written - Needs " + (index + length) + " or " + (srcIndex + length) + ", maximum is " + capacity() + " or " + src.capacity()); } int i = componentId; while (length > 0) { ChannelBuffer s = components[i]; int adjustment = indices[i]; int localLength = Math.min(length, s.capacity() - (index - adjustment)); s.setBytes(index - adjustment, src, srcIndex, localLength); index += localLength; srcIndex += localLength; length -= localLength; i ++; } }
Example 4
Source File: RaopRtpAudioDecryptionHandler.java From Android-Airplay-Server with MIT License | 5 votes |
@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 |
public int setBytes(int index, InputStream in, int length) throws IOException { int componentId = componentId(index); if (index > capacity() - length) { throw new IndexOutOfBoundsException("Too many bytes to write - Needs " + (index + length) + ", maximum is " + capacity()); } int i = componentId; int readBytes = 0; do { ChannelBuffer s = components[i]; int adjustment = indices[i]; int localLength = Math.min(length, s.capacity() - (index - adjustment)); int localReadBytes = s.setBytes(index - adjustment, in, localLength); if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } if (localReadBytes == localLength) { index += localLength; length -= localLength; readBytes += localLength; i ++; } else { index += localReadBytes; length -= localReadBytes; readBytes += localReadBytes; } } while (length > 0); return readBytes; }
Example 6
Source File: HeapChannelBuffer.java From simple-netty-source with Apache License 2.0 | 5 votes |
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) { if (dst instanceof HeapChannelBuffer) { getBytes(index, ((HeapChannelBuffer) dst).array, dstIndex, length); } else { dst.setBytes(dstIndex, array, index, length); } }
Example 7
Source File: CompositeChannelBuffer.java From simple-netty-source with Apache License 2.0 | 4 votes |
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { int componentId = componentId(index); if (index > capacity() - length) { throw new IndexOutOfBoundsException("Too many bytes to write - Needs " + (index + length) + ", maximum is " + capacity()); } int i = componentId; int readBytes = 0; do { ChannelBuffer s = components[i]; int adjustment = indices[i]; int localLength = Math.min(length, s.capacity() - (index - adjustment)); int localReadBytes = s.setBytes(index - adjustment, in, localLength); if (localReadBytes == 0) { break; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } if (localReadBytes == localLength) { index += localLength; length -= localLength; readBytes += localLength; i ++; } else { index += localReadBytes; length -= localReadBytes; readBytes += localReadBytes; } } while (length > 0); return readBytes; }