Package org.iq80.leveldb.util
Class SliceOutput
java.lang.Object
java.io.OutputStream
org.iq80.leveldb.util.SliceOutput
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
- Direct Known Subclasses:
BasicSliceOutput,DynamicSliceOutput
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanReturnstrueif and only if(this.capacity - this.writerIndex)is greater than0.abstract voidreset()Resets this stream to the initial position.abstract intsize()Returns thewriterIndexof this buffer.abstract Sliceslice()Returns a slice of this buffer's readable bytes.abstract ByteBufferConverts this buffer's readable bytes into a NIO buffer.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 intwriteBytes(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 operationabstract voidwriteBytes(ByteBuffer source) Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer's position reaches its limit, and increases thewriterIndexby the number of the transferred bytes.abstract intwriteBytes(FileChannel in, int position, int length) abstract intwriteBytes(ScatteringByteChannel in, int length) Transfers the content of the specified channel to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.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(SliceInput source, 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(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).voidwriteChar(int value) Unsupported operationvoidwriteChars(String s) Unsupported operationvoidwriteDouble(double v) Unsupported operationvoidwriteFloat(float v) Unsupported operationabstract 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 operationabstract voidwriteZero(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. -
size
public abstract int size()Returns thewriterIndexof this buffer. -
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
-
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). 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 (=length) whilewriteBytes(Slice, int, int)does not.- Parameters:
length- the number of bytes to transfer- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.writableBytesor iflengthis greater thensource.readableBytes
-
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
- 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
Transfers the specified source buffer's data to this buffer starting at the currentwriterIndexuntil the source buffer's position reaches its limit, and increases thewriterIndexby the number of the transferred bytes.- Throws:
IndexOutOfBoundsException- ifsource.remaining()is 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- Returns:
- the actual number of bytes read in from the specified stream
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.writableBytesIOException- if the specified stream threw an exception during I/O
-
writeBytes
Transfers the content of the specified channel to this buffer starting at the currentwriterIndexand increases thewriterIndexby the number of the transferred bytes.- Parameters:
length- the maximum number of bytes to transfer- Returns:
- the actual number of bytes read in from the specified channel
- Throws:
IndexOutOfBoundsException- iflengthis greater thanthis.writableBytesIOException- if the specified channel threw an exception during I/O
-
writeBytes
- Throws:
IOException
-
writeZero
public abstract 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. -
toByteBuffer
Converts this buffer's readable bytes into a NIO buffer. The returned buffer might or might not share the content with this buffer, while they have separate indexes and marks. This method is identical tobuf.toByteBuffer(buf.readerIndex(), buf.readableBytes()). This method does not modifyreaderIndexorwriterIndexof this buffer. -
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.- Throws:
UnsupportedCharsetException- if the specified character set name is not supported by the current VM
-
writeChar
public void writeChar(int value) Unsupported operation- Specified by:
writeCharin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeFloat
public void writeFloat(float v) Unsupported operation- Specified by:
writeFloatin interfaceDataOutput- Throws:
UnsupportedOperationException- always
-
writeDouble
public void writeDouble(double v) Unsupported operation- Specified by:
writeDoublein 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
-