本文整理汇总了Java中org.jgroups.util.Util.readLine方法的典型用法代码示例。如果您正苦于以下问题:Java Util.readLine方法的具体用法?Java Util.readLine怎么用?Java Util.readLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.util.Util
的用法示例。
在下文中一共展示了Util.readLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loop
import org.jgroups.util.Util; //导入方法依赖的package包/类
private static void loop(GridFilesystem fs) {
while(true) {
try {
System.out.print("> ");
String line=Util.readLine(System.in);
if(!execute(fs, line))
break;
}
catch(Throwable t) {
t.printStackTrace();
}
}
}
示例2: start
import org.jgroups.util.Util; //导入方法依赖的package包/类
protected void start() throws Exception {
Receiver r=null;
DatagramChannel channel=null;
try {
r=new Receiver();
r.start();
channel=DatagramChannel.open(prot_family).setOption(StandardSocketOptions.IP_MULTICAST_TTL, ttl)
.bind(new InetSocketAddress(bind_addr, local_port));
sock=channel.socket();
}
catch(Exception ex) {
if(channel != null)
channel.close();
if(r != null) {
r.kill();
r.interrupt();
}
throw ex;
}
DataInputStream in=new DataInputStream(System.in);
while(true) {
System.out.print("> ");
try {
String line=Util.readLine(in);
byte[] buf=line.getBytes();
DatagramPacket packet=new DatagramPacket(buf, buf.length, mcast_addr, mcast_port);
sock.send(packet);
}
catch(Throwable t) {
t.printStackTrace();
}
}
}
示例3: readFrame
import org.jgroups.util.Util; //导入方法依赖的package包/类
public static Frame readFrame(DataInputStream in) throws IOException {
String verb=Util.readLine(in);
if(verb == null)
throw new EOFException("reading verb");
if(verb.isEmpty())
return null;
verb=verb.trim();
Map<String,String> headers=new HashMap<>();
byte[] body=null;
for(;;) {
String header=Util.readLine(in);
if(header == null)
throw new EOFException("reading header");
if(header.isEmpty())
break;
int index=header.indexOf(":");
if(index != -1)
headers.put(header.substring(0, index).trim(), header.substring(index+1).trim());
}
if(headers.containsKey("content-length")) {
int length=Integer.parseInt(headers.get("content-length"));
body=new byte[length];
in.read(body, 0, body.length);
}
else {
ByteBuffer buf=ByteBuffer.allocate(500);
boolean terminate=false;
for(;;) {
int c=in.read();
if(c == -1 || c == 0)
terminate=true;
if(buf.remaining() == 0 || terminate) {
if(body == null) {
body=new byte[buf.position()];
System.arraycopy(buf.array(), buf.arrayOffset(), body, 0, buf.position());
}
else {
byte[] tmp=new byte[body.length + buf.position()];
System.arraycopy(body, 0, tmp, 0, body.length);
try {
System.arraycopy(buf.array(), buf.arrayOffset(), tmp, body.length, buf.position());
}
catch(Throwable t) {
}
body=tmp;
}
buf.rewind();
}
if(terminate)
break;
buf.put((byte)c);
}
}
return new Frame(verb, headers, body);
}