當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。