私はAndroidのSocketChannelの書き込みを含むコードをデバッグするとき、私はIllegalArgumentExceptionを持っていますが、Windowsのこのコードは同じですが、AndroidとSocketChannelのウィンドウの違いはありますか?はWindowsで異なるAndroidのJava SocketChannel write(ByteBufferソース)ですか?
UPDATE: (コードは、オープンソースプロジェクトfrostwire、アンドロイド(this file in github)の一部であり、この部分は、Vuzeは4.5と同じで、私はちょうど試みを追加{})
private int channelWrite(ByteBuffer buf) throws IOException
{
int written = 0;
while(remainingBytesToScatter > 0 && buf.remaining() > 0)
{
int currentWritten = 0;
try{
currentWritten = channel.write((ByteBuffer)(buf.slice().limit(Math.min(50+rnd.nextInt(100),buf.remaining()))));
}catch(Exception e) {
if(e instanceof IOException) {
Log.d("", "chanel write IOException " + e.getMessage());
}else if(e instanceof IOException) {
Log.d("", "chanel write AsynchronousCloseException " + e.getMessage());
}else if(e instanceof ClosedByInterruptException) {
Log.d("", "chanel write ClosedByInterruptException " + e.getMessage());
}else if(e instanceof ClosedChannelException) {
Log.d("", "chanel write ClosedChannelException " + e.getMessage());
}else if(e instanceof NotYetConnectedException) {
Log.d("", "chanel write ClosedChannelException " + e.getMessage());
}else {
// while in second time, reach here
Log.d("", "chanel write unknown " + e.getMessage());
}
}
if(currentWritten == 0)
break;
buf.position(buf.position()+currentWritten);
remainingBytesToScatter -= currentWritten;
if(remainingBytesToScatter <= 0)
{
remainingBytesToScatter = 0;
try
{
channel.socket().setTcpNoDelay(false);
} catch (SocketException e)
{
Debug.printStackTrace(e);
}
}
written += currentWritten;
}
if(buf.remaining() > 0)
written += channel.write(buf);
return written;
}