co.cask.tigon.io
Class BufferedEncoder

java.lang.Object
  extended by co.cask.tigon.io.BufferedEncoder
All Implemented Interfaces:
Encoder

public final class BufferedEncoder
extends Object
implements Encoder

A Encoder that performs all writes to in memory buffer.


Constructor Summary
BufferedEncoder(int size, com.google.common.base.Function<OutputStream,Encoder> encoderFactory)
           
 
Method Summary
 void reset()
           
 int size()
           
 Encoder writeBool(boolean b)
           
 Encoder writeBytes(byte[] bytes)
           
 Encoder writeBytes(byte[] bytes, int off, int len)
           
 Encoder writeBytes(ByteBuffer bytes)
          Writes out the remaining bytes in ByteBuffer.
 Encoder writeDouble(double d)
           
 Encoder writeFloat(float f)
           
 Encoder writeInt(int i)
           
 Encoder writeLong(long l)
           
 Encoder writeNull()
           
 Encoder writeRaw(byte[] rawBytes)
          Writes raw bytes to the buffer without encoding.
 Encoder writeRaw(byte[] rawBytes, int off, int len)
          Writes raw bytes to the buffer without encoding.
 Encoder writeString(String s)
           
 void writeTo(OutputStream out)
          Writes all the buffered bytes into the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedEncoder

public BufferedEncoder(int size,
                       com.google.common.base.Function<OutputStream,Encoder> encoderFactory)
Method Detail

reset

public void reset()

writeTo

public void writeTo(OutputStream out)
             throws IOException
Writes all the buffered bytes into the given OutputStream. If the write completed successfully, the internal buffered will be reset.

Parameters:
out - The output stream to write to.
Throws:
IOException

size

public int size()

writeRaw

public Encoder writeRaw(byte[] rawBytes)
                 throws IOException
Writes raw bytes to the buffer without encoding. Same as calling writeRaw(rawBytes, 0, rawBytes.length).

Throws:
IOException

writeRaw

public Encoder writeRaw(byte[] rawBytes,
                        int off,
                        int len)
                 throws IOException
Writes raw bytes to the buffer without encoding.

Parameters:
rawBytes - The bytes to write.
off - Offset to start in the byte array.
len - Number of bytes to write starting from the offset.
Throws:
IOException

writeNull

public Encoder writeNull()
                  throws IOException
Specified by:
writeNull in interface Encoder
Throws:
IOException

writeBool

public Encoder writeBool(boolean b)
                  throws IOException
Specified by:
writeBool in interface Encoder
Throws:
IOException

writeInt

public Encoder writeInt(int i)
                 throws IOException
Specified by:
writeInt in interface Encoder
Throws:
IOException

writeLong

public Encoder writeLong(long l)
                  throws IOException
Specified by:
writeLong in interface Encoder
Throws:
IOException

writeFloat

public Encoder writeFloat(float f)
                   throws IOException
Specified by:
writeFloat in interface Encoder
Throws:
IOException

writeDouble

public Encoder writeDouble(double d)
                    throws IOException
Specified by:
writeDouble in interface Encoder
Throws:
IOException

writeString

public Encoder writeString(String s)
                    throws IOException
Specified by:
writeString in interface Encoder
Throws:
IOException

writeBytes

public Encoder writeBytes(byte[] bytes)
                   throws IOException
Specified by:
writeBytes in interface Encoder
Throws:
IOException

writeBytes

public Encoder writeBytes(byte[] bytes,
                          int off,
                          int len)
                   throws IOException
Specified by:
writeBytes in interface Encoder
Throws:
IOException

writeBytes

public Encoder writeBytes(ByteBuffer bytes)
                   throws IOException
Description copied from interface: Encoder
Writes out the remaining bytes in ByteBuffer.

The given ByteBuffer is untouched after this method returns (i.e. same position and limit).

Specified by:
writeBytes in interface Encoder
Throws:
IOException


Copyright © 2014 Cask Data, Inc. Licensed under the Apache License, Version 2.0.