Class WriteOutBytes
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.druid.segment.writeout.WriteOutBytes
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,Channel
,WritableByteChannel
- Direct Known Subclasses:
ByteBufferWriteOutBytes
public abstract class WriteOutBytes extends OutputStream implements WritableByteChannel
Appendable byte sequence for temporary storage. Methods inherited fromOutputStream
,WritableByteChannel
andwriteInt(int)
append to the sequence. MethodswriteTo(WritableByteChannel)
andasInputStream()
allow to write the sequence somewhere else.readFully(long, java.nio.ByteBuffer)
allows to access the sequence randomly. WriteOutBytes is a resource that is managed bySegmentWriteOutMedium
, so it's ownclose()
method does nothing. However WriteOutBytes should appear closed, i. e.Channel.isOpen()
returns false, after the parental SegmentWriteOutMedium is closed.
-
-
Constructor Summary
Constructors Constructor Description WriteOutBytes()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract InputStream
asInputStream()
Creates a finiteInputStream
with the bytes that are written to this WriteOutBytes so far.void
close()
Deprecated.does nothing.abstract void
readFully(long pos, ByteBuffer buffer)
Reads bytes from the byte sequences, represented by this WriteOutBytes, at the random position, into the given buffer.abstract long
size()
Returns the number of bytes written to this WriteOutBytes so far.abstract void
writeInt(int v)
Writes 4 bytes of the given value in big-endian order, i.abstract void
writeTo(WritableByteChannel channel)
Takes all bytes that are written to this WriteOutBytes so far and writes them into the given channel.-
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write, write, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.nio.channels.WritableByteChannel
write
-
-
-
-
Method Detail
-
writeInt
public abstract void writeInt(int v) throws IOException
Writes 4 bytes of the given value in big-endian order, i. e. similar toDataOutput.writeInt(int)
.- Throws:
IOException
-
size
public abstract long size()
Returns the number of bytes written to this WriteOutBytes so far.
-
writeTo
public abstract void writeTo(WritableByteChannel channel) throws IOException
Takes all bytes that are written to this WriteOutBytes so far and writes them into the given channel.- Throws:
IOException
-
asInputStream
public abstract InputStream asInputStream() throws IOException
Creates a finiteInputStream
with the bytes that are written to this WriteOutBytes so far. The returned InputStream must be closed properly after it's used up.- Throws:
IOException
-
readFully
public abstract void readFully(long pos, ByteBuffer buffer) throws IOException
Reads bytes from the byte sequences, represented by this WriteOutBytes, at the random position, into the given buffer.- Throws:
BufferUnderflowException
- if the byte sequence from the given pos ends before the given buffer is filledIllegalArgumentException
- if the given pos is negativeIOException
-
close
@Deprecated public final void close()
Deprecated.does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
-
-