def read_console():
log("Запускаем читатель команд из консоли")
while True:
cmd = input()
if cmd == "exit":
log("Выходим....")
connection.exit()
exit(0)
break
# TODO: More commands
prefixes = {'INFO': colored("INFO", "blue"),
'WARN': colored("WARN", "yellow"),
'ERR': colored("ERR", "red")}
def log(message, prefix='INFO'):
print("%s %s %s" % (
colored(time.asctime(time.localtime(time.time())), "cyan", attrs=['reverse']), prefixes[prefix], message))
String content;
if(!Charset.isSupported(contentRequest.getCharset())) {
content = "[ERR:01] => Charset isn't supported.";
} else {
Charset charset = Charset.forName(contentRequest.getCharset());
ByteBuffer buffer = charset.encode(contentOf(contentRequest.getLink()));
content = new String(buffer.array());
}
public class PacketBuffer {
public PacketBuffer(ByteBuf buffer) {
this.buffer = buffer;
this.buffer.retain();
}
public int readInt() {
return buffer.readInt();
}
public void writeInt(int i) {
buffer.writeInt(i);
}
public long readLong() {
return buffer.readLong();
}
public void writeLong(long l) {
buffer.writeLong(l);
}
private ByteBuf buffer;
public String readString() {
int len = readInt();
byte[] bytes = readBytes(len);
return new String(bytes);
}
public void writeBytes(byte[] bytes) {
buffer.writeBytes(bytes);
}
public byte[] readBytes(int len) {
byte[] b = new byte[len];
buffer.readBytes(b);
return b;
}
public void writeString(String s) {
byte[] bytes = s.getBytes();
writeInt(bytes.length);
writeBytes(bytes);
}
public ByteBuf getBuffer() {
return buffer;
}
}
OutContentResponsePacket
public class OutContentResponsePacket extends Packet {
private String content;
public OutContentResponsePacket() {
super(Side.OUT, 1);
}
public OutContentResponsePacket(String content) {
this();
this.content = content;
}
public String getContent() {
return content;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeString(content);
}
@Override
public void read(PacketBuffer buffer) {
content = buffer.readString();
}
}
Packet
public abstract class Packet {
private int id;
private Side side;
public Packet(Side side, int id) {
this.side = side;
this.id = id;
}
public Side getSide() {
return side;
}
public int getID() {
return id;
}
public abstract void write(PacketBuffer buffer);
public abstract void read(PacketBuffer buffer);
}
Хоть какие, не важно