Java 8 WritableByteChannel - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 WritableByteChannel class.

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
    return new IndexedIntsIterator(this);
  } 
 
  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());
6
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
      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: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:write
This code example shows how to use the following methods:close, isOpen
	public void sessionClosed(NextFilter next, IoSession session)
			throws Exception { 
		if (headers.isOpen()) {
			headers.close();
		} 
		if (raw.isOpen()) {
			raw.close();
		} 
		next.sessionClosed(session);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:close
 
    public void shutdown() { 
      keepRunning = false;
      this.interrupt();
      try { 
        out.close();
      } catch (IOException e) {
        e.printStackTrace();
      } 
    } 
 
    public void run() { 
      byte[] bytes = new byte[4096];
      ByteBuffer buffer = ByteBuffer.wrap(bytes);
      try { 
        while (keepRunning) {
          int count = in.read(bytes);
          // 0 = nothing read 
          // -1 = EOF 
          if (count <= 0) {
5
CodeRank
This code example shows how to use the following methods:write
This code example shows how to use the following methods:close
        } 
 
        public void close() 
            throws IOException 
        { 
            delegate.close();
        } 
 
        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 );
                } 
5
CodeRank

Related Java 8 WritableByteChannel Questions & Answers:

See Code Examples for Java 8 WritableByteChannel Methods: