congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
LinkedBuffer.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
io.protostuff.LinkedBuffer
constructor

Best Java code snippets using io.protostuff.LinkedBuffer.<init> (Showing top 20 results out of 315)

origin: protostuff/protostuff

/**
 * Wraps the byte array buffer as a read-only buffer.
 */
public static LinkedBuffer wrap(byte[] array, int offset, int length)
{
  return new LinkedBuffer(array, offset, offset + length);
}
origin: protostuff/protostuff

/**
 * Allocates a new buffer with default size.
 */
public static LinkedBuffer allocate()
{
  return new LinkedBuffer(DEFAULT_BUFFER_SIZE);
}
origin: protostuff/protostuff

@Override
public LinkedBuffer drain(final WriteSession session,
    final LinkedBuffer lb) throws IOException
{
  // grow
  return new LinkedBuffer(session.nextBufferSize, lb);
}
origin: protostuff/protostuff

@Override
public LinkedBuffer writeByte(final byte value,
    final WriteSession session, LinkedBuffer lb) throws IOException
{
  session.size++;
  if (lb.offset == lb.buffer.length)
  {
    // grow
    lb = new LinkedBuffer(session.nextBufferSize, lb);
  }
  lb.buffer[lb.offset++] = value;
  return lb;
}
origin: protostuff/protostuff

/**
 * Uses the existing byte array as the internal buffer.
 */
public static LinkedBuffer use(byte[] buffer, int start)
{
  assert start >= 0;
  if (buffer.length - start < MIN_BUFFER_SIZE)
    throw new IllegalArgumentException(MIN_BUFFER_SIZE + " is the minimum buffer size.");
  return new LinkedBuffer(buffer, start, start);
}
origin: protostuff/protostuff

/**
 * Allocates a new buffer with the specified size and appends it to the previous buffer.
 */
public static LinkedBuffer allocate(int size, LinkedBuffer previous)
{
  if (size < MIN_BUFFER_SIZE)
    throw new IllegalArgumentException(MIN_BUFFER_SIZE + " is the minimum buffer size.");
  return new LinkedBuffer(size, previous);
}
origin: protostuff/protostuff

/**
 * Allocates a new buffer with the specified size.
 */
public static LinkedBuffer allocate(int size)
{
  if (size < MIN_BUFFER_SIZE)
    throw new IllegalArgumentException(MIN_BUFFER_SIZE + " is the minimum buffer size.");
  return new LinkedBuffer(size);
}
origin: protostuff/protostuff

private void writeStartArray()
{
  if (tail.buffer.length - tail.offset < MAX_ARRAYHEADER_SIZE)
  {
    tail = new LinkedBuffer(this.nextBufferSize, tail);
  }
  arrayHeader = tail;
  tail = LinkedBuffer.wrap(tail.buffer, tail.offset + MAX_ARRAYHEADER_SIZE, 0);
  arrayHeader.next = tail;
  arraySize = 1;
}
origin: protostuff/protostuff

public LinkedBuffer writeStartObject()
{
  LinkedBuffer objectHeader;
  
  if (tail.buffer.length - tail.offset < MAX_MAPHEADER_SIZE)
  {
    tail = new LinkedBuffer(this.nextBufferSize, tail);
  }
  objectHeader = tail;
  tail = LinkedBuffer.wrap(tail.buffer, tail.offset + MAX_MAPHEADER_SIZE, 0);
  objectHeader.next = tail;
  return objectHeader;
}
origin: protostuff/protostuff

static LinkedBuffer newBuffer(int size, char c, int loops)
{
  LinkedBuffer lb = new LinkedBuffer(size);
  while (loops-- > 0)
  {
    lb.buffer[lb.offset++] = (byte) c;
  }
  return lb;
}
origin: protostuff/protostuff

@Override
public LinkedBuffer writeInt16(final int value,
    final WriteSession session, LinkedBuffer lb) throws IOException
{
  session.size += 2;
  if (lb.offset + 2 > lb.buffer.length)
  {
    // grow
    lb = new LinkedBuffer(session.nextBufferSize, lb);
  }
  IntSerializer.writeInt16(value, lb.buffer, lb.offset);
  lb.offset += 2;
  return lb;
}
origin: protostuff/protostuff

@Override
public LinkedBuffer writeInt32(final int value,
    final WriteSession session, LinkedBuffer lb) throws IOException
{
  session.size += 4;
  if (lb.offset + 4 > lb.buffer.length)
  {
    // grow
    lb = new LinkedBuffer(session.nextBufferSize, lb);
  }
  IntSerializer.writeInt32(value, lb.buffer, lb.offset);
  lb.offset += 4;
  return lb;
}
origin: protostuff/protostuff

public <T> int writeListTo(OutputStream out, List<T> messages, Schema<T> schema)
    throws IOException
{
  return ProtostuffIOUtil.writeListTo(out, messages, schema,
      new LinkedBuffer(LinkedBuffer.DEFAULT_BUFFER_SIZE));
}
origin: protostuff/protostuff

static <T> byte[] toByteArrayBufferedProtobuf(T message, Schema<T> schema)
{
  final ProtobufOutput output = new ProtobufOutput(new LinkedBuffer(BUF_SIZE));
  try
  {
    schema.writeTo(output, message);
  }
  catch (IOException e)
  {
    throw new RuntimeException("Serializing to a byte array threw an IOException " +
        "(should never happen).", e);
  }
  return output.toByteArray();
}
origin: protostuff/protostuff

static <T> byte[] toByteArrayBufferedProtostuff(T message, Schema<T> schema)
{
  final ProtostuffOutput output = new ProtostuffOutput(new LinkedBuffer(BUF_SIZE));
  try
  {
    schema.writeTo(output, message);
  }
  catch (IOException e)
  {
    throw new RuntimeException("Serializing to a byte array threw an IOException " +
        "(should never happen).", e);
  }
  return output.toByteArray();
}
origin: protostuff/protostuff

public void testPartialSurrogatePair() throws Exception
{
  // Make sure that we don't overflow or get out of bounds,
  // since pairs require 2 characters.
  String partial = "\uD83C";
  // 3 bytes can't hold a 4-byte encoding, but we
  // don't expect it to use the 4-byte encoding path,
  // since it's not a pair
  LinkedBuffer lb = new LinkedBuffer(3);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  WriteSession session = new WriteSession(lb, out);
  StreamedStringSerializer.writeUTF8(partial, session, lb);
  byte[] buffered = session.toByteArray();
}
origin: protostuff/protostuff

static void checkVarDelimited(CharSequence str, int size, int stringLen) throws Exception
{
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
  WriteSession session = new WriteSession(lb, out);
  StreamedStringSerializer.writeUTF8VarDelimited(str, session, lb);
  LinkedBuffer.writeTo(out, lb);
  byte[] buf = out.toByteArray();
  assertTrue(buf.length == stringLen + size);
  int len = readRawVarint32(buf, 0);
  assertTrue(len == stringLen);
  print("total len: " + buf.length);
}
origin: protostuff/protostuff

public void checkVarDelimitedBoundry(int initialGap, int secondWriteSize) throws IOException
{
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int bufferSize = BUF_SIZE;
  final LinkedBuffer lb = new LinkedBuffer(bufferSize);
  WriteSession session = new WriteSession(lb, out, null, bufferSize);
  // Should fill up the buffer with initialGap byte(s) left
  StreamedStringSerializer.writeUTF8(repeatChar('a', bufferSize - initialGap), session, lb);
  // Write a string of length secondWriteSize that should be larger
  // than the next buffer size
  assertTrue(secondWriteSize > bufferSize);
  StreamedStringSerializer.writeUTF8VarDelimited(repeatChar('a', secondWriteSize), session, lb);
}
origin: protostuff/protostuff

public void testStream() throws Exception
{
  // everything will fit
  testStream("1234567", new LinkedBuffer(12));
  // need to flush once
  testStream("1234567", str('a', 4), newBuffer(12, 'a', 4));
  // 1 write chunk and encode remaining
  testStream("1234567", new LinkedBuffer(4));
  // no write chunks and encode remaining
  testStream("1234567", str('a', 1), newBuffer(4, 'a', 1));
  // 1 write chunk and encode remaining
  testStream("1234567", str('a', 4), newBuffer(8, 'a', 4));
}
origin: protostuff/protostuff

static void checkVarDelimited(CharSequence str, int size, int stringLen) throws Exception
{
  LinkedBuffer lb = new LinkedBuffer(512);
  WriteSession session = new WriteSession(lb);
  StringSerializer.writeUTF8VarDelimited(str, session, lb);
  byte[] buf = session.toByteArray();
  assertTrue(buf.length == stringLen + size);
  int len = readRawVarint32(lb.buffer, 0);
  assertTrue(len == stringLen);
  print("total len: " + buf.length);
}
io.protostuffLinkedBuffer<init>

Javadoc

Creates a buffer with the specified size.

Popular methods of LinkedBuffer

  • allocate
    Allocates a new buffer with the specified size and appends it to the previous buffer.
  • clear
  • writeTo
  • use
    Uses the existing byte array as the internal buffer.
  • wrap
    Wraps the byte array buffer as a read-only buffer.

Popular in Java

  • Reactive rest calls using spring rest template
  • startActivity (Activity)
  • getResourceAsStream (ClassLoader)
  • notifyDataSetChanged (ArrayAdapter)
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Permission (java.security)
    Legacy security code; do not use.
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Top plugins for WebStorm
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