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

How to use
writeTo
method
in
io.protostuff.LinkedBuffer

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

origin: protostuff/protostuff

/**
 * Serializes the {@code message} into an {@link OutputStream} using the given schema.
 * 
 * @return the size of the message
 */
public static <T> int writeTo(OutputStream out, T message, Schema<T> schema,
    LinkedBuffer buffer) throws IOException
{
  if (buffer.start != buffer.offset)
    throw new IllegalArgumentException("Buffer previously used and had not been reset.");
  final ProtobufOutput output = new ProtobufOutput(buffer);
  schema.writeTo(output, message);
  return LinkedBuffer.writeTo(out, buffer);
}
origin: protostuff/protostuff

/**
 * Serializes the {@code message} into an {@link OutputStream} using the given schema.
 * 
 * @return the size of the message
 */
public static <T> int writeTo(final OutputStream out, final T message,
    final Schema<T> schema, final LinkedBuffer buffer) throws IOException
{
  if (buffer.start != buffer.offset)
    throw new IllegalArgumentException("Buffer previously used and had not been reset.");
  final ProtostuffOutput output = new ProtostuffOutput(buffer, out);
  schema.writeTo(output, message);
  LinkedBuffer.writeTo(out, buffer);
  return output.size;
}
origin: protostuff/protostuff

/**
 * Serializes the {@code message}, prefixed with its length, into an {@link OutputStream}.
 * 
 * @return the size of the message
 */
public static <T> int writeDelimitedTo(final OutputStream out, final T message,
    final Schema<T> schema, final LinkedBuffer buffer) throws IOException
{
  if (buffer.start != buffer.offset)
    throw new IllegalArgumentException("Buffer previously used and had not been reset.");
  final ProtostuffOutput output = new ProtostuffOutput(buffer);
  schema.writeTo(output, message);
  ProtobufOutput.writeRawVarInt32Bytes(out, output.size);
  LinkedBuffer.writeTo(out, buffer);
  return output.size;
}
origin: protostuff/protostuff

/**
 * Serializes the {@code message} into an {@link OutputStream} using the given schema.
 * 
 * @return the size of the message
 */
public static <T> int writeTo(final OutputStream out, final T message,
    final Schema<T> schema, final LinkedBuffer buffer) throws IOException
{
  if (buffer.start != buffer.offset)
    throw new IllegalArgumentException("Buffer previously used and had not been reset.");
  final ProtostuffOutput output = new ProtostuffOutput(buffer, out);
  final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output);
  schema.writeTo(graphOutput, message);
  LinkedBuffer.writeTo(out, buffer);
  return output.size;
}
origin: protostuff/protostuff

/**
 * Serializes the {@code message}, prefixed with its length, into an {@link OutputStream}.
 * 
 * @return the size of the message
 */
public static <T> int writeDelimitedTo(final OutputStream out, final T message,
    final Schema<T> schema, final LinkedBuffer buffer) throws IOException
{
  if (buffer.start != buffer.offset)
    throw new IllegalArgumentException("Buffer previously used and had not been reset.");
  final ProtostuffOutput output = new ProtostuffOutput(buffer);
  final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output);
  schema.writeTo(graphOutput, message);
  ProtobufOutput.writeRawVarInt32Bytes(out, output.size);
  LinkedBuffer.writeTo(out, buffer);
  return output.size;
}
origin: protostuff/protostuff

/**
 * Serializes the {@code message}, prefixed with its length, into an {@link OutputStream}.
 * 
 * @return the size of the message
 */
public static <T> int writeDelimitedTo(OutputStream out, T message, Schema<T> schema,
    LinkedBuffer buffer) throws IOException
{
  if (buffer.start != buffer.offset)
    throw new IllegalArgumentException("Buffer previously used and had not been reset.");
  final ProtobufOutput output = new ProtobufOutput(buffer);
  schema.writeTo(output, message);
  final int size = output.getSize();
  ProtobufOutput.writeRawVarInt32Bytes(out, size);
  final int msgSize = LinkedBuffer.writeTo(out, buffer);
  assert size == msgSize;
  return size;
}
origin: protostuff/protostuff

/**
 * Used by the code generated messages that implement {@link java.io.Externalizable}. Writes to the
 * {@link DataOutput} .
 * 
 * @return the size of the message.
 */
public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema)
    throws IOException
{
  final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE);
  final ProtostuffOutput output = new ProtostuffOutput(buffer);
  schema.writeTo(output, message);
  ProtobufOutput.writeRawVarInt32Bytes(out, output.size);
  LinkedBuffer.writeTo(out, buffer);
  return output.size;
}
origin: protostuff/protostuff

static void checkFixedDelimited(CharSequence str) throws Exception
{
  ByteArrayOutputStream bout = new ByteArrayOutputStream();
  OutputStreamWriter writer = new OutputStreamWriter(bout, "UTF-8");
  bout.write(getShortStringLengthInBytes(str));
  writer.write(str.toString(), 0, str.length());
  writer.close();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
  WriteSession session = new WriteSession(lb, out);
  StreamedStringSerializer.writeUTF8FixedDelimited(str, session, lb);
  LinkedBuffer.writeTo(out, lb);
  byte[] b1 = bout.toByteArray();
  byte[] b2 = out.toByteArray();
  assertEquals(b1, b2);
}
origin: protostuff/protostuff

/**
 * Serializes the {@code message} into an {@link OutputStream} via {@link JsonXOutput} using the given
 * {@code schema}.
 */
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema, boolean numeric,
    LinkedBuffer buffer) throws IOException
{
  if (buffer.start != buffer.offset)
    throw new IllegalArgumentException("Buffer previously used and had not been reset.");
  final JsonXOutput output = new JsonXOutput(buffer, out, numeric, schema);
  output.writeStartObject();
  schema.writeTo(output, message);
  if (output.isLastRepeated())
    output.writeEndArray();
  output.writeEndObject();
  LinkedBuffer.writeTo(out, buffer);
}
origin: protostuff/protostuff

@Override
protected <T> byte[] toByteArray(T message, Schema<T> schema)
{
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  LinkedBuffer buffer = buf();
  final KvpOutput output = new KvpOutput(buffer, out, schema, numeric);
  try
  {
    schema.writeTo(output, message);
    LinkedBuffer.writeTo(out, buffer);
  }
  catch (IOException e)
  {
    throw new RuntimeException("Serializing to a byte array threw an IOException " +
        "(should never happen).", e);
  }
  byte[] data = out.toByteArray();
  // System.err.println(data.length + " | " + getClass().getSimpleName());
  return data;
}
origin: protostuff/protostuff

/**
 * Used by the code generated messages that implement {@link java.io.Externalizable}. Writes to the
 * {@link DataOutput} .
 * 
 * @return the size of the message.
 */
public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema)
    throws IOException
{
  final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE);
  final ProtostuffOutput output = new ProtostuffOutput(buffer);
  final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output);
  schema.writeTo(graphOutput, message);
  ProtobufOutput.writeRawVarInt32Bytes(out, output.size);
  LinkedBuffer.writeTo(out, buffer);
  return output.size;
}
origin: protostuff/protostuff

/**
 * Used by the code generated messages that implement {@link java.io.Externalizable}. Writes to the
 * {@link DataOutput} .
 * 
 * @return the size of the message.
 */
public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema)
    throws IOException
{
  final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE);
  final ProtobufOutput output = new ProtobufOutput(buffer);
  schema.writeTo(output, message);
  final int size = output.getSize();
  ProtobufOutput.writeRawVarInt32Bytes(out, size);
  final int msgSize = LinkedBuffer.writeTo(out, buffer);
  assert size == msgSize;
  return size;
}
origin: protostuff/protostuff

public void testInt() throws Exception
{
  for (int i : int_targets)
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
    WriteSession session = new WriteSession(lb, out);
    StreamedStringSerializer.writeInt(i, session, lb);
    LinkedBuffer.writeTo(out, lb);
    ByteArrayOutputStream out2 = new ByteArrayOutputStream();
    LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE);
    WriteSession session2 = new WriteSession(lb2, out2);
    StreamedStringSerializer.writeInt(i, session2, lb2);
    LinkedBuffer.writeTo(out2, lb2);
    byte[] buffered = out.toByteArray();
    byte[] buffered_needed_to_flush = out2.toByteArray();
    byte[] builtin = STRING.ser(Integer.toString(i));
    assertEquals(builtin, buffered);
    assertEquals(builtin, buffered_needed_to_flush);
  }
}
origin: protostuff/protostuff

static void checkAscii(CharSequence str) throws Exception
{
  byte[] builtin = str.toString().getBytes("UTF-8");
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
  WriteSession session = new WriteSession(lb, out);
  StreamedStringSerializer.writeAscii(str, session, lb);
  LinkedBuffer.writeTo(out, lb);
  assertTrue(builtin.length == session.size);
  byte[] buffered = out.toByteArray();
  assertTrue(builtin.length == buffered.length);
  String strBuiltin = new String(builtin, "ASCII");
  String strBuffered = new String(buffered, "ASCII");
  assertEquals(strBuiltin, strBuffered);
  print(strBuiltin);
  print("len: " + builtin.length);
}
origin: protostuff/protostuff

public void testDouble() throws Exception
{
  for (double i : double_targets)
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
    WriteSession session = new WriteSession(lb, out);
    StreamedStringSerializer.writeDouble(i, session, lb);
    LinkedBuffer.writeTo(out, lb);
    ByteArrayOutputStream out2 = new ByteArrayOutputStream();
    LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE);
    WriteSession session2 = new WriteSession(lb2, out2);
    StreamedStringSerializer.writeDouble(i, session2, lb2);
    LinkedBuffer.writeTo(out2, lb2);
    byte[] buffered = out.toByteArray();
    byte[] buffered_needed_to_flush = out2.toByteArray();
    byte[] builtin = STRING.ser(Double.toString(i));
    assertEquals(builtin, buffered);
    assertEquals(builtin, buffered_needed_to_flush);
  }
}
origin: protostuff/protostuff

public void testLong() throws Exception
{
  for (long i : long_targets)
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
    WriteSession session = new WriteSession(lb, out);
    StreamedStringSerializer.writeLong(i, session, lb);
    LinkedBuffer.writeTo(out, lb);
    ByteArrayOutputStream out2 = new ByteArrayOutputStream();
    LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE);
    WriteSession session2 = new WriteSession(lb2, out2);
    StreamedStringSerializer.writeLong(i, session2, lb2);
    LinkedBuffer.writeTo(out2, lb2);
    byte[] buffered = out.toByteArray();
    byte[] buffered_needed_to_flush = out2.toByteArray();
    byte[] builtin = STRING.ser(Long.toString(i));
    assertEquals(builtin, buffered);
    assertEquals(builtin, buffered_needed_to_flush);
  }
}
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

static void check(CharSequence str) throws Exception
{
  byte[] builtin = str.toString().getBytes("UTF-8");
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
  WriteSession session = new WriteSession(lb, out);
  StreamedStringSerializer.writeUTF8(str, session, lb);
  LinkedBuffer.writeTo(out, lb);
  assertTrue(builtin.length == session.size);
  byte[] buffered = out.toByteArray();
  assertTrue(builtin.length == buffered.length);
  String strBuiltin = new String(builtin, "UTF-8");
  String strBuffered = new String(buffered, "UTF-8");
  assertEquals(strBuiltin, strBuffered);
  assertTrue(Arrays.equals(builtin, buffered));
  assertEquals(STRING.deser(builtin), STRING.deser(buffered));
  print(strBuiltin);
  print("len: " + builtin.length);
}
origin: protostuff/protostuff

static void testStream(String str, String prefix, LinkedBuffer tail) throws IOException
{
  byte[] copy = new byte[tail.offset - tail.start];
  System.arraycopy(tail.buffer, tail.start, copy, 0, tail.offset - tail.start);
  byte[] data = str.getBytes();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  WriteSession session = new WriteSession(tail, out);
  session.size += (tail.offset - tail.start);
  tail = B64Code.sencode(data, 0, data.length, session, tail);
  assertTrue(tail == session.head);
  LinkedBuffer.writeTo(out, tail);
  byte[] dataFromStream = out.toByteArray();
  verifyB64(str, prefix, dataFromStream);
  WriteSession bws = new WriteSession(new LinkedBuffer(copy, 0));
  bws.tail.offset += copy.length;
  bws.size += copy.length;
  bws.tail = B64Code.encode(data, 0, data.length, bws, bws.tail);
  assertTrue(Arrays.equals(dataFromStream, bws.toByteArray()));
  // System.err.println(gg.length + " == " + decoded.length + " | " +
  // str.equals(strd) + " | " + str + " == " + strd);
}
origin: protostuff/protostuff

public void testBarList() throws Exception
{
  Bar barCompare = bar;
  ArrayList<Bar> list = new ArrayList<Bar>();
  list.add(bar);
  list.add(negativeBar);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int total = writeListTo(out, list, barCompare.cachedSchema());
  ByteArrayOutputStream out2 = new ByteArrayOutputStream();
  LinkedBuffer buffer = new LinkedBuffer(512);
  int total2 = writeListTo(buffer, list, barCompare.cachedSchema());
  LinkedBuffer.writeTo(out2, buffer);
  byte[] data = out.toByteArray();
  byte[] data2 = out2.toByteArray();
  assertTrue(data.length == total);
  assertTrue(data2.length == total2);
  assertTrue(total == total2);
  String text = STRING.deser(data);
  String text2 = STRING.deser(data2);
  assertEquals(text, text2);
  print(text);
}
io.protostuffLinkedBufferwriteTo

Javadoc

Writes the contents of the LinkedBuffer into the DataOutput.

Popular methods of LinkedBuffer

  • allocate
  • clear
  • <init>
    Uses the buffer starting at the specified offset and appends to the provided buffer appendTarget.
  • 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)
  • setContentView (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Top 12 Jupyter Notebook extensions
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