当前位置: 首页>>代码示例>>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;未经允许,请勿转载。