Class PersistentHttpStream
- java.lang.Object
-
- java.io.InputStream
-
- com.sedmelluq.discord.lavaplayer.tools.io.SeekableInputStream
-
- com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
HeartbeatingHttpStream,YoutubePersistentHttpStream
public class PersistentHttpStream extends SeekableInputStream implements java.lang.AutoCloseable
Use an HTTP endpoint as a stream, where the connection resetting is handled gracefully by reopening the connection and using a closed stream will just reopen the connection.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.net.URIcontentUrlprotected java.io.InputStreamcurrentContentprotected HttpInterfacehttpInterfaceprotected longposition-
Fields inherited from class com.sedmelluq.discord.lavaplayer.tools.io.SeekableInputStream
contentLength
-
-
Constructor Summary
Constructors Constructor Description PersistentHttpStream(HttpInterface httpInterface, java.net.URI contentUrl, java.lang.Long contentLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()booleancanSeekHard()intcheckStatusCode()Connect and return status code or return last status code if already connected.voidclose()protected voidconnect(boolean skipStatusCheck)java.io.InputStreamcreateContentInputStream(org.apache.http.HttpResponse response)protected java.net.URIgetConnectUrl()org.apache.http.HttpResponsegetCurrentResponse()longgetPosition()java.util.List<AudioTrackInfoProvider>getTrackInfoProviders()protected intinternalRead(byte[] b, int off, int len, boolean attemptReconnect)protected longinternalSkip(long n, boolean attemptReconnect)booleanmarkSupported()intread()intread(byte[] b, int off, int len)voidreleaseConnection()Detach from the current connection, making sure not to close the connection when the stream is closed.voidreset()protected voidseekHard(long position)longskip(long n)protected booleanuseHeadersForRange()-
Methods inherited from class com.sedmelluq.discord.lavaplayer.tools.io.SeekableInputStream
getContentLength, getMaxSkipDistance, seek, skipFully
-
-
-
-
Field Detail
-
httpInterface
protected final HttpInterface httpInterface
-
contentUrl
protected final java.net.URI contentUrl
-
currentContent
protected java.io.InputStream currentContent
-
position
protected long position
-
-
Constructor Detail
-
PersistentHttpStream
public PersistentHttpStream(HttpInterface httpInterface, java.net.URI contentUrl, java.lang.Long contentLength)
- Parameters:
httpInterface- The HTTP interface to use for requestscontentUrl- The URL of the resourcecontentLength- The length of the resource in bytes
-
-
Method Detail
-
checkStatusCode
public int checkStatusCode() throws java.io.IOExceptionConnect and return status code or return last status code if already connected. This causes the internal status code checker to be disabled, so non-success status codes will be returned instead of being thrown as they would be otherwise.- Returns:
- The status code when connecting to the URL
- Throws:
java.io.IOException- On IO error
-
getCurrentResponse
public org.apache.http.HttpResponse getCurrentResponse()
- Returns:
- An HTTP response if one is currently open.
-
getConnectUrl
protected java.net.URI getConnectUrl()
-
useHeadersForRange
protected boolean useHeadersForRange()
-
connect
protected void connect(boolean skipStatusCheck) throws java.io.IOException- Throws:
java.io.IOException
-
createContentInputStream
public java.io.InputStream createContentInputStream(org.apache.http.HttpResponse response) throws java.io.IOException- Returns:
- An InputStream implementation for the current http stream.
- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
internalRead
protected int internalRead(byte[] b, int off, int len, boolean attemptReconnect) throws java.io.IOException- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
internalSkip
protected long internalSkip(long n, boolean attemptReconnect) throws java.io.IOException- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.InputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOException- Overrides:
resetin classjava.io.InputStream- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classjava.io.InputStream
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException
-
releaseConnection
public void releaseConnection()
Detach from the current connection, making sure not to close the connection when the stream is closed.
-
getPosition
public long getPosition()
- Specified by:
getPositionin classSeekableInputStream- Returns:
- Current position in the stream
-
seekHard
protected void seekHard(long position) throws java.io.IOException- Specified by:
seekHardin classSeekableInputStream- Throws:
java.io.IOException
-
canSeekHard
public boolean canSeekHard()
- Specified by:
canSeekHardin classSeekableInputStream- Returns:
trueif it is possible to seek to an arbitrary position in this stream, even when it is behind the current position.
-
getTrackInfoProviders
public java.util.List<AudioTrackInfoProvider> getTrackInfoProviders()
- Specified by:
getTrackInfoProvidersin classSeekableInputStream
-
-