Package java.nio

Examples of java.nio.ByteBuffer.limit()


  private void broadcast (int udpPort, DatagramSocket socket) throws IOException {
    int classID = kryo.getRegisteredClass(DiscoverHost.class).getID();
    ByteBuffer dataBuffer = ByteBuffer.allocate(4);
    IntSerializer.put(dataBuffer, classID, true);
    dataBuffer.flip();
    byte[] data = new byte[dataBuffer.limit()];
    dataBuffer.get(data);
    for (NetworkInterface iface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
      for (InetAddress address : Collections.list(iface.getInetAddresses())) {
        if (!address.isSiteLocalAddress()) continue;
        // Java 1.5 doesn't support getting the subnet mask, so try the two most common.
View Full Code Here


        byte[] bytes;
        ByteBuffer byteBuffer= encoder.encode(CharBuffer.wrap(document.get()));
        if (byteBuffer.hasArray())
          bytes= byteBuffer.array();
        else {
          bytes= new byte[byteBuffer.limit()];
          byteBuffer.get(bytes);
        }
        stream= new ByteArrayInputStream(bytes, 0, byteBuffer.limit());
      } catch (CharacterCodingException ex) {
        Assert.isTrue(ex instanceof UnmappableCharacterException);
View Full Code Here

          bytes= byteBuffer.array();
        else {
          bytes= new byte[byteBuffer.limit()];
          byteBuffer.get(bytes);
        }
        stream= new ByteArrayInputStream(bytes, 0, byteBuffer.limit());
      } catch (CharacterCodingException ex) {
        Assert.isTrue(ex instanceof UnmappableCharacterException);
        String message= "Charset mapping failed.";
        IStatus s= new Status(IStatus.ERROR, Plugin.PLUGIN_ID, EditorsUI.CHARSET_MAPPING_FAILED, message, null);
        throw new CoreException(s);
View Full Code Here

    buffer.putInt(length);
    buffer.put(type);
    buffer.put(contentPayload);
   
    buffer.position(4);
    buffer.limit(length + 8);
   
    long crc = crc(buffer);
    buffer.limit(length + 12);
    buffer.putInt((int)crc);
   
View Full Code Here

   
    buffer.position(4);
    buffer.limit(length + 8);
   
    long crc = crc(buffer);
    buffer.limit(length + 12);
    buffer.putInt((int)crc);
   
    buffer.position(0);
    return buffer.array();
   
View Full Code Here

          break;
        }

        ByteBuffer  b = (ByteBuffer)read_buffers.get(0);
               
        int  old_limit = b.limit();
       
        if ( b.remaining() > rem ){
         
          b.limit( b.position() + rem );
        }
View Full Code Here

               
        int  old_limit = b.limit();
       
        if ( b.remaining() > rem ){
         
          b.limit( b.position() + rem );
        }
       
        buffer.put( b );
       
        b.limit( old_limit );
View Full Code Here

          b.limit( b.position() + rem );
        }
       
        buffer.put( b );
       
        b.limit( old_limit );
       
        total += rem - buffer.remaining();
       
        if ( b.hasRemaining()){
         
View Full Code Here

        Debug.out( "preReadProcess:: bb["+i+"] == null, decoder destroyed=" +destroyed );
      }
     
     
      if( shrink_remaining_buffers ) {
        bb.limit( 0 )//ensure no read into this next buffer is possible
      }
      else {
        int remaining = bb.remaining();
       
        if( remaining < 1 continue//skip full buffer
View Full Code Here

          pre_read_start_position = bb.position();
          marked = true;
        }

        if( remaining > allowed ) {  //read only part of this buffer
          bb.limit( bb.position() + allowed )//limit current buffer
          bytes_available += bb.remaining();
          shrink_remaining_buffers = true//shrink any tail buffers
        }
        else //full buffer is allowed to be read
          bytes_available += remaining;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.