Package io.airlift.slice
Class DynamicSliceOutput
- java.lang.Object
-
- java.io.OutputStream
-
- io.airlift.slice.SliceOutput
-
- io.airlift.slice.DynamicSliceOutput
-
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
public class DynamicSliceOutput extends SliceOutput
-
-
Constructor Summary
Constructors Constructor Description DynamicSliceOutput(int estimatedSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DynamicSliceOutputappendByte(int value)DynamicSliceOutputappendBytes(byte[] source)DynamicSliceOutputappendBytes(byte[] source, int sourceIndex, int length)DynamicSliceOutputappendBytes(Slice slice)DynamicSliceOutputappendDouble(double value)DynamicSliceOutputappendInt(int value)DynamicSliceOutputappendLong(long value)DynamicSliceOutputappendShort(int value)SlicecopySlice()longgetRetainedSize()Approximate number of bytes retained by this.SlicegetUnderlyingSlice()Returns the raw underlying slice of this output stream.booleanisWritable()Returnstrueif and only if(this.capacity - this.writerIndex)is greater than0.voidreset()Resets this stream to the initial position.voidreset(int position)Resets this stream to the specified position.intsize()Returns thewriterIndexof this buffer.Sliceslice()Returns a slice of this buffer's readable bytes.StringtoString()StringtoString(Charset charset)Decodes this buffer's readable bytes into a string with the specified character set name.intwritableBytes()Returns the number of writable bytes which is equal to(this.capacity - this.writerIndex).voidwriteByte(int value)Sets the specified byte at the currentwriterIndexand increases thewriterIndexby1in this buffer.voidwriteBytes(byte[] source)Transfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=source.length).voidwriteBytes(byte[] source, int sourceIndex, int length)Transfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).voidwriteBytes(Slice source)Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer becomes unreadable, and increases thewriterIndexby the number of the transferred bytes.voidwriteBytes(Slice source, int sourceIndex, int length)Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).voidwriteBytes(InputStream in, int length)Transfers the content of the specified stream to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.voidwriteDouble(double value)Sets the specified 64-bit double at the currentwriterIndexand increases thewriterIndexby8in this buffer.voidwriteFloat(float value)Sets the specified 32-bit float at the currentwriterIndexand increases thewriterIndexby4in this buffer.voidwriteInt(int value)Sets the specified 32-bit integer at the currentwriterIndexand increases thewriterIndexby4in this buffer.voidwriteLong(long value)Sets the specified 64-bit long integer at the currentwriterIndexand increases thewriterIndexby8in this buffer.voidwriteShort(int value)Sets the specified 16-bit short integer at the currentwriterIndexand increases thewriterIndexby2in this buffer.voidwriteZero(int length)Fills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.-
Methods inherited from class io.airlift.slice.SliceOutput
write, write, write, writeBoolean, writeBytes, writeChar, writeChars, writeUTF
-
Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream
-
-
-
-
Method Detail
-
reset
public void reset()
Description copied from class:SliceOutputResets this stream to the initial position.- Specified by:
resetin classSliceOutput
-
reset
public void reset(int position)
Description copied from class:SliceOutputResets this stream to the specified position.- Specified by:
resetin classSliceOutput
-
size
public int size()
Description copied from class:SliceOutputReturns thewriterIndexof this buffer.- Specified by:
sizein classSliceOutput
-
getRetainedSize
public long getRetainedSize()
Description copied from class:SliceOutputApproximate number of bytes retained by this.- Specified by:
getRetainedSizein classSliceOutput
-
isWritable
public boolean isWritable()
Description copied from class:SliceOutputReturnstrueif and only if(this.capacity - this.writerIndex)is greater than0.- Specified by:
isWritablein classSliceOutput
-
writableBytes
public int writableBytes()
Description copied from class:SliceOutputReturns the number of writable bytes which is equal to(this.capacity - this.writerIndex).- Specified by:
writableBytesin classSliceOutput
-
writeByte
public void writeByte(int value)
Description copied from class:SliceOutputSets the specified byte at the currentwriterIndexand increases thewriterIndexby1in this buffer. The 24 high-order bits of the specified value are ignored.- Specified by:
writeBytein interfaceDataOutput- Specified by:
writeBytein classSliceOutput
-
writeShort
public void writeShort(int value)
Description copied from class:SliceOutputSets the specified 16-bit short integer at the currentwriterIndexand increases thewriterIndexby2in this buffer. The 16 high-order bits of the specified value are ignored.- Specified by:
writeShortin interfaceDataOutput- Specified by:
writeShortin classSliceOutput
-
writeInt
public void writeInt(int value)
Description copied from class:SliceOutputSets the specified 32-bit integer at the currentwriterIndexand increases thewriterIndexby4in this buffer.- Specified by:
writeIntin interfaceDataOutput- Specified by:
writeIntin classSliceOutput
-
writeLong
public void writeLong(long value)
Description copied from class:SliceOutputSets the specified 64-bit long integer at the currentwriterIndexand increases thewriterIndexby8in this buffer.- Specified by:
writeLongin interfaceDataOutput- Specified by:
writeLongin classSliceOutput
-
writeFloat
public void writeFloat(float value)
Description copied from class:SliceOutputSets the specified 32-bit float at the currentwriterIndexand increases thewriterIndexby4in this buffer.- Specified by:
writeFloatin interfaceDataOutput- Specified by:
writeFloatin classSliceOutput
-
writeDouble
public void writeDouble(double value)
Description copied from class:SliceOutputSets the specified 64-bit double at the currentwriterIndexand increases thewriterIndexby8in this buffer.- Specified by:
writeDoublein interfaceDataOutput- Specified by:
writeDoublein classSliceOutput
-
writeBytes
public void writeBytes(byte[] source)
Description copied from class:SliceOutputTransfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=source.length).- Specified by:
writeBytesin classSliceOutput
-
writeBytes
public void writeBytes(byte[] source, int sourceIndex, int length)Description copied from class:SliceOutputTransfers the specified source array's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).- Specified by:
writeBytesin classSliceOutputsourceIndex- the first index of the sourcelength- the number of bytes to transfer
-
writeBytes
public void writeBytes(Slice source)
Description copied from class:SliceOutputTransfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer becomes unreadable, and increases thewriterIndexby the number of the transferred bytes. This method is basically same withSliceOutput.writeBytes(Slice, int, int), except that this method increases thereaderIndexof the source buffer by the number of the transferred bytes whileSliceOutput.writeBytes(Slice, int, int)does not.- Specified by:
writeBytesin classSliceOutput
-
writeBytes
public void writeBytes(Slice source, int sourceIndex, int length)
Description copied from class:SliceOutputTransfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).- Specified by:
writeBytesin classSliceOutputsourceIndex- the first index of the sourcelength- the number of bytes to transfer
-
writeBytes
public void writeBytes(InputStream in, int length) throws IOException
Description copied from class:SliceOutputTransfers the content of the specified stream to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.- Specified by:
writeBytesin classSliceOutputlength- the number of bytes to transfer- Throws:
IOException- if the specified stream threw an exception during I/O
-
writeZero
public void writeZero(int length)
Description copied from class:SliceOutputFills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.- Overrides:
writeZeroin classSliceOutput- Parameters:
length- the number of NULs to write to the buffer
-
appendLong
public DynamicSliceOutput appendLong(long value)
- Specified by:
appendLongin classSliceOutput
-
appendDouble
public DynamicSliceOutput appendDouble(double value)
- Specified by:
appendDoublein classSliceOutput
-
appendInt
public DynamicSliceOutput appendInt(int value)
- Specified by:
appendIntin classSliceOutput
-
appendShort
public DynamicSliceOutput appendShort(int value)
- Specified by:
appendShortin classSliceOutput
-
appendByte
public DynamicSliceOutput appendByte(int value)
- Specified by:
appendBytein classSliceOutput
-
appendBytes
public DynamicSliceOutput appendBytes(byte[] source, int sourceIndex, int length)
- Specified by:
appendBytesin classSliceOutput
-
appendBytes
public DynamicSliceOutput appendBytes(byte[] source)
- Specified by:
appendBytesin classSliceOutput
-
appendBytes
public DynamicSliceOutput appendBytes(Slice slice)
- Specified by:
appendBytesin classSliceOutput
-
slice
public Slice slice()
Description copied from class:SliceOutputReturns a slice of this buffer's readable bytes. Modifying the content of the returned buffer or this buffer affects each other's content while they maintain separate indexes and marks. This method is identical tobuf.slice(buf.readerIndex(), buf.readableBytes()). This method does not modifyreaderIndexorwriterIndexof this buffer.- Specified by:
slicein classSliceOutput
-
copySlice
public Slice copySlice()
-
getUnderlyingSlice
public Slice getUnderlyingSlice()
Description copied from class:SliceOutputReturns the raw underlying slice of this output stream. The slice may be larger than the size of this stream.- Specified by:
getUnderlyingSlicein classSliceOutput
-
toString
public String toString(Charset charset)
Description copied from class:SliceOutputDecodes this buffer's readable bytes into a string with the specified character set name. This method is identical tobuf.toString(buf.readerIndex(), buf.readableBytes(), charsetName). This method does not modifyreaderIndexorwriterIndexof this buffer.- Specified by:
toStringin classSliceOutput
-
-