Package io.pravega.common.io
Class ByteBufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- io.pravega.common.io.ByteBufferOutputStream
-
- All Implemented Interfaces:
DirectDataOutput,RandomAccessOutputStream,java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
@NotThreadSafe public class ByteBufferOutputStream extends java.io.OutputStream implements RandomAccessOutputStream
AnOutputStreamthat is backed by aByteBufferwhich can be resized as needed. Prefer using this instead ofByteArrayOutputStreamsince this makes direct use ofByteBufferintrinsic methods for writing primitive types (seeDirectDataOutputfor example).
-
-
Constructor Summary
Constructors Constructor Description ByteBufferOutputStream()Creates a new instance of theByteBufferOutputStream.ByteBufferOutputStream(int initialSize)Creates a new instance of theByteBufferOutputStreamwith given initial size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()ByteArraySegmentgetData()Returns aByteArraySegmentwrapping the current contents of theRandomAccessOutputStream.intsize()Gets a value indicating the size of this OutputStream.voidwrite(byte[] array)voidwrite(byte[] b, int offset, int length)voidwrite(byte[] array, int arrayOffset, int length, int streamPosition)Writes a sequence of bytes at the given position.voidwrite(int b)voidwrite(int byteValue, int streamPosition)Writes the given byte value at the given position.voidwriteBuffer(BufferView buffer)Includes the givenBufferView.voidwriteInt(int intValue)Writes the given value as a 32 bit Integer.voidwriteInt(int intValue, int streamPosition)Writes the given Int value at the given position.voidwriteLong(long longValue)Writes the given value as a 64 bit Long.voidwriteShort(int shortValue)Writes the given value as a 16 bit Short.
-
-
-
Constructor Detail
-
ByteBufferOutputStream
public ByteBufferOutputStream()
Creates a new instance of theByteBufferOutputStream.
-
ByteBufferOutputStream
public ByteBufferOutputStream(int initialSize)
Creates a new instance of theByteBufferOutputStreamwith given initial size.- Parameters:
initialSize- The initial size to create with.
-
-
Method Detail
-
write
public void write(int b)
- Specified by:
writein classjava.io.OutputStream
-
write
public void write(int byteValue, int streamPosition)Description copied from interface:RandomAccessOutputStreamWrites the given byte value at the given position.- Specified by:
writein interfaceRandomAccessOutputStream- Parameters:
byteValue- The value to write.streamPosition- The position to write at.
-
write
public void write(byte[] array)
- Overrides:
writein classjava.io.OutputStream
-
write
public void write(byte[] b, int offset, int length)- Overrides:
writein classjava.io.OutputStream
-
write
public void write(byte[] array, int arrayOffset, int length, int streamPosition)Description copied from interface:RandomAccessOutputStreamWrites a sequence of bytes at the given position. NOTE: depending on the implementation of this interface, this may result in increasing the size of the stream. For example, if position is smaller than size() AND position + length is larger than size() then the extra bytes may be appended at the end, if the underlying OutputStream's structure permits it.- Specified by:
writein interfaceRandomAccessOutputStream- Parameters:
array- The buffer to write from.arrayOffset- The offset within the buffer to start at.length- The number of bytes to write.streamPosition- The position within the OutputStream to write at.
-
size
public int size()
Description copied from interface:RandomAccessOutputStreamGets a value indicating the size of this OutputStream.- Specified by:
sizein interfaceRandomAccessOutputStream- Returns:
- size of stream
-
flush
public void flush()
- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream
-
writeBuffer
public void writeBuffer(BufferView buffer)
Description copied from interface:DirectDataOutputIncludes the givenBufferView.- Specified by:
writeBufferin interfaceDirectDataOutput- Parameters:
buffer- TheBufferViewto include.
-
writeShort
public void writeShort(int shortValue)
Description copied from interface:DirectDataOutputWrites the given value as a 16 bit Short. Every effort will be made to write this using efficient techniques (such as making use of intrinsic instructions).- Specified by:
writeShortin interfaceDirectDataOutput- Parameters:
shortValue- The Short value to write.
-
writeInt
public void writeInt(int intValue)
Description copied from interface:DirectDataOutputWrites the given value as a 32 bit Integer. Every effort will be made to write this using efficient techniques (such as making use of intrinsic instructions).- Specified by:
writeIntin interfaceDirectDataOutput- Parameters:
intValue- The Integer value to write.
-
writeInt
public void writeInt(int intValue, int streamPosition)Description copied from interface:RandomAccessOutputStreamWrites the given Int value at the given position.- Specified by:
writeIntin interfaceRandomAccessOutputStream- Parameters:
intValue- The value to write.streamPosition- The position to write at.
-
writeLong
public void writeLong(long longValue)
Description copied from interface:DirectDataOutputWrites the given value as a 64 bit Long. Every effort will be made to write this using efficient techniques (such as making use of intrinsic instructions).- Specified by:
writeLongin interfaceDirectDataOutput- Parameters:
longValue- The Long value to write.
-
getData
public ByteArraySegment getData()
Description copied from interface:RandomAccessOutputStreamReturns aByteArraySegmentwrapping the current contents of theRandomAccessOutputStream. Further changes to theRandomAccessOutputStreammay or may not be reflected in the returned object (depending on methods invoked and whether the underlying buffers need to be resized).- Specified by:
getDatain interfaceRandomAccessOutputStream- Returns:
- A
ByteArraySegmentfrom the current contents of theRandomAccessOutputStream.
-
-