//问题出在这里:加了这部分代码才能收完数据包
if (r == 12){
try{
//Logs是自己写的一个输出到文本框的输出类
Logs.println("12");
}
catch(Exception ex){ }
}//以上是问题所在的代码
你这段代码没有对Channel处理吧
if (r == 12){
try{
//Logs是自己写的一个输出到文本框的输出类
Logs.println("12");
}
catch(Exception ex){ }
}//以上是问题所在的代码
你这段代码没有对Channel处理吧
解决方案 »
- Android 小问题
- 在java中怎么把ascii 字符放在小框框中...也就是下面程序的每一个小框子中
- TreeSet排序问题
- 请熟悉Java平台的前辈给解释几个概念
- 可以将char类型的变量转变成int型吗?怎样转,谢谢大家!
- 请问大家一个问题,现在有一个父类F,里面用ThreadLocal()对象记录了某个资源(比如Connection),然后有很多类extends这个F,其他的类通
- java面试题,纠结了半天只做了一半,在线等高手解答!
- 入门级错误,NocCassDefFoundError
- 关于包的问题
- 有关sqlserver连接的问题,高手请务必进来!!!!!
- JAVA程序间隔自动运行的问题
- 500分求字符串分析问题
WritableByteChannel dest)
throws IOException
{
ByteBuffer buffer = ByteBuffer.allocateDirect (16 * 1024);
while (src.read (buffer) != -1) {
// Prepare the buffer to be drained
buffer.flip();
// Write to the channel; may block
dest.write (buffer);
// If partial transfer, shift remainder down
// If buffer is empty, same as doing clear()
buffer.compact();
}
// EOF will leave buffer in fill state
buffer.flip();
// Make sure that the buffer is fully drained
while (buffer.hasRemaining()) {
dest.write (buffer);
}
}
* Channel copy method 1. This method copies data from the src
* channel and writes it to the dest channel until EOF on src.
* This implementation makes use of compact() on the temp buffer
* to pack down the data if the buffer wasn't fully drained. This
* may result in data copying, but minimizes system calls. It also
* requires a cleanup loop to make sure all the data gets sent.
*/
* Channel copy method 2. This method performs the same copy, but
* assures the temp buffer is empty before reading more data. This
* never requires data copying but may result in more systems calls.
* No post-loop cleanup is needed because the buffer will be empty
* when the loop is exited.
*/
68
private static void channelCopy2 (ReadableByteChannel src,
WritableByteChannel dest)
throws IOException
{
ByteBuffer buffer = ByteBuffer.allocateDirect (16 * 1024);
while (src.read (buffer) != -1) {
// Prepare the buffer to be drained
buffer.flip();
// Make sure that the buffer was fully drained
while (buffer.hasRemaining()) {
dest.write (buffer);
}
// Make the buffer empty, ready for filling
buffer.clear();
}
}