Java Code Examples for com.alibaba.dubbo.common.io.Bytes#copyOf()
The following examples show how to use
com.alibaba.dubbo.common.io.Bytes#copyOf() .
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: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 5 votes |
public void write( byte b[], int off, int len ) { if ( ( off < 0 ) || ( off > b.length ) || ( len < 0 ) || ( ( off + len ) > b.length ) || ( ( off + len ) < 0 ) ) throw new IndexOutOfBoundsException(); if ( len == 0 ) return; int newcount = count + len; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); System.arraycopy( b, off, buffer, count, len ); count = newcount; }
Example 2
Source File: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 5 votes |
public void write( byte b[], int off, int len ) { if ( ( off < 0 ) || ( off > b.length ) || ( len < 0 ) || ( ( off + len ) > b.length ) || ( ( off + len ) < 0 ) ) throw new IndexOutOfBoundsException(); if ( len == 0 ) return; int newcount = count + len; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); System.arraycopy( b, off, buffer, count, len ); count = newcount; }
Example 3
Source File: RandomAccessByteArrayOutputStream.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void write( byte b[], int off, int len ) { if ( ( off < 0 ) || ( off > b.length ) || ( len < 0 ) || ( ( off + len ) > b.length ) || ( ( off + len ) < 0 ) ) throw new IndexOutOfBoundsException(); if ( len == 0 ) return; int newcount = count + len; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); System.arraycopy( b, off, buffer, count, len ); count = newcount; }
Example 4
Source File: RandomAccessByteArrayOutputStream.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void write( int b ) { int newcount = count + 1; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); buffer[count] = ( byte ) b; count = newcount; }
Example 5
Source File: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 5 votes |
public void write( byte b[], int off, int len ) { if ( ( off < 0 ) || ( off > b.length ) || ( len < 0 ) || ( ( off + len ) > b.length ) || ( ( off + len ) < 0 ) ) throw new IndexOutOfBoundsException(); if ( len == 0 ) return; int newcount = count + len; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); System.arraycopy( b, off, buffer, count, len ); count = newcount; }
Example 6
Source File: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 5 votes |
public void write( int b ) { int newcount = count + 1; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); buffer[count] = ( byte ) b; count = newcount; }
Example 7
Source File: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 5 votes |
public void write( int b ) { int newcount = count + 1; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); buffer[count] = ( byte ) b; count = newcount; }
Example 8
Source File: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 5 votes |
public void write( int b ) { int newcount = count + 1; if ( newcount > buffer.length ) buffer = Bytes.copyOf( buffer, Math.max( buffer.length << 1, newcount ) ); buffer[count] = ( byte ) b; count = newcount; }
Example 9
Source File: RandomAccessByteArrayOutputStream.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public void write(byte b[], int off, int len) { if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) throw new IndexOutOfBoundsException(); if (len == 0) return; int newcount = count + len; if (newcount > buffer.length) buffer = Bytes.copyOf(buffer, Math.max(buffer.length << 1, newcount)); System.arraycopy(b, off, buffer, count, len); count = newcount; }
Example 10
Source File: RandomAccessByteArrayOutputStream.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public void write(int b) { int newcount = count + 1; if (newcount > buffer.length) buffer = Bytes.copyOf(buffer, Math.max(buffer.length << 1, newcount)); buffer[count] = (byte) b; count = newcount; }
Example 11
Source File: DeprecatedExchangeCodec.java From dubbox with Apache License 2.0 | 4 votes |
protected Object decode(Channel channel, InputStream is, int readable, byte[] header) throws IOException { // check magic number. if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) { int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); is.read(header, length, readable - length); } for (int i = 1; i < header.length - 1; i++) { if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { UnsafeByteArrayInputStream bis = ((UnsafeByteArrayInputStream) is); bis.position(bis.position() - header.length + i); header = Bytes.copyOf(header, i); break; } } return super.decode(channel, is, readable, header); } // check length. if (readable < HEADER_LENGTH) { return NEED_MORE_INPUT; } // get data length. int len = Bytes.bytes2int(header, 12); checkPayload(channel, len); int tt = len + HEADER_LENGTH; if (readable < tt) { return NEED_MORE_INPUT; } // limit input stream. if (readable != tt) is = StreamUtils.limitedInputStream(is, len); try { return decodeBody(channel, is, header); } finally { if (is.available() > 0) { try { if (logger.isWarnEnabled()) { logger.warn("Skip input stream " + is.available()); } StreamUtils.skipUnusedStream(is); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } }
Example 12
Source File: ExchangeCodec.java From dubbox with Apache License 2.0 | 4 votes |
protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException { // check magic number. if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) { int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); buffer.readBytes(header, length, readable - length); } for (int i = 1; i < header.length - 1; i ++) { if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { buffer.readerIndex(buffer.readerIndex() - header.length + i); header = Bytes.copyOf(header, i); break; } } return super.decode(channel, buffer, readable, header); } // check length. if (readable < HEADER_LENGTH) { return DecodeResult.NEED_MORE_INPUT; } // get data length. int len = Bytes.bytes2int(header, 12); checkPayload(channel, len); int tt = len + HEADER_LENGTH; if( readable < tt ) { return DecodeResult.NEED_MORE_INPUT; } // limit input stream. ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len); try { return decodeBody(channel, is, header); } finally { if (is.available() > 0) { try { if (logger.isWarnEnabled()) { logger.warn("Skip input stream " + is.available()); } StreamUtils.skipUnusedStream(is); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } }
Example 13
Source File: ExchangeCodec.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException { // check magic number. if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) { int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); buffer.readBytes(header, length, readable - length); } for (int i = 1; i < header.length - 1; i ++) { if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { buffer.readerIndex(buffer.readerIndex() - header.length + i); header = Bytes.copyOf(header, i); break; } } return super.decode(channel, buffer, readable, header); } // check length. if (readable < HEADER_LENGTH) { return DecodeResult.NEED_MORE_INPUT; } // get data length. int len = Bytes.bytes2int(header, 12); checkPayload(channel, len); int tt = len + HEADER_LENGTH; if( readable < tt ) { return DecodeResult.NEED_MORE_INPUT; } // limit input stream. ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len); try { return decodeBody(channel, is, header); } finally { if (is.available() > 0) { try { if (logger.isWarnEnabled()) { logger.warn("Skip input stream " + is.available()); } StreamUtils.skipUnusedStream(is); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } }
Example 14
Source File: DeprecatedExchangeCodec.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
protected Object decode(Channel channel, InputStream is, int readable, byte[] header) throws IOException { // check magic number. if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) { int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); is.read(header, length, readable - length); } for (int i = 1; i < header.length - 1; i++) { if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { UnsafeByteArrayInputStream bis = ((UnsafeByteArrayInputStream) is); bis.position(bis.position() - header.length + i); header = Bytes.copyOf(header, i); break; } } return super.decode(channel, is, readable, header); } // check length. if (readable < HEADER_LENGTH) { return NEED_MORE_INPUT; } // get data length. int len = Bytes.bytes2int(header, 12); checkPayload(channel, len); int tt = len + HEADER_LENGTH; if (readable < tt) { return NEED_MORE_INPUT; } // limit input stream. if (readable != tt) is = StreamUtils.limitedInputStream(is, len); try { return decodeBody(channel, is, header); } finally { if (is.available() > 0) { try { if (logger.isWarnEnabled()) { logger.warn("Skip input stream " + is.available()); } StreamUtils.skipUnusedStream(is); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } }
Example 15
Source File: DeprecatedExchangeCodec.java From dubbox with Apache License 2.0 | 4 votes |
protected Object decode(Channel channel, InputStream is, int readable, byte[] header) throws IOException { // check magic number. if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) { int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); is.read(header, length, readable - length); } for (int i = 1; i < header.length - 1; i++) { if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { UnsafeByteArrayInputStream bis = ((UnsafeByteArrayInputStream) is); bis.position(bis.position() - header.length + i); header = Bytes.copyOf(header, i); break; } } return super.decode(channel, is, readable, header); } // check length. if (readable < HEADER_LENGTH) { return NEED_MORE_INPUT; } // get data length. int len = Bytes.bytes2int(header, 12); checkPayload(channel, len); int tt = len + HEADER_LENGTH; if (readable < tt) { return NEED_MORE_INPUT; } // limit input stream. if (readable != tt) is = StreamUtils.limitedInputStream(is, len); try { return decodeBody(channel, is, header); } finally { if (is.available() > 0) { try { if (logger.isWarnEnabled()) { logger.warn("Skip input stream " + is.available()); } StreamUtils.skipUnusedStream(is); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } }
Example 16
Source File: ExchangeCodec.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Override protected Object decode(Channel channel, ChannelBuffer buffer, int readable, byte[] header) throws IOException { // check magic number. if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) { int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); buffer.readBytes(header, length, readable - length); } for (int i = 1; i < header.length - 1; i++) { if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { buffer.readerIndex(buffer.readerIndex() - header.length + i); header = Bytes.copyOf(header, i); break; } } return super.decode(channel, buffer, readable, header); } // check length. if (readable < HEADER_LENGTH) { return DecodeResult.NEED_MORE_INPUT; } // get data length. int len = Bytes.bytes2int(header, 12); checkPayload(channel, len); int tt = len + HEADER_LENGTH; if (readable < tt) { return DecodeResult.NEED_MORE_INPUT; } // limit input stream. ChannelBufferInputStream is = new ChannelBufferInputStream(buffer, len); try { // 响应结果解析 return decodeBody(channel, is, header); } finally { if (is.available() > 0) { try { if (logger.isWarnEnabled()) { logger.warn("Skip input stream " + is.available()); } StreamUtils.skipUnusedStream(is); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } }
Example 17
Source File: DeprecatedExchangeCodec.java From dubbo3 with Apache License 2.0 | 4 votes |
protected Object decode(Channel channel, InputStream is, int readable, byte[] header) throws IOException { // check magic number. if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW) { int length = header.length; if (header.length < readable) { header = Bytes.copyOf(header, readable); is.read(header, length, readable - length); } for (int i = 1; i < header.length - 1; i++) { if (header[i] == MAGIC_HIGH && header[i + 1] == MAGIC_LOW) { UnsafeByteArrayInputStream bis = ((UnsafeByteArrayInputStream) is); bis.position(bis.position() - header.length + i); header = Bytes.copyOf(header, i); break; } } return super.decode(channel, is, readable, header); } // check length. if (readable < HEADER_LENGTH) { return NEED_MORE_INPUT; } // get data length. int len = Bytes.bytes2int(header, 12); checkPayload(channel, len); int tt = len + HEADER_LENGTH; if (readable < tt) { return NEED_MORE_INPUT; } // limit input stream. if (readable != tt) is = StreamUtils.limitedInputStream(is, len); try { return decodeBody(channel, is, header); } finally { if (is.available() > 0) { try { if (logger.isWarnEnabled()) { logger.warn("Skip input stream " + is.available()); } StreamUtils.skipUnusedStream(is); } catch (IOException e) { logger.warn(e.getMessage(), e); } } } }
Example 18
Source File: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 2 votes |
public byte[] toByteArray() { return Bytes.copyOf( buffer, count ); }
Example 19
Source File: RandomAccessByteArrayOutputStream.java From dubbo-2.6.5 with Apache License 2.0 | 2 votes |
public byte[] toByteArray() { return Bytes.copyOf(buffer, count); }
Example 20
Source File: RandomAccessByteArrayOutputStream.java From dubbox with Apache License 2.0 | 2 votes |
public byte[] toByteArray() { return Bytes.copyOf( buffer, count ); }