提交 0d27b71d authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Remove unused code

上级 b0264ee3
...@@ -171,11 +171,6 @@ public class DataUtils { ...@@ -171,11 +171,6 @@ public class DataUtils {
*/ */
private static final byte[] EMPTY_BYTES = {}; private static final byte[] EMPTY_BYTES = {};
/**
* The maximum byte to grow a buffer at a time.
*/
private static final int MAX_GROW = 16 * 1024 * 1024;
/** /**
* Get the length of the variable size int. * Get the length of the variable size int.
* *
...@@ -300,14 +295,12 @@ public class DataUtils { ...@@ -300,14 +295,12 @@ public class DataUtils {
/** /**
* Write characters from a string (without the length). * Write characters from a string (without the length).
* *
* @param buff the target buffer * @param buff the target buffer (must be large enough)
* @param s the string * @param s the string
* @param len the number of characters * @param len the number of characters
* @return the byte buffer
*/ */
public static ByteBuffer writeStringData(ByteBuffer buff, public static void writeStringData(ByteBuffer buff,
String s, int len) { String s, int len) {
buff = DataUtils.ensureCapacity(buff, 3 * len);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
int c = s.charAt(i); int c = s.charAt(i);
if (c < 0x80) { if (c < 0x80) {
...@@ -321,7 +314,6 @@ public class DataUtils { ...@@ -321,7 +314,6 @@ public class DataUtils {
buff.put((byte) (c & 0x3f)); buff.put((byte) (c & 0x3f));
} }
} }
return buff;
} }
/** /**
...@@ -860,32 +852,6 @@ public class DataUtils { ...@@ -860,32 +852,6 @@ public class DataUtils {
} }
} }
/**
* Ensure the byte buffer has the given capacity, plus 1 KB. If not, a new,
* larger byte buffer is created and the data is copied.
*
* @param buff the byte buffer
* @param len the minimum remaining capacity
* @return the byte buffer (possibly a new one)
*/
public static ByteBuffer ensureCapacity(ByteBuffer buff, int len) {
len += 1024;
if (buff.remaining() > len) {
return buff;
}
return grow(buff, len);
}
private static ByteBuffer grow(ByteBuffer buff, int len) {
len = buff.remaining() + len;
int capacity = buff.capacity();
len = Math.max(len, Math.min(capacity + MAX_GROW, capacity * 2));
ByteBuffer temp = ByteBuffer.allocate(len);
buff.flip();
temp.put(buff);
return temp;
}
/** /**
* Read a hex long value from a map. * Read a hex long value from a map.
* *
......
...@@ -73,19 +73,7 @@ public class WriteBuffer { ...@@ -73,19 +73,7 @@ public class WriteBuffer {
*/ */
public WriteBuffer putStringData(String s, int len) { public WriteBuffer putStringData(String s, int len) {
ByteBuffer b = ensureCapacity(3 * len); ByteBuffer b = ensureCapacity(3 * len);
for (int i = 0; i < len; i++) { DataUtils.writeStringData(b, s, len);
int c = s.charAt(i);
if (c < 0x80) {
b.put((byte) c);
} else if (c >= 0x800) {
b.put((byte) (0xe0 | (c >> 12)));
b.put((byte) (((c >> 6) & 0x3f)));
b.put((byte) (c & 0x3f));
} else {
b.put((byte) (0xc0 | (c >> 6)));
b.put((byte) (c & 0x3f));
}
}
return this; return this;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论