Package io.airlift.slice
Class SliceOutput
java.lang.Object
java.io.OutputStream
io.airlift.slice.SliceOutput
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
- Direct Known Subclasses:
BasicSliceOutput,DynamicSliceOutput,OutputStreamSliceOutput
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract SliceOutputappendByte(int value) abstract SliceOutputappendBytes(byte[] source) abstract SliceOutputappendBytes(byte[] source, int sourceIndex, int length) abstract SliceOutputappendBytes(Slice slice) abstract SliceOutputappendDouble(double value) abstract SliceOutputappendInt(int value) abstract SliceOutputappendLong(long value) abstract SliceOutputappendShort(int value) abstract longApproximate number of bytes retained by this.abstract SliceReturns the raw underlying slice of this output stream.abstract booleanReturnstrueif and only if(this.capacity - this.writerIndex)is greater than0.abstract voidreset()Resets this stream to the initial position.abstract voidreset(int position) Resets this stream to the specified position.abstract intsize()Returns thewriterIndexof this buffer.abstract Sliceslice()Returns a slice of this buffer's readable bytes.abstract StringDecodes this buffer's readable bytes into a string with the specified character set name.abstract intReturns the number of writable bytes which is equal to(this.capacity - this.writerIndex).final voidwrite(byte[] source) final voidwrite(byte[] source, int sourceIndex, int length) final voidwrite(int value) final voidwriteBoolean(boolean value) abstract voidwriteByte(int value) Sets the specified byte at the currentwriterIndexand increases thewriterIndexby1in this buffer.abstract 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).abstract 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).abstract 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.abstract 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).abstract 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.voidwriteBytes(String s) Unsupported operationvoidwriteChar(int value) Unsupported operationvoidwriteChars(String s) Unsupported operationabstract voidwriteDouble(double value) Sets the specified 64-bit double at the currentwriterIndexand increases thewriterIndexby8in this buffer.abstract voidwriteFloat(float v) Sets the specified 32-bit float at the currentwriterIndexand increases thewriterIndexby4in this buffer.abstract voidwriteInt(int value) Sets the specified 32-bit integer at the currentwriterIndexand increases thewriterIndexby4in this buffer.abstract voidwriteLong(long value) Sets the specified 64-bit long integer at the currentwriterIndexand increases thewriterIndexby8in this buffer.abstract voidwriteShort(int value) Sets the specified 16-bit short integer at the currentwriterIndexand increases thewriterIndexby2in this buffer.voidUnsupported operationvoidwriteZero(int length) Fills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream
-
Constructor Details
-
SliceOutput
public SliceOutput()
-
-
Method Details
-
reset
public abstract void reset()Resets this stream to the initial position. -
reset
public abstract void reset(int position) Resets this stream to the specified position. -
size
public abstract int size()Returns thewriterIndexof this buffer. -
getRetainedSize
public abstract long getRetainedSize()Approximate number of bytes retained by this. -
writableBytes
public abstract int writableBytes()Returns the number of writable bytes which is equal to(this.capacity - this.writerIndex). -
isWritable
public abstract boolean isWritable()Returnstrueif and only if(this.capacity - this.writerIndex)is greater than0. -
writeBoolean
public final void writeBoolean(boolean value) - Specified by:
writeBooleanin interfaceDataOutput
-
write
public final void write(int value) - Specified by:
writein interfaceDataOutput- Specified by:
writein classOutputStream
-
writeByte
public abstract void writeByte(int value) Sets 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- Throws:
IndexOutOfBoundsException- ifthis.writableBytesis less than1
-
writeShort
public abstract void writeShort(int value) Sets 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- Throws:
IndexOutOfBoundsException- ifthis.writableBytesis less than2
-
writeInt
public abstract void writeInt(int value) Sets the specified 32-bit integer at the currentwriterIndexand increases thewriterIndexby4in this buffer.- Specified by:
writeIntin interfaceDataOutput- Throws:
IndexOutOfBoundsException- ifthis.writableBytesis less than4
-
writeLong
public abstract void writeLong(long value) Sets the specified 64-bit long integer at the currentwriterIndexand increases thewriterIndexby8in this buffer.- Specified by:
writeLongin interfaceDataOutput- Throws:
IndexOutOfBoundsException- ifthis.writableBytesis less than8
-
writeFloat
public abstract void writeFloat(float v) Sets the specified 32-bit float at the currentwriterIndexand increases thewriterIndexby4in this buffer.- Specified by:
writeFloatin interfaceDataOutput- Throws:
IndexOutOfBoundsException- ifthis.writableBytesis less than4
-
writeDouble
public abstract void writeDouble(double value) Sets the specified 64-bit double at the currentwriterIndexand increases thewriterIndexby8in this buffer.- Specified by:
writeDoublein interfaceDataOutput- Throws:
IndexOutOfBoundsException- ifthis.writableBytesis less than8
-
writeBytes
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. This method is basically same withwriteBytes(Slice, int, int), except that this method increases thereaderIndexof the source buffer by the number of the transferred bytes whilewriteBytes(Slice, int, int)does not.- Throws:
IndexOutOfBoundsException- ifsource.readableBytesis greater thanthis.writableBytes
-
writeBytes
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes (=length).- Parameters:
sourceIndex- the first index of the sourcelength- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifiedsourceIndexis less than0, ifsourceIndex + lengthis greater thansource.capacity, or iflengthis greater thanthis.writableBytes
-
write
public final void write(byte[] source) - Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream
-
writeBytes
public abstract void writeBytes(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).- Throws:
IndexOutOfBoundsException- ifsource.lengthis greater thanthis.writableBytes
-
write
public final void write(byte[] source, int sourceIndex, int length) - Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream
-
writeBytes
public abstract void writeBytes(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).- Parameters:
sourceIndex- the first index of the sourcelength- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- if the specifiedsourceIndexis less than0, ifsourceIndex + lengthis greater thansource.length, or iflengthis greater thanthis.writableBytes
-
writeBytes
Transfers the content of the specified stream to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.- Parameters:
length- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.writableBytesIOException- if the specified stream threw an exception during I/O
-
writeZero
public void writeZero(int length) Fills this buffer with NUL (0x00) starting at the currentwriterIndexand increases thewriterIndexby the specifiedlength.- Parameters:
length- the number of NULs to write to the buffer- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.writableBytes
-
slice
Returns 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. -
getUnderlyingSlice
Returns the raw underlying slice of this output stream. The slice may be larger than the size of this stream. -
toString
Decodes 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. -
appendLong
-
appendDouble
-
appendInt
-
appendShort
-
appendByte
-
appendBytes
-
appendBytes
-
appendBytes
-
writeChar
public void writeChar(int value) Unsupported operation- Specified by:
writeCharin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeChars
Unsupported operation- Specified by:
writeCharsin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeUTF
Unsupported operation- Specified by:
writeUTFin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeBytes
Unsupported operation- Specified by:
writeBytesin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-