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
public abstract class SliceOutput extends OutputStream implements DataOutput
-
-
Constructor Summary
Constructors Constructor Description SliceOutput()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract 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 longgetRetainedSize()Approximate number of bytes retained by this.abstract SlicegetUnderlyingSlice()Returns the raw underlying slice of this output stream.abstract booleanisWritable()Returnstrueif 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 StringtoString(Charset charset)Decodes this buffer's readable bytes into a string with the specified character set name.abstract intwritableBytes()Returns the number of writable bytes which is equal to(this.capacity - this.writerIndex).voidwrite(byte[] source)voidwrite(byte[] source, int sourceIndex, int length)voidwrite(int value)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.voidwriteUTF(String s)Unsupported 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
-
-
-
-
Method Detail
-
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
public abstract void writeBytes(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. 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
public abstract void writeBytes(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).- 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) throws IOException- Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream- Throws:
IOException
-
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
public abstract void writeBytes(InputStream in, int length) throws IOException
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
public abstract Slice 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
public abstract Slice getUnderlyingSlice()
Returns the raw underlying slice of this output stream. The slice may be larger than the size of this stream.
-
toString
public abstract String toString(Charset charset)
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
public abstract SliceOutput appendLong(long value)
-
appendDouble
public abstract SliceOutput appendDouble(double value)
-
appendInt
public abstract SliceOutput appendInt(int value)
-
appendShort
public abstract SliceOutput appendShort(int value)
-
appendByte
public abstract SliceOutput appendByte(int value)
-
appendBytes
public abstract SliceOutput appendBytes(byte[] source, int sourceIndex, int length)
-
appendBytes
public abstract SliceOutput appendBytes(byte[] source)
-
appendBytes
public abstract SliceOutput appendBytes(Slice slice)
-
writeChar
public void writeChar(int value)
Unsupported operation- Specified by:
writeCharin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeChars
public void writeChars(String s)
Unsupported operation- Specified by:
writeCharsin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeUTF
public void writeUTF(String s)
Unsupported operation- Specified by:
writeUTFin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeBytes
public void writeBytes(String s)
Unsupported operation- Specified by:
writeBytesin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
-