forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
976fb0f
commit 2d19ea5
Showing
5 changed files
with
100 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">kimi</a> | ||
|
@@ -41,7 +40,7 @@ public ByteBufferBackedChannelBuffer(ByteBuffer buffer) { | |
writerIndex(capacity); | ||
} | ||
|
||
private ByteBufferBackedChannelBuffer(ByteBufferBackedChannelBuffer buffer) { | ||
public ByteBufferBackedChannelBuffer(ByteBufferBackedChannelBuffer buffer) { | ||
this.buffer = buffer.buffer; | ||
capacity = buffer.capacity; | ||
setIndex(buffer.readerIndex(), buffer.writerIndex()); | ||
|
@@ -55,12 +54,12 @@ public ChannelBufferFactory factory() { | |
} | ||
} | ||
|
||
@Override | ||
|
||
public int capacity() { | ||
return capacity; | ||
} | ||
|
||
@Override | ||
|
||
public ChannelBuffer copy(int index, int length) { | ||
ByteBuffer src; | ||
try { | ||
|
@@ -77,12 +76,12 @@ public ChannelBuffer copy(int index, int length) { | |
return new ByteBufferBackedChannelBuffer(dst); | ||
} | ||
|
||
@Override | ||
|
||
public byte getByte(int index) { | ||
return buffer.get(index); | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, byte[] dst, int dstIndex, int length) { | ||
ByteBuffer data = buffer.duplicate(); | ||
try { | ||
|
@@ -93,7 +92,7 @@ public void getBytes(int index, byte[] dst, int dstIndex, int length) { | |
data.get(dst, dstIndex, length); | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, ByteBuffer dst) { | ||
ByteBuffer data = buffer.duplicate(); | ||
int bytesToCopy = Math.min(capacity() - index, dst.remaining()); | ||
|
@@ -105,7 +104,7 @@ public void getBytes(int index, ByteBuffer dst) { | |
dst.put(data); | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) { | ||
if (dst instanceof ByteBufferBackedChannelBuffer) { | ||
ByteBufferBackedChannelBuffer bbdst = (ByteBufferBackedChannelBuffer) dst; | ||
|
@@ -120,7 +119,7 @@ public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) { | |
} | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, OutputStream out, int length) throws IOException { | ||
if (length == 0) { | ||
return; | ||
|
@@ -138,31 +137,31 @@ public void getBytes(int index, OutputStream out, int length) throws IOException | |
} | ||
} | ||
|
||
@Override | ||
|
||
public boolean isDirect() { | ||
return buffer.isDirect(); | ||
} | ||
|
||
@Override | ||
|
||
public void setByte(int index, int value) { | ||
buffer.put(index, (byte) value); | ||
} | ||
|
||
@Override | ||
|
||
public void setBytes(int index, byte[] src, int srcIndex, int length) { | ||
ByteBuffer data = buffer.duplicate(); | ||
data.limit(index + length).position(index); | ||
data.put(src, srcIndex, length); | ||
} | ||
|
||
@Override | ||
|
||
public void setBytes(int index, ByteBuffer src) { | ||
ByteBuffer data = buffer.duplicate(); | ||
data.limit(index + src.remaining()).position(index); | ||
data.put(src); | ||
} | ||
|
||
@Override | ||
|
||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) { | ||
if (src instanceof ByteBufferBackedChannelBuffer) { | ||
ByteBufferBackedChannelBuffer bbsrc = (ByteBufferBackedChannelBuffer) src; | ||
|
@@ -177,7 +176,7 @@ public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) { | |
} | ||
} | ||
|
||
@Override | ||
|
||
public ByteBuffer toByteBuffer(int index, int length) { | ||
if (index == 0 && length == capacity()) { | ||
return buffer.duplicate(); | ||
|
@@ -187,7 +186,7 @@ public ByteBuffer toByteBuffer(int index, int length) { | |
} | ||
} | ||
|
||
@Override | ||
|
||
public int setBytes(int index, InputStream in, int length) throws IOException { | ||
int readBytes = 0; | ||
|
||
|
@@ -227,17 +226,17 @@ public int setBytes(int index, InputStream in, int length) throws IOException { | |
return readBytes; | ||
} | ||
|
||
@Override | ||
|
||
public byte[] array() { | ||
return buffer.array(); | ||
} | ||
|
||
@Override | ||
|
||
public boolean hasArray() { | ||
return buffer.hasArray(); | ||
} | ||
|
||
@Override | ||
|
||
public int arrayOffset() { | ||
return buffer.arrayOffset(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">kimi</a> | ||
|
@@ -68,80 +67,80 @@ public void ensureWritableBytes(int minWritableBytes) { | |
buffer = newBuffer; | ||
} | ||
|
||
@Override | ||
|
||
public int capacity() { | ||
return buffer.capacity(); | ||
} | ||
|
||
@Override | ||
|
||
public ChannelBuffer copy(int index, int length) { | ||
DynamicChannelBuffer copiedBuffer = new DynamicChannelBuffer(Math.max(length, 64), factory()); | ||
copiedBuffer.buffer = buffer.copy(index, length); | ||
copiedBuffer.setIndex(0, length); | ||
return copiedBuffer; | ||
} | ||
|
||
@Override | ||
|
||
public ChannelBufferFactory factory() { | ||
return factory; | ||
} | ||
|
||
@Override | ||
|
||
public byte getByte(int index) { | ||
return buffer.getByte(index); | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, byte[] dst, int dstIndex, int length) { | ||
buffer.getBytes(index, dst, dstIndex, length); | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, ByteBuffer dst) { | ||
buffer.getBytes(index, dst); | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) { | ||
buffer.getBytes(index, dst, dstIndex, length); | ||
} | ||
|
||
@Override | ||
|
||
public void getBytes(int index, OutputStream dst, int length) throws IOException { | ||
buffer.getBytes(index, dst, length); | ||
} | ||
|
||
@Override | ||
|
||
public boolean isDirect() { | ||
return buffer.isDirect(); | ||
} | ||
|
||
@Override | ||
|
||
public void setByte(int index, int value) { | ||
buffer.setByte(index, value); | ||
} | ||
|
||
@Override | ||
|
||
public void setBytes(int index, byte[] src, int srcIndex, int length) { | ||
buffer.setBytes(index, src, srcIndex, length); | ||
} | ||
|
||
@Override | ||
|
||
public void setBytes(int index, ByteBuffer src) { | ||
buffer.setBytes(index, src); | ||
} | ||
|
||
@Override | ||
|
||
public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) { | ||
buffer.setBytes(index, src, srcIndex, length); | ||
} | ||
|
||
@Override | ||
|
||
public int setBytes(int index, InputStream src, int length) throws IOException { | ||
return buffer.setBytes(index, src, length); | ||
} | ||
|
||
@Override | ||
|
||
public ByteBuffer toByteBuffer(int index, int length) { | ||
return buffer.toByteBuffer(index, length); | ||
} | ||
|
@@ -176,17 +175,17 @@ public int writeBytes(InputStream in, int length) throws IOException { | |
return super.writeBytes(in, length); | ||
} | ||
|
||
@Override | ||
|
||
public byte[] array() { | ||
return buffer.array(); | ||
} | ||
|
||
@Override | ||
|
||
public boolean hasArray() { | ||
return buffer.hasArray(); | ||
} | ||
|
||
@Override | ||
|
||
public int arrayOffset() { | ||
return buffer.arrayOffset(); | ||
} | ||
|
Oops, something went wrong.