mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
28 lines
639 B
Java
28 lines
639 B
Java
package com.l2jserver.util;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import org.jboss.netty.buffer.ChannelBuffer;
|
|
|
|
public class BufferUtils {
|
|
public static final String readString(ChannelBuffer buffer) {
|
|
char[] str = new char[buffer.readableBytes()];
|
|
int index = 0;
|
|
char c;
|
|
while ((c = buffer.readChar()) != 0) {
|
|
str[index++] = c;
|
|
}
|
|
return String.valueOf(Arrays.copyOfRange(str, 0, index));
|
|
}
|
|
|
|
public static final void writeString(ChannelBuffer buffer, String str) {
|
|
if (str != null) {
|
|
final int len = str.length();
|
|
for (int i = 0; i < len; i++) {
|
|
buffer.writeChar(str.charAt(i));
|
|
}
|
|
}
|
|
buffer.writeChar('\000');
|
|
}
|
|
}
|