当前位置: 首页>>代码示例>>Java>>正文


Java GatheringByteChannel.write方法代码示例

本文整理汇总了Java中java.nio.channels.GatheringByteChannel.write方法的典型用法代码示例。如果您正苦于以下问题:Java GatheringByteChannel.write方法的具体用法?Java GatheringByteChannel.write怎么用?Java GatheringByteChannel.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.GatheringByteChannel的用法示例。


在下文中一共展示了GatheringByteChannel.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: divideProcessing

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
protected void divideProcessing (int bufferSize, StringBuffer bf, ByteBuffer bb, GatheringByteChannel outChannel, String charset) throws IOException {
	int bfsCnt = bf.length()/bufferSize+1;
	for(int i=0;i<bfsCnt;i++) {
		String sub = null;
		if(i<bfsCnt-1) {
			sub = bf.substring(i*bufferSize, (i+1)*bufferSize);
		} else {
			sub = bf.substring(i*bufferSize, i*bufferSize+(bf.length()%bufferSize));
		}
		if(sub != null){
			bb.put(sub.getBytes(charset));
			bb.flip();
   			
   			outChannel.write(bb);
   			bb.clear();
		}
	}
	bf.setLength(0);
}
 
开发者ID:experdb,项目名称:eXperDB-DB2PG,代码行数:20,代码来源:ExecuteQuery.java

示例2: writeTo

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
@Override
public long writeTo(GatheringByteChannel channel) throws IOException {
    long written = 0;

    if (remaining > 0) {
        written = records.writeTo(channel, size() - remaining, remaining);
        if (written < 0)
            throw new EOFException("Wrote negative bytes to channel. This shouldn't happen.");
        remaining -= written;
    }

    pending = TransportLayers.hasPendingWrites(channel);
    if (remaining <= 0 && pending)
        channel.write(EMPTY_BYTE_BUFFER);

    return written;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:RecordsSend.java

示例3: getBytes

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    checkIndex(index, length);
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = memory.duplicate();
    }
    index = idx(index);
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:PooledUnsafeDirectByteBuf.java

示例4: gather

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
public static void gather() {
	ByteBuffer header = ByteBuffer.allocate(14);
	ByteBuffer body = ByteBuffer.allocate(100);

	header.put(headers.getBytes());
	body.put(bodys.getBytes());

	GatheringByteChannel channel = getChannel();

	try {
		header.flip();
		body.flip();
		channel.write(new ByteBuffer[] { header, body });
	} catch (IOException e) {
		e.printStackTrace();
	}

}
 
开发者ID:zoopaper,项目名称:netty-study,代码行数:19,代码来源:ScatterAndGather.java

示例5: sendBuffer

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
private void sendBuffer (ByteBuffer data,
	GatheringByteChannel channel, String contentType)
	throws Exception
{
	ByteBuffer [] buffers = { staticHdr, dynHdr, data };

	staticHdr.rewind();

	cbtemp.clear();
	cbtemp.put ("Content-Length: " + data.limit());
	cbtemp.put (LINE_SEP);
	cbtemp.put ("Content-Type: ");
	cbtemp.put (contentType);
	cbtemp.put (LINE_SEP);
	cbtemp.put (LINE_SEP);
	cbtemp.flip();

	buffers [1] = utf8.encode (cbtemp);

	while (channel.write (buffers) != 0) {
		// nothing
	}
}
 
开发者ID:jt120,项目名称:nio,代码行数:24,代码来源:HttpServer.java

示例6: main

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
public static void main (String [] argv)
	throws Exception
{
	int reps = 10;

	if (argv.length > 0) {
		reps = Integer.parseInt (argv [0]);
	}

	FileOutputStream fos = new FileOutputStream (DEMOGRAPHIC);
	GatheringByteChannel gatherChannel = fos.getChannel();

	// generate some brilliant marcom, er, repurposed content
	ByteBuffer [] bs = utterBS (reps);

	// deliver the message to the waiting market
	while (gatherChannel.write (bs) > 0) {
		// empty body
		// loop until write() returns zero
	}

	System.out.println ("Mindshare paradigms synergized to "
		+ DEMOGRAPHIC);

	fos.close();
}
 
开发者ID:jt120,项目名称:nio,代码行数:27,代码来源:Marketing.java

示例7: writeTo

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
@Override
public long writeTo(GatheringByteChannel channel) throws IOException {
    long written = channel.write(buffers);
    if (written < 0)
        throw new EOFException("Wrote negative bytes to channel. This shouldn't happen.");
    remaining -= written;
    pending = TransportLayers.hasPendingWrites(channel);
    return written;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:10,代码来源:ByteBufferSend.java

示例8: writeTo

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
@Override
public long writeTo(GatheringByteChannel channel, long position, int length) throws IOException {
    if (position > Integer.MAX_VALUE)
        throw new IllegalArgumentException("position should not be greater than Integer.MAX_VALUE: " + position);
    if (position + length > buffer.limit())
        throw new IllegalArgumentException("position+length should not be greater than buffer.limit(), position: "
                + position + ", length: " + length + ", buffer.limit(): " + buffer.limit());

    int pos = (int) position;
    ByteBuffer dup = buffer.duplicate();
    dup.position(pos);
    dup.limit(pos + length);
    return channel.write(dup);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:15,代码来源:MemoryRecords.java

示例9: writeFullyTo

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
/**
 * Write all records to the given channel (including partial records).
 * @param channel The channel to write to
 * @return The number of bytes written
 * @throws IOException For any IO errors writing to the channel
 */
public int writeFullyTo(GatheringByteChannel channel) throws IOException {
    buffer.mark();
    int written = 0;
    while (written < sizeInBytes())
        written += channel.write(buffer);
    buffer.reset();
    return written;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:15,代码来源:MemoryRecords.java

示例10: getBytes

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
public int getBytes(int index, GatheringByteChannel out, int length)
        throws IOException {

    if (useGathering()) {
        return (int) out.write(toByteBuffers(index, length));
    }

    // XXX Gathering write is not supported because of a known issue.
    //     See http://bugs.sun.com/view_bug.do?bug_id=6210541
    //     This issue appeared in 2004 and is still unresolved!?
    return out.write(toByteBuffer(index, length));
}
 
开发者ID:kennylbj,项目名称:kiwi,代码行数:13,代码来源:CompositeBuffer.java

示例11: writeTo

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
@Override
public long writeTo(GatheringByteChannel channel) throws IOException {
    long written = channel.write(buffers);
    if (written < 0)
        throw new EOFException("Wrote negative bytes to channel. This shouldn't happen.");
    remaining -= written;
    // This is temporary workaround. As Send , Receive interfaces are being used by BlockingChannel.
    // Once BlockingChannel is removed we can make Send, Receive to work with transportLayer rather than
    // GatheringByteChannel or ScatteringByteChannel.
    if (channel instanceof TransportLayer)
        pending = ((TransportLayer) channel).hasPendingWrites();

    return written;
}
 
开发者ID:txazo,项目名称:kafka,代码行数:15,代码来源:ByteBufferSend.java

示例12: getBytes

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
	// adapted from UnpooledDirectByteBuf:
	checkIndex(index, length);
	if (length == 0) {
		return 0;
	}

	ByteBuffer tmpBuf = memorySegment.wrap(index, length);
	return out.write(tmpBuf);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:12,代码来源:NetworkBuffer.java

示例13: gatherWrite

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
public static void gatherWrite(ByteBuffer[] byteBuffers,String file) throws IOException {

		FileOutputStream fos = new FileOutputStream(file);
		GatheringByteChannel gatherChannel = fos.getChannel();
		while(gatherChannel.write(byteBuffers)>0){
		}
		System.out.println("全部写入文件:"+file);
		gatherChannel.close();
		fos.close();

	}
 
开发者ID:sence-std,项目名称:std-nio,代码行数:12,代码来源:GatherChannel.java

示例14: drainTo

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
/**
 * Drain pending buffers one at a time into the socket
 * @param channel
 * @return
 * @throws IOException
 */
@Override
int drainTo (final GatheringByteChannel channel) throws IOException {
    int bytesWritten = 0;
    long rc = 0;
    do {
        /*
         * Nothing to write
         */
        if (m_currentWriteBuffer == null && m_queuedBuffers.isEmpty()) {
            break;
        }

        ByteBuffer buffer = null;
        if (m_currentWriteBuffer == null) {
            m_currentWriteBuffer = m_queuedBuffers.poll();
            buffer = m_currentWriteBuffer.b();
            buffer.flip();
        } else {
            buffer = m_currentWriteBuffer.b();
        }

        rc = channel.write(buffer);

        //Discard the buffer back to a pool if no data remains
        if (!buffer.hasRemaining()) {
            m_currentWriteBuffer.discard();
            m_currentWriteBuffer = null;
            m_messagesWritten++;
        }
        bytesWritten += rc;

    } while (rc > 0);

    m_bytesWritten += bytesWritten;
    return bytesWritten;
}
 
开发者ID:anhnv-3991,项目名称:VoltDB,代码行数:43,代码来源:PicoNIOWriteStream.java

示例15: getBytes

import java.nio.channels.GatheringByteChannel; //导入方法依赖的package包/类
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    ensureAccessible();
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = buffer.duplicate();
    }
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:16,代码来源:UnpooledDirectByteBuf.java


注:本文中的java.nio.channels.GatheringByteChannel.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。