Tabnine Logo
ByteBuffer.allocate
Code IndexAdd Tabnine to your IDE (free)

How to use
allocate
method
in
org.littleshoot.mina.common.ByteBuffer

Best Java code snippets using org.littleshoot.mina.common.ByteBuffer.allocate (Showing top 20 results out of 315)

origin: org.littleshoot/mina-port

/**
 * Returns the direct or heap buffer which is capable of the specified
 * size.  This method tries to allocate direct buffer first, and then
 * tries heap buffer if direct buffer memory is exhausted.  Please use
 * {@link #allocate(int, boolean)} to allocate buffers of specific type.
 *
 * @param capacity the capacity of the buffer
 */
public static ByteBuffer allocate(int capacity) {
  if (useDirectBuffers) {
    try {
      // first try to allocate direct buffer
      return allocate(capacity, true);
    } catch (OutOfMemoryError e) {
      // fall through to heap buffer
    }
  }
  return allocate(capacity, false);
}
origin: org.littleshoot/mina-port

private Context() {
  decoder = charset.newDecoder();
  buf = ByteBuffer.allocate(80).setAutoExpand(true);
}
origin: org.littleshoot/sip-stack

private Context()
  {
  decoder = charset.newDecoder();
  buf = ByteBuffer.allocate(80).setAutoExpand(true);
  }
origin: org.littleshoot/sip-stack

private ByteBuffer createDelimiterBuf(final String delimiter)
  {
  ByteBuffer tmp = ByteBuffer.allocate(delimiter.length());
  try
    {
    tmp.putString(delimiter, charset.newEncoder());
    tmp.flip();
    return tmp;
    }
  catch (CharacterCodingException e)
    {
    LOG.error("Bad charset?", e);
    return null;
    }
  }
origin: org.littleshoot/mina-port

public IoSessionInputStream() {
  buf = ByteBuffer.allocate(16);
  buf.setAutoExpand(true);
  buf.limit(0);
}
origin: org.littleshoot/mina-util

public IoSessionInputStream(final IoSession ioSession, 
  final int readTimeout)
  {
  m_ioSession = ioSession;
  m_readTimeout = readTimeout;
  m_buf = ByteBuffer.allocate(16);
  m_buf.setAutoExpand(true);
  m_buf.limit(0);
  }
origin: org.littleshoot/mina-port

@Override
public void write(int b) throws IOException {
  ByteBuffer buf = ByteBuffer.allocate(1);
  buf.put((byte) b);
  buf.flip();
  write(buf);
}
origin: org.littleshoot/mina-util

@Override
public void write(final int b) throws IOException
  {
  final ByteBuffer buf = ByteBuffer.allocate(1);
  buf.put((byte) b);
  buf.flip();
  write(buf);
  }
}
origin: org.littleshoot/mina-port

public Object readObject() throws ClassNotFoundException, IOException {
  int objectSize = in.readInt();
  if (objectSize <= 0) {
    throw new StreamCorruptedException("Invalid objectSize: "
        + objectSize);
  }
  if (objectSize > maxObjectSize) {
    throw new StreamCorruptedException("ObjectSize too big: "
        + objectSize + " (expected: <= " + maxObjectSize + ')');
  }
  ByteBuffer buf = ByteBuffer.allocate(objectSize + 4, false);
  buf.putInt(objectSize);
  in.readFully(buf.array(), 4, objectSize);
  buf.position(0);
  buf.limit(objectSize + 4);
  Object answer = buf.getObject(classLoader);
  buf.release();
  return answer;
}
origin: org.littleshoot/mina-util

private static ByteBuffer createBuffer(final ByteBuffer buffer)
  {
  final ByteBuffer data = ByteBuffer.allocate(
    buffer.limit() - buffer.position());
  
  LOG.trace("Created buffer with capacity: "+data.capacity());
  data.put(buffer);
  data.rewind();
  return data;
  }
origin: org.littleshoot/sip-stack

public ByteBuffer encode(final SipMessage message)
  {
  final ByteBuffer buffer = ByteBuffer.allocate(300);
  buffer.setAutoExpand(true);
  
  final SipMessageVisitor visitor = new EncoderVisitor(buffer);
  message.accept(visitor);
  buffer.flip();
  
  return buffer;
  }
origin: org.littleshoot/mina-util

/**
 * Combines the remaining data from the given <code>Collection</code> of
 * <code>ByteBuffer</code>s into a single consolidated 
 * <code>ByteBuffer</code>.
 * 
 * @param buffers The <code>Collection</code> of <code>ByteBuffer</code>s
 * to make into a single buffer.
 * @return A new <code>ByteBuffer</code> combining the remaining data of
 * the <code>Collection</code> of <code>ByteBuffer</code>s.
 */
public static ByteBuffer combine(final Collection<ByteBuffer> buffers)
  {
  final ByteBuffer buf = ByteBuffer.allocate(remaining(buffers));
  for (final ByteBuffer curBuf : buffers)
    {
    buf.put(curBuf);
    }
  buf.flip();
  return buf;
  }
 
origin: org.littleshoot/mina-util

private static ByteBuffer createBuffer(final ByteBuffer buffer)
  {
  // We calculate this here because the final split buffer will not
  // necessarily have a size equal to the chunk size -- it will
  // usually be smaller.
  final ByteBuffer data = ByteBuffer.allocate(
    buffer.limit() - buffer.position());
  
  data.put(buffer);
  data.flip();
  return data;
  }
origin: org.littleshoot/mina-port

  public void encode(IoSession session, Object message,
      ProtocolEncoderOutput out) throws Exception {
    if (!(message instanceof Serializable)) {
      throw new NotSerializableException();
    }

    ByteBuffer buf = ByteBuffer.allocate(64);
    buf.setAutoExpand(true);
    buf.putObject(message);

    int objectSize = buf.position() - 4;
    if (objectSize > maxObjectSize) {
      buf.release();
      throw new IllegalArgumentException(
          "The encoded object is too big: " + objectSize + " (> "
              + maxObjectSize + ')');
    }

    buf.flip();
    out.write(buf);
  }
}
origin: org.littleshoot/mina-port

public void writeObject(Object obj) throws IOException {
  ByteBuffer buf = ByteBuffer.allocate(64, false);
  buf.setAutoExpand(true);
  buf.putObject(obj);
  int objectSize = buf.position() - 4;
  if (objectSize > maxObjectSize) {
    buf.release();
    throw new IllegalArgumentException(
        "The encoded object is too big: " + objectSize + " (> "
            + maxObjectSize + ')');
  }
  out.write(buf.array(), 0, buf.position());
  buf.release();
}
origin: org.littleshoot/mina-port

public void encode(IoSession session, Object message,
    ProtocolEncoderOutput out) throws Exception {
  CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER);
  if (encoder == null) {
    encoder = charset.newEncoder();
    session.setAttribute(ENCODER, encoder);
  }
  String value = message.toString();
  ByteBuffer buf = ByteBuffer.allocate(value.length())
      .setAutoExpand(true);
  buf.putString(value, encoder);
  if (buf.position() > maxLineLength) {
    throw new IllegalArgumentException("Line length: " + buf.position());
  }
  buf.putString(delimiter.getValue(), encoder);
  buf.flip();
  out.write(buf);
}
origin: org.littleshoot/tcp-framing

/**
 * Encodes the TCP frame into a {@link ByteBuffer}.
 * 
 * @param frame The frame to encode.
 * @return The encoded frame in a {@link ByteBuffer}.
 */
public ByteBuffer encode(final TcpFrame frame)
  {
  final int length = frame.getLength();
  final ByteBuffer buf = ByteBuffer.allocate(2 + length);
  MinaUtils.putUnsignedShort(buf, length);
  buf.put(frame.getData());
  buf.flip();
  //m_log.debug("Encoded TCP Frame as buffer: {}", buf);
  return buf;
  }
origin: org.littleshoot/mina-port

  private void storeRemainingInSession(ByteBuffer buf, IoSession session) {
    ByteBuffer remainingBuf = ByteBuffer.allocate(buf.capacity());
    remainingBuf.setAutoExpand(true);
    remainingBuf.order(buf.order());
    remainingBuf.put(buf);
    session.setAttribute(BUFFER, remainingBuf);
  }
}
origin: org.littleshoot/mina-port

private void readSession(DatagramSessionImpl session) {
  ByteBuffer readBuf = ByteBuffer.allocate(session.getReadBufferSize());
  try {
    int readBytes = session.getChannel().read(readBuf.buf());
    if (readBytes > 0) {
      readBuf.flip();
      ByteBuffer newBuf = ByteBuffer.allocate(readBuf.limit());
      newBuf.put(readBuf);
      newBuf.flip();
      session.increaseReadBytes(readBytes);
      session.getFilterChain().fireMessageReceived(session, newBuf);
    }
  } catch (IOException e) {
    session.getFilterChain().fireExceptionCaught(session, e);
  } finally {
    readBuf.release();
  }
}
origin: org.littleshoot/stun-stack

private static UUID createTransactionId()
  {
  final UUID id = UUID.randomUUID();
  final byte[] idBytes = id.getRawBytes();
  final ByteBuffer idBuf = ByteBuffer.wrap(idBytes);
  
  // Lower the limit to make room for the magic cookie.
  idBuf.limit(idBytes.length - 4);
  
  final ByteBuffer newIdBuf = ByteBuffer.allocate(16);
  MinaUtils.putUnsignedInt(newIdBuf, MAGIC_COOKIE);
  newIdBuf.put(idBuf);
  newIdBuf.flip();
  
  return new UUID(MinaUtils.toByteArray(newIdBuf));
  }
org.littleshoot.mina.commonByteBufferallocate

Javadoc

Returns the direct or heap buffer which is capable of the specified size. This method tries to allocate direct buffer first, and then tries heap buffer if direct buffer memory is exhausted. Please use #allocate(int,boolean) to allocate buffers of specific type.

Popular methods of ByteBuffer

  • wrap
    Wraps the specified byte array into MINA heap buffer. Please note that MINA buffers are going to be
  • flip
  • put
  • setAllocator
    Changes the current allocator with the specified one to manage the allocated buffers from now.
  • setUseDirectBuffers
  • get
  • hasRemaining
  • limit
  • position
  • remaining
  • capacity
    Changes the capacity of this buffer.
  • clear
  • capacity,
  • clear,
  • duplicate,
  • getString,
  • getUnsigned,
  • getUnsignedInt,
  • getUnsignedShort,
  • putString,
  • setAutoExpand

Popular in Java

  • Start an intent from android
  • requestLocationUpdates (LocationManager)
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (Timer)
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JFrame (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now