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

How to use
WriteSession
in
io.protostuff

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

origin: protostuff/protostuff

@Override
public JsonXOutput clear()
{
  super.clear();
  return this;
}
origin: protostuff/protostuff

@Benchmark
public byte[] bufferedSerializer()
{
  try
  {
    final WriteSession session = new WriteSession(sharedBuffer);
    StringSerializer.writeUTF8(s, session, sharedBuffer);
    return session.toByteArray();
  }
  finally
  {
    sharedBuffer.clear();
  }
}
origin: protostuff/protostuff

private static void flushAndReset(LinkedBuffer node, final WriteSession session)
    throws IOException
{
  int len;
  do
  {
    if ((len = node.offset - node.start) > 0)
      node.offset = session.flush(node, node.buffer, node.start, len);
  } while ((node = node.next) != null);
}
origin: protostuff/protostuff

@Benchmark
public byte[] bufferedRecycledSerializer()
{
  final WriteSession session = this.sharedSession;
  try
  {
    StringSerializer.writeUTF8(s, session, session.head);
    return session.toByteArray();
  }
  finally
  {
    session.clear();
  }
}
origin: protostuff/protostuff

public void testParseInt() throws Exception
{
  assertTrue(0 == NumberParser.parseInt(new byte[] { '0' }, 0, 1, 10));
  assertTrue(1 == NumberParser.parseInt(new byte[] { '1' }, 0, 1, 10));
  assertTrue(-1 == NumberParser.parseInt(new byte[] { '-', '1' }, 0, 2, 10));
  final LinkedBuffer lb = LinkedBuffer.allocate(256);
  final WriteSession session = new WriteSession(lb);
  assertTrue(lb == StringSerializer.writeInt(
      Integer.MAX_VALUE, session, session.tail));
  assertTrue(Integer.MAX_VALUE == NumberParser.parseInt(
      session.toByteArray(), 0, session.size, 10));
  session.clear();
  assertTrue(lb == StringSerializer.writeInt(
      Integer.MAX_VALUE - 1, session, session.tail));
  assertTrue(Integer.MAX_VALUE - 1 == NumberParser.parseInt(
      session.toByteArray(), 0, session.size, 10));
  session.clear();
  assertTrue(lb == StringSerializer.writeInt(
      Integer.MIN_VALUE, session, session.tail));
  assertTrue(Integer.MIN_VALUE == NumberParser.parseInt(
      session.toByteArray(), 0, session.size, 10));
  session.clear();
  assertTrue(lb == StringSerializer.writeInt(
      Integer.MIN_VALUE + 1, session, session.tail));
  assertTrue(Integer.MIN_VALUE + 1 == NumberParser.parseInt(
      session.toByteArray(), 0, session.size, 10));
}
origin: fengjiachun/Jupiter

public static byte[] toByteArray(Output output) {
  if (output instanceof WriteSession) {
    return ((WriteSession) output).toByteArray();
  }
  throw new IllegalArgumentException("Output [" + Reflects.simpleClassName(output)
      + "] must be a WriteSession's implementation");
}
origin: protostuff/protostuff

@Setup
public void prepare() throws IOException
{
  sharedBuffer = LinkedBuffer.allocate(512);
  sharedSession = new WriteSession(sharedBuffer);
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < stringLength; i++)
  {
    sb.append('.');
  }
  s = sb.toString();
}
origin: protostuff/protostuff

public void testParseLong() throws IOException
{
  assertTrue(0l == NumberParser.parseLong(new byte[] { '0' }, 0, 1, 10));
  assertTrue(1l == NumberParser.parseLong(new byte[] { '1' }, 0, 1, 10));
  assertTrue(-1l == NumberParser.parseLong(new byte[] { '-', '1' }, 0, 2, 10));
  final LinkedBuffer lb = LinkedBuffer.allocate(256);
  final WriteSession session = new WriteSession(lb);
  assertTrue(lb == StringSerializer.writeLong(
      Long.MAX_VALUE, session, session.tail));
  assertTrue(Long.MAX_VALUE == NumberParser.parseLong(
      session.toByteArray(), 0, session.size, 10));
  session.clear();
  assertTrue(lb == StringSerializer.writeLong(
      Long.MAX_VALUE - 1, session, session.tail));
  assertTrue(Long.MAX_VALUE - 1 == NumberParser.parseLong(
      session.toByteArray(), 0, session.size, 10));
  session.clear();
  assertTrue(lb == StringSerializer.writeLong(
      Long.MIN_VALUE, session, session.tail));
  assertTrue(Long.MIN_VALUE == NumberParser.parseLong(
      session.toByteArray(), 0, session.size, 10));
  session.clear();
  assertTrue(lb == StringSerializer.writeLong(
      Long.MIN_VALUE + 1, session, session.tail));
  assertTrue(Long.MIN_VALUE + 1 == NumberParser.parseLong(
      session.toByteArray(), 0, session.size, 10));
}
origin: fengjiachun/Jupiter

public static byte[] toByteArray(Output output) {
  if (output instanceof WriteSession) {
    return ((WriteSession) output).toByteArray();
  }
  throw new IllegalArgumentException("Output [" + Reflects.simpleClassName(output)
      + "] must be a WriteSession's implementation");
}
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

static void testBuffer(String str, String prefix, LinkedBuffer tail, int nextBufferSize) throws IOException
{
  byte[] data = str.getBytes();
  WriteSession session = new WriteSession(tail, nextBufferSize);
  session.size += (tail.offset - tail.start);
  tail = B64Code.encode(data, 0, data.length, session, tail);
  byte[] result = session.toByteArray();
  verifyB64(str, prefix, result);
}
origin: protostuff/protostuff

@Override
public XmlXOutput clear()
{
  super.clear();
  return this;
}
origin: org.jupiter-rpc/jupiter-all

public static byte[] toByteArray(Output output) {
  if (output instanceof WriteSession) {
    return ((WriteSession) output).toByteArray();
  }
  throw new IllegalArgumentException("Output [" + Reflects.simpleClassName(output)
      + "] must be a WriteSession's implementation");
}
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

@Override
public LinkedBuffer drain(final WriteSession session,
    final LinkedBuffer lb) throws IOException
{
  // flush and reset
  lb.offset = session.flush(lb.buffer, lb.start, lb.offset - lb.start);
  return lb;
}
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

/**
 * Resets this output for re-use.
 */
@Override
public ProtostuffOutput clear()
{
  super.clear();
  return this;
}
origin: org.jupiter-rpc/jupiter-serialization-protostuff

public static byte[] toByteArray(Output output) {
  if (output instanceof WriteSession) {
    return ((WriteSession) output).toByteArray();
  }
  throw new IllegalArgumentException("Output [" + Reflects.simpleClassName(output)
      + "] must be a WriteSession's implementation");
}
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

@Override
public LinkedBuffer writeByte(final byte value,
    final WriteSession session, LinkedBuffer lb) throws IOException
{
  session.size++;
  if (lb.offset == lb.buffer.length)
  {
    // flush and reset
    lb.offset = session.flush(lb.buffer, lb.start, lb.offset - lb.start);
  }
  lb.buffer[lb.offset++] = value;
  return lb;
}
io.protostuffWriteSession

Javadoc

Designed to be subclassed by implementations of Output for easier serialization code for streaming or full buffering. This is used when objects need to be serialzied/written into a LinkedBuffer.

Most used methods

  • clear
  • toByteArray
  • <init>
  • flush

Popular in Java

  • Running tasks concurrently on multiple threads
  • onRequestPermissionsResult (Fragment)
  • compareTo (BigDecimal)
  • setRequestProperty (URLConnection)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • Menu (java.awt)
  • Collectors (java.util.stream)
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • JTable (javax.swing)
  • 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