Class DirectBufferStreamBroker
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.tools.io.DirectBufferStreamBroker
-
public class DirectBufferStreamBroker extends java.lang.ObjectA helper class to consume the entire contents of a stream into a direct byte buffer. Designed for cases where this is repeated several times, as it supports resetting.
-
-
Constructor Summary
Constructors Constructor Description DirectBufferStreamBroker(int initialSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear the underlying buffer.booleanconsumeNext(java.io.InputStream inputStream, int maximumSavedBytes, int maximumReadBytes)Consume an entire stream and append it into the buffer (or clear first if clear parameter is true).byte[]extractBytes()Copies the final state after aconsumeNext(InputStream, int, int)operation into a new byte array.java.nio.ByteBuffergetBuffer()booleanisTruncated()voidresetAndCompact()Reset the buffer to its initial size.
-
-
-
Method Detail
-
resetAndCompact
public void resetAndCompact()
Reset the buffer to its initial size.
-
clear
public void clear()
Clear the underlying buffer.
-
getBuffer
public java.nio.ByteBuffer getBuffer()
- Returns:
- A duplicate of the underlying buffer.
-
isTruncated
public boolean isTruncated()
-
extractBytes
public byte[] extractBytes()
Copies the final state after aconsumeNext(InputStream, int, int)operation into a new byte array.- Returns:
- New byte array containing consumed data.
-
consumeNext
public boolean consumeNext(java.io.InputStream inputStream, int maximumSavedBytes, int maximumReadBytes) throws java.io.IOExceptionConsume an entire stream and append it into the buffer (or clear first if clear parameter is true).- Parameters:
inputStream- The input stream to fully consume.maximumSavedBytes- Maximum number of bytes to save internally. If this is exceeded, it will continue reading and discarding until maximum read byte count is reached.maximumReadBytes- Maximum number of bytes to read.- Returns:
- If stream was fully read before
maximumReadByteswas reached, returnstrue. Returnsfalseif the number of bytes read ismaximumReadBytes, even if no more data is left in the stream. - Throws:
java.io.IOException- On read error
-
-