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


Java WritableByteChannel.write方法代码示例

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


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

示例1: fastCopy

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
/**
     * copy
     *
     * @param src
     * @param dest
     * @throws IOException
     */
    public static void fastCopy(final ReadableByteChannel src, final WritableByteChannel dest) throws IOException {
        final ByteBuffer buffer = ByteBuffer.allocateDirect(8 * 1024);
        int count = 0;

        while ((count = src.read(buffer)) != -1) {
//            LogUtil.d("luaviewp-fastCopy", count, buffer.capacity(), buffer.remaining(), buffer.array().length);
            // prepare the buffer to be drained
            buffer.flip();
            // write to the channel, may block
            dest.write(buffer);
            // If partial transfer, shift remainder down
            // If buffer is empty, same as doing clear()
            buffer.compact();
        }
        // EOF will leave buffer in fill state
        buffer.flip();
        // make sure the buffer is fully drained.
        while (buffer.hasRemaining()) {
            dest.write(buffer);
        }
    }
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:29,代码来源:ChannelTools.java

示例2: getBox

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
public void getBox(WritableByteChannel writableByteChannel) throws IOException {
    ByteBuffer bb = ByteBuffer.allocate(16);
    long size = getSize();
    if (isSmallBox(size)) {
        IsoTypeWriter.writeUInt32(bb, size);
    } else {
        IsoTypeWriter.writeUInt32(bb, 1);
    }
    bb.put(IsoFile.fourCCtoBytes("mdat"));
    if (isSmallBox(size)) {
        bb.put(new byte[8]);
    } else {
        IsoTypeWriter.writeUInt64(bb, size);
    }
    bb.rewind();
    writableByteChannel.write(bb);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:18,代码来源:MP4Builder.java

示例3: transferTo

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    if (this.byteBufferHeader.hasRemaining()) {
        transfered += target.write(this.byteBufferHeader);
        return transfered;
    } else {
        List<ByteBuffer> messageBufferList = this.getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {
            if (bb.hasRemaining()) {
                transfered += target.write(bb);
                return transfered;
            }
        }
    }

    return 0;
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:18,代码来源:ManyMessageTransfer.java

示例4: write

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void write(WritableByteChannel channel) throws IOException {
    logger.config(getLoggingFilename() + ":Writing tag to channel");

    byte[] bodyByteBuffer = writeFramesToBuffer().toByteArray();
    logger.config(getLoggingFilename() + ":bodybytebuffer:sizebeforeunsynchronisation:" + bodyByteBuffer.length);

    // Unsynchronize if option enabled and unsync required
    unsynchronization = TagOptionSingleton.getInstance().isUnsyncTags() && ID3Unsynchronization.requiresUnsynchronization(bodyByteBuffer);
    if (isUnsynchronization()) {
        bodyByteBuffer = ID3Unsynchronization.unsynchronize(bodyByteBuffer);
        logger.config(getLoggingFilename() + ":bodybytebuffer:sizeafterunsynchronisation:" + bodyByteBuffer.length);
    }
    ByteBuffer headerBuffer = writeHeaderToBuffer(0, bodyByteBuffer.length);

    channel.write(headerBuffer);
    channel.write(ByteBuffer.wrap(bodyByteBuffer));
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:22,代码来源:ID3v23Tag.java

示例5: transferTo

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    if (this.byteBufferHeader.hasRemaining()) {
        transferred += target.write(this.byteBufferHeader);
        return transferred;
    } else {
        List<ByteBuffer> messageBufferList = this.queryMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {
            if (bb.hasRemaining()) {
                transferred += target.write(bb);
                return transferred;
            }
        }
    }

    return 0;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:18,代码来源:QueryMessageTransfer.java

示例6: transferTo

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    if (this.byteBufferHeader.hasRemaining()) {
        transfered += target.write(this.byteBufferHeader);
        return transfered;
    }
    else {
        List<ByteBuffer> messageBufferList = this.getMessageResult.getMessageBufferList();
        for (ByteBuffer bb : messageBufferList) {
            if (bb.hasRemaining()) {
                transfered += target.write(bb);
                return transfered;
            }
        }
    }

    return 0;
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:19,代码来源:ManyMessageTransfer.java

示例7: writeNioBuffer

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
private int writeNioBuffer(
    WritableByteChannel writeCh,
    ByteBuffer buf) throws IOException {
  int originalLimit = buf.limit();
  int ret = 0;

  try {
    int ioSize = Math.min(buf.remaining(), NIO_BUFFER_LIMIT);
    buf.limit(buf.position() + ioSize);
    ret = writeCh.write(buf);
  } finally {
    buf.limit(originalLimit);
  }

  return ret;
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:17,代码来源:MessageWithHeader.java

示例8: send

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
@Override
public int send(WritableByteChannel channel, int sendCurrentLength) throws IOException {
	synchronized (writeBuffer) {
		int navail=(int)(nWritten-nRead);
		int l=Math.min(navail, readBuffer.capacity()-readBuffer.position());
		l=Math.min(sendCurrentLength, l);
		readBuffer.limit(readBuffer.position()+l);
		int n=channel.write(readBuffer);
		if(n>0)
		{
			nRead+=n;
			if(navail==readBuffer.capacity())
			{
				// If buffer was full before but no longer then notify possibly waiting writers.
				writeBuffer.notifyAll();
			}
		}
		if(readBuffer.position()==readBuffer.capacity())
		{
			readBuffer.position(0);
		}
		return n;
	}
}
 
开发者ID:rizsi,项目名称:rcom,代码行数:25,代码来源:OutputStreamSender.java

示例9: getBox

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
public void getBox(WritableByteChannel os) throws IOException {
    for (Box replacer : replacers) {
        replacer.getBox(os);
    }
    ByteBuffer header = ByteBuffer.allocate(8);
    IsoTypeWriter.writeUInt32(header, 8 + data.limit());
    header.put(TYPE.getBytes());
    header.rewind();
    os.write(header);
    data.rewind();
    os.write(data);

}
 
开发者ID:begeekmyfriend,项目名称:mp4parser_android,代码行数:14,代码来源:FreeBox.java

示例10: writeFully

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
public static void writeFully(final WritableByteChannel channel, final ByteBuffer buf)
        throws IOException {
    do {
        int written = channel.write(buf);
        if (written < 0) {
            throw new EOFException();
        }
    } while (buf.hasRemaining());
}
 
开发者ID:lisnstatic,项目名称:live_master,代码行数:10,代码来源:ChannelHelper.java

示例11: channelIO

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
/**
 * Helper for {@link #channelRead(ReadableByteChannel, ByteBuffer)}
 * and {@link #channelWrite(WritableByteChannel, ByteBuffer)}. Only
 * one of readCh or writeCh should be non-null.
 * 
 * @see #channelRead(ReadableByteChannel, ByteBuffer)
 * @see #channelWrite(WritableByteChannel, ByteBuffer)
 */
private static int channelIO(ReadableByteChannel readCh, 
                             WritableByteChannel writeCh,
                             ByteBuffer buf) throws IOException {
  
  int originalLimit = buf.limit();
  int initialRemaining = buf.remaining();
  int ret = 0;
  
  while (buf.remaining() > 0) {
    try {
      int ioSize = Math.min(buf.remaining(), NIO_BUFFER_LIMIT);
      buf.limit(buf.position() + ioSize);
      
      ret = (readCh == null) ? writeCh.write(buf) : readCh.read(buf); 
      
      if (ret < ioSize) {
        break;
      }

    } finally {
      buf.limit(originalLimit);        
    }
  }

  int nBytes = initialRemaining - buf.remaining(); 
  return (nBytes > 0) ? nBytes : ret;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:36,代码来源:Server.java

示例12: writePadding

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
/**
 * Write paddings byte to the channel
 *
 * @param channel
 * @param padding
 * @throws IOException
 */
protected void writePadding(WritableByteChannel channel, int padding) throws IOException
{
    if (padding > 0)
    {
        channel.write(ByteBuffer.wrap(new byte[padding]));
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:15,代码来源:AbstractID3v2Tag.java

示例13: transferTo

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    if (this.byteBufferHeader.hasRemaining()) {
        transferred += target.write(this.byteBufferHeader);
        return transferred;
    } else if (this.selectMappedBufferResult.getByteBuffer().hasRemaining()) {
        transferred += target.write(this.selectMappedBufferResult.getByteBuffer());
        return transferred;
    }

    return 0;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:13,代码来源:OneMessageTransfer.java

示例14: transferToArbitraryChannel

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
private long transferToArbitraryChannel(long position, int icount,
                                        WritableByteChannel target)
    throws IOException
{
    // Untrusted target: Use a newly-erased buffer
    int c = Math.min(icount, TRANSFER_SIZE);
    ByteBuffer bb = ByteBuffer.allocate(c);
    long tw = 0;                    // Total bytes written
    long pos = position;
    try {
        while (tw < icount) {
            bb.limit(Math.min((int)(icount - tw), TRANSFER_SIZE));
            int nr = read(bb, pos);
            if (nr <= 0)
                break;
            bb.flip();
            // ## Bug: Will block writing target if this channel
            // ##      is asynchronously closed
            int nw = target.write(bb);
            tw += nw;
            if (nw != nr)
                break;
            pos += nw;
            bb.clear();
        }
        return tw;
    } catch (IOException x) {
        if (tw > 0)
            return tw;
        throw x;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:FileChannelImpl.java

示例15: transferTo

import java.nio.channels.WritableByteChannel; //导入方法依赖的package包/类
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    if (this.byteBufferHeader.hasRemaining()) {
        transfered += target.write(this.byteBufferHeader);
        return transfered;
    }
    else if (this.selectMapedBufferResult.getByteBuffer().hasRemaining()) {
        transfered += target.write(this.selectMapedBufferResult.getByteBuffer());
        return transfered;
    }

    return 0;
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:14,代码来源:OneMessageTransfer.java


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