WritableByteChannel write - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for WritableByteChannel write method.

This code example shows how to use the following methods:remaining, asReadOnlyBuffer
  } 
 
  public void writeToChannel(WritableByteChannel channel) throws IOException
  { 
    channel.write(ByteBuffer.wrap(new byte[]{version, (byte) numBytes}));
    channel.write(ByteBuffer.wrap(Ints.toByteArray(buffer.remaining())));
    channel.write(buffer.asReadOnlyBuffer());
  } 
 
  public static VSizeIndexedInts readFromByteBuffer(ByteBuffer buffer)
  { 
    byte versionFromBuffer = buffer.get();
 
    if (version == versionFromBuffer) {
      int numBytes = buffer.get();
      int size = buffer.getInt();
      ByteBuffer bufferToUse = buffer.asReadOnlyBuffer();
      bufferToUse.limit(bufferToUse.position() + size);
      buffer.position(bufferToUse.limit());
 
8
CodeRank
This code example shows how to use the following methods:write
    public int getBytes(int index, GatheringByteChannel out, int length)
            throws IOException { 
        byte[] b = new byte[length];
        is.read(b, index, length);
        ByteBuffer bb = ByteBuffer.wrap(b);
        return out.write(bb);
    } 
 
    public void setByte(int i, int i1) {
        throw new RuntimeException();
    } 
 
    public void getBytes(int index, OutputStream out, int length)
            throws IOException { 
        byte[] b = new byte[length];
        is.read(b, index, length);
        out.write(b, index, length);
    } 
 
    public void getBytes(int index, byte[] dst, int dstIndex, int length) {
7
CodeRank
This code example shows how to use the following methods:write
  public void writeInt(WritableByteChannel out, int intValue) throws IOException
  { 
    final ByteBuffer buffer = ByteBuffer.allocate(4);
    buffer.putInt(intValue);
    buffer.flip();
    out.write(buffer);
  } 
 
  public int readInt(InputStream in) throws IOException
  { 
    byte[] intBytes = new byte[4];
 
    ByteStreams.readFully(in, intBytes);
 
    return ByteBuffer.wrap(intBytes).getInt();
  } 
 
  public void writeInts(OutputStream out, int[] ints) throws IOException
  { 
    writeInt(out, ints.length);
6
CodeRank
This code example shows how to use the following methods:write
      StringWriter out  = new StringWriter(10240);
      ObjectMapper mapper = new ObjectMapper();
      mapper.writeValue(out, config);
      out.close();
      byte[] dataBytes = out.toString().getBytes();
      destChannel.write(ByteBuffer.wrap(dataBytes));
	} 
	 
	private void doGetConfig(DatabusRequest request) throws IOException, 
			RequestProcessingException 
	{ 
		ServerContainer.RuntimeConfig config = request.getConfig();
		serializeConfig(config, request.getResponseContent());
	} 
 
	private void doPutConfig(DatabusRequest request) throws IOException, 
			RequestProcessingException 
	{ 
		Properties cmdParams = request.getParams();
		try 
6
CodeRank
This code example shows how to use the following methods:clear, flip, limit
This code example shows how to use the following methods:flip, duplicate
  * @param      out   the output stream to which to write the data. 
  * @exception  IOException  if an I/O error occurs. 
  */ 
  public synchronized void writeTo(OutputStream out) throws IOException {
    WritableByteChannel channel = Channels.newChannel(out);
    ByteBuffer bb = buf.duplicate();
    bb.flip();
    channel.write(bb);
  } 
 
  @Override 
  public void write(byte[] b) throws IOException {
    checkSizeAndGrow(b.length);
 
    buf.put(b);
  } 
 
  @Override 
  public void write(byte[] b, int off, int len) throws IOException {
    checkSizeAndGrow(len);
7
CodeRank
This code example shows how to use the following methods:clear, flip, remaining
 
		_byteBuffer = ByteBuffer.allocate(bufferLength);
	} 
 
	public void ensureSpace(int length) throws IOException {
		if (_byteBuffer.remaining() < length) {
			write(); 
		} 
	} 
 
	public void finish() throws IOException {
		_byteBuffer.flip();
 
		_writableByteChannel.write(_byteBuffer);
	} 
 
	public ByteBuffer getBuffer() {
		return _byteBuffer;
	} 
 

7
CodeRank
This code example shows how to use the following methods:isOpen, write
   } 
 
   @Override 
   public int write(ByteBuffer src) throws IOException {
      checkOpen(); 
      return delegate.write(src);
   } 
 
   public void flush() throws IOException {
      gridOutputStream.flush();
   } 
 
   @Override 
   public boolean isOpen() { 
      return delegate.isOpen();
   } 
 
   @Override 
   public void close() throws IOException {
      delegate.close();
6
CodeRank
This code example shows how to use the following methods:rewind
        return TYPE;
    } 
 
    public void getBox(WritableByteChannel writableByteChannel) throws IOException {
        header.rewind();
        content.rewind();
        writableByteChannel.write(header);
        writableByteChannel.write(content);
    } 
 
    public long getSize() { 
        return header.limit() + content.limit();
    } 
 
    public void parse(ReadableByteChannel readableByteChannel, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException {
        this.header = header;
        if (readableByteChannel instanceof FileChannel && contentSize > 1024 * 1024) {
            // It's quite expensive to map a file into the memory. Just do it when the box is larger than a MB. 
            content = ((FileChannel) readableByteChannel).map(FileChannel.MapMode.READ_ONLY, ((FileChannel) readableByteChannel).position(), contentSize);
            ((FileChannel) readableByteChannel).position(((FileChannel) readableByteChannel).position() + contentSize);
6
CodeRank
This code example shows how to use the following methods:write
 
        public int write( ByteBuffer src )
            throws IOException 
        { 
            ByteBuffer event = src.slice();
            int written = delegate.write( src );
            if ( written > 0 )
            { 
                try 
                { 
                    event.limit( written );
                    completionHandler.fireTransferProgressed( event );
                } 
                catch ( TransferCancelledException e )
                { 
                    throw (IOException) new IOException( e.getMessage() ).initCause( e );
                } 
            } 
            return written;
        } 
5
CodeRank
write Method Overview
Writes a sequence of bytes to this channel from the given buffer.
See Code Examples for other Java 8 WritableByteChannel Methods: