當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteChannel.write方法代碼示例

本文整理匯總了Java中java.nio.channels.ByteChannel.write方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteChannel.write方法的具體用法?Java ByteChannel.write怎麽用?Java ByteChannel.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.channels.ByteChannel的用法示例。


在下文中一共展示了ByteChannel.write方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeGetRequestTo

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
private void writeGetRequestTo(ByteChannel channel) throws IOException {

	// @formatter:off
	String request = new StringBuilder("GET").append(SPACE)
		.append(this.url.getPath()).append(SPACE).append("HTTP/1.1")
                .append(CRLF)
   		.append("User-Agent: NIOHttp/0.1 Java")
                .append(CRLF)
                .append("Host:").append(SPACE).append(url.getHost())
                .append(CRLF)
                .append("Accept-Language: en-us").append(CRLF)
                .append("Connection: close").append(CRLF).append(CRLF)
                .toString();
           // @formatter:on

	ByteBuffer sending = ByteBuffer.allocate(request.getBytes().length);
	sending.put(request.getBytes());
	sending.flip();
	channel.write(sending);
    }
 
開發者ID:Oliver-Loeffler,項目名稱:NIOHttp,代碼行數:21,代碼來源:FutureDemo.java

示例2: batch

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
/** Returns whether the whole outQueue has been flushed */
public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws IOException {
	ByteBuffer buffer = ws.outQueue.peek();
	WrappedByteChannel c = null;

	if( buffer == null ) {
		if( sockchannel instanceof WrappedByteChannel ) {
			c = (WrappedByteChannel) sockchannel;
			if( c.isNeedWrite() ) {
				c.writeMore();
			}
		}
	} else {
		do {// FIXME writing as much as possible is unfair!!
			/*int written = */sockchannel.write( buffer );
			if( buffer.remaining() > 0 ) {
				return false;
			} else {
				ws.outQueue.poll(); // Buffer finished. Remove it.
				buffer = ws.outQueue.peek();
			}
		} while ( buffer != null );
	}

	if( ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft().getRole() == Role.SERVER ) {//
		synchronized ( ws ) {
			ws.closeConnection();
		}
	}
	return c != null ? !( (WrappedByteChannel) sockchannel ).isNeedWrite() : true;
}
 
開發者ID:LDLN,項目名稱:Responder-Android,代碼行數:32,代碼來源:SocketChannelIOHelper.java

示例3: batch

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
/**
 * Returns whether the whole outQueue has been flushed
 */
public static boolean batch(WebSocketImpl ws, ByteChannel sockchannel) throws IOException {
    ByteBuffer buffer = ws.outQueue.peek();
    WrappedByteChannel c = null;

    if (buffer == null) {
        if (sockchannel instanceof WrappedByteChannel) {
            c = (WrappedByteChannel) sockchannel;
            if (c.isNeedWrite()) {
                c.writeMore();
            }
        }
    } else {
        do {// FIXME writing as much as possible is unfair!!
            /*int written = */
            sockchannel.write(buffer);
            if (buffer.remaining() > 0) {
                return false;
            } else {
                ws.outQueue.poll(); // Buffer finished. Remove it.
                buffer = ws.outQueue.peek();
            }
        } while (buffer != null);
    }

    if (ws != null && ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null && ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER) {//
        synchronized (ws) {
            ws.closeConnection();
        }
    }
    return c != null ? !((WrappedByteChannel) sockchannel).isNeedWrite() : true;
}
 
開發者ID:GloriousEggroll,項目名稱:quorrabot,代碼行數:35,代碼來源:SocketChannelIOHelper.java

示例4: writeBlocking

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
public static void writeBlocking(WebSocketImpl ws, ByteChannel channel) throws InterruptedException, IOException {
    if (!$assertionsDisabled && (channel instanceof AbstractSelectableChannel) && !((AbstractSelectableChannel) channel).isBlocking()) {
        throw new AssertionError();
    } else if ($assertionsDisabled || !(channel instanceof WrappedByteChannel) || ((WrappedByteChannel) channel).isBlocking()) {
        ByteBuffer buf = (ByteBuffer) ws.outQueue.take();
        while (buf.hasRemaining()) {
            channel.write(buf);
        }
    } else {
        throw new AssertionError();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:13,代碼來源:SocketChannelIOHelper.java

示例5: writeGetRequestToChannel

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
private void writeGetRequestToChannel(ByteChannel channel) throws IOException {

	Request request = new HttpRequestBuilder(this.url).closeConnection()
		.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1").httpGet();

	sysout(request.getBytes(), "HTTP Request");
	ByteBuffer sending = ByteBuffer.allocate(request.getBytes().length);
	sending.put(request.getBytes());
	sending.flip();
	channel.write(sending);
    }
 
開發者ID:Oliver-Loeffler,項目名稱:NIOHttp,代碼行數:12,代碼來源:Demo.java

示例6: batch

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
/** Returns whether the whole outQueue has been flushed
 * @param ws The WebSocketImpl associated with the channels
 * @param sockchannel The channel to write to
 * @throws IOException May be thrown by {@link WrappedByteChannel#writeMore()}
 * @return returns Whether there is more data to write
 */
public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws IOException {
	ByteBuffer buffer = ws.outQueue.peek();
	WrappedByteChannel c = null;

	if( buffer == null ) {
		if( sockchannel instanceof WrappedByteChannel ) {
			c = (WrappedByteChannel) sockchannel;
			if( c.isNeedWrite() ) {
				c.writeMore();
			}
		}
	} else {
		do {// FIXME writing as much as possible is unfair!!
			/*int written = */sockchannel.write( buffer );
			if( buffer.remaining() > 0 ) {
				return false;
			} else {
				ws.outQueue.poll(); // Buffer finished. Remove it.
				buffer = ws.outQueue.peek();
			}
		} while ( buffer != null );
	}

	if( ws != null && ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null && ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER ) {//
		synchronized ( ws ) {
			ws.closeConnection();
		}
	}
	return c == null || !((WrappedByteChannel) sockchannel).isNeedWrite();
}
 
開發者ID:MundoSK,項目名稱:MundoSK,代碼行數:37,代碼來源:SocketChannelIOHelper.java

示例7: write

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
/**
 * ByteChannelへ書き込む
 * @param channel
 * @param value
 * @param work
 * @throws IOException
 */
public static  void write(@NonNull final ByteChannel channel,
	final boolean value,
	@Nullable final ByteBuffer work) throws IOException {
	
	final ByteBuffer buf = checkBuffer(work, 1);
	buf.put((byte)(value ? 1 : 0));
	buf.flip();
	channel.write(buf);
}
 
開發者ID:saki4510t,項目名稱:libcommon,代碼行數:17,代碼來源:ChannelHelper.java

示例8: writeData

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
@Test
public void writeData() throws Exception {
	this.server.expect("hello".getBytes());
	this.server.start();
	ByteChannel channel = this.connection.open(DEFAULT_TIMEOUT);
	ByteBuffer buffer = ByteBuffer.wrap("hello".getBytes());
	channel.write(buffer);
	this.server.closeAndVerify();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:SocketTargetServerConnectionTests.java

示例9: batch

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
/** Returns whether the whole outQueue has been flushed */
public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws IOException {
	ByteBuffer buffer = ws.outQueue.peek();
	WrappedByteChannel c = null;

	if( buffer == null ) {
		if( sockchannel instanceof WrappedByteChannel ) {
			c = (WrappedByteChannel) sockchannel;
			if( c.isNeedWrite() ) {
				c.writeMore();
			}
		}
	} else {
		do {// FIXME writing as much as possible is unfair!!
			/*int written = */sockchannel.write( buffer );
			if( buffer.remaining() > 0 ) {
				return false;
			} else {
				ws.outQueue.poll(); // Buffer finished. Remove it.
				buffer = ws.outQueue.peek();
			}
		} while ( buffer != null );
	}

	if( ws != null && ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null && ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER ) {//
		synchronized ( ws ) {
			ws.closeConnection();
		}
	}
	return c != null ? !( (WrappedByteChannel) sockchannel ).isNeedWrite() : true;
}
 
開發者ID:RestComm,項目名稱:android-QoS,代碼行數:32,代碼來源:SocketChannelIOHelper.java

示例10: batch

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
public static boolean batch(WebSocketImplementation ws, ByteChannel sockchannel) throws IOException {
	ByteBuffer buffer = ws.outQueue.peek();
	WrappedByteChannel c = null;

	if(buffer == null) {
		if(sockchannel instanceof WrappedByteChannel) {
			c = (WrappedByteChannel) sockchannel;
			if(c.isNeedWrite()) {
				c.writeMore();
			}
		}
	} else {
		do {
			sockchannel.write(buffer);
			if(buffer.remaining() > 0) {
				return false;
			} else {
				ws.outQueue.poll();
				buffer = ws.outQueue.peek();
			}
		} while (buffer != null);
	}

	if(ws != null && ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null && ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER) {//
		synchronized (ws) {
			ws.closeConnection();
		}
	}
	return c != null ? !((WrappedByteChannel) sockchannel).isNeedWrite() : true;
}
 
開發者ID:frc2503,項目名稱:r2016,代碼行數:31,代碼來源:SocketChannelIOHelper.java

示例11: batch

import java.nio.channels.ByteChannel; //導入方法依賴的package包/類
/** Returns whether the whole outQueue has been flushed */
public static boolean batch( WebSocketImpl ws, ByteChannel sockchannel ) throws IOException {
	ByteBuffer buffer = ws.outQueue.peek();

	if( buffer == null ) {
		if( sockchannel instanceof WrappedByteChannel ) {
			WrappedByteChannel c = (WrappedByteChannel) sockchannel;
			if( c.isNeedWrite() ) {
				c.writeMore();
				return !c.isNeedWrite();
			}
			return true;
		}
	} else {
		do {// FIXME writing as much as possible is unfair!!
			/*int written = */sockchannel.write( buffer );
			if( buffer.remaining() > 0 ) {
				return false;
			} else {
				ws.outQueue.poll(); // Buffer finished. Remove it.
				buffer = ws.outQueue.peek();
			}
		} while ( buffer != null );
	}

	if( ws.isClosed() ) {
		synchronized ( ws ) {
			sockchannel.close();
		}
	}
	return sockchannel instanceof WrappedByteChannel == true ? !( (WrappedByteChannel) sockchannel ).isNeedWrite() : true;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:33,代碼來源:SocketChannelIOHelper.java


注:本文中的java.nio.channels.ByteChannel.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。