Class HttpFileStream

java.lang.Object
RandomAccessStream
com.mku.fs.streams.HttpFileStream

public class HttpFileStream extends RandomAccessStream
File stream implementation for remote HTTP files.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a file stream from a JavaFile.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if stream can read from file.
    boolean
    Check if stream can seek.
    boolean
    Check if stream can write to file.
    void
    Close this stream and associated resources.
    void
    Flush the buffers to the associated file.
    long
    Get the length of the stream.
    long
    Get the current position of the stream.
    int
    read(byte[] buffer, int offset, int count)
    Read data from the file stream into the buffer provided.
    void
    Reset the stream.
    long
    seek(long offset, SeekOrigin origin)
    Seek to the offset provided.
    void
    setLength(long value)
    Set the length of the stream.
    void
    setMaxNetBytesSkip(long maxNetBytesSkip)
    Maximum amount of bytes allowed to skip forwards when seeking otherwise will open a new connection
    void
    setPosition(long value)
    Set the current position of the stream.
    void
    write(byte[] buffer, int offset, int count)
    Write the data from the buffer provided into the stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HttpFileStream

      public HttpFileStream(HttpFile file, String mode)
      Construct a file stream from a JavaFile. This will create a wrapper stream that will route read() and write() to the FileChannel
      Parameters:
      file - The JavaFile that will be used to get the read/write stream
      mode - The mode "r" for read "rw" for write
  • Method Details

    • setMaxNetBytesSkip

      public void setMaxNetBytesSkip(long maxNetBytesSkip)
      Maximum amount of bytes allowed to skip forwards when seeking otherwise will open a new connection
      Parameters:
      maxNetBytesSkip - The maximum number of bytes to skip
    • canRead

      public boolean canRead()
      Check if stream can read from file.
      Returns:
      True if readable
    • canWrite

      public boolean canWrite()
      Check if stream can write to file.
      Returns:
      True if writable
    • canSeek

      public boolean canSeek()
      Check if stream can seek.
      Returns:
      True if seekable
    • getLength

      public long getLength()
      Get the length of the stream. This is the same as the backed file.
      Returns:
      The file stream length
    • getPosition

      public long getPosition() throws IOException
      Get the current position of the stream.
      Returns:
      The current position
      Throws:
      IOException - Thrown if there is an IO error.
    • setPosition

      public void setPosition(long value) throws IOException
      Set the current position of the stream.
      Parameters:
      value - The new position.
      Throws:
      IOException - Thrown if there is an IO error.
    • setLength

      public void setLength(long value) throws IOException
      Set the length of the stream. This is applicable for write streams only.
      Parameters:
      value - The new length.
      Throws:
      IOException - Thrown if there is an IO error.
    • read

      public int read(byte[] buffer, int offset, int count) throws IOException
      Read data from the file stream into the buffer provided.
      Parameters:
      buffer - The buffer to write the data.
      offset - The offset of the buffer to start writing the data.
      count - The maximum number of bytes to read from.
      Returns:
      The bytes read
      Throws:
      IOException - Thrown if there is an IO error.
    • write

      public void write(byte[] buffer, int offset, int count) throws IOException
      Write the data from the buffer provided into the stream.
      Parameters:
      buffer - The buffer to read the data from.
      offset - The offset of the buffer to start reading the data.
      count - The maximum number of bytes to read from the buffer.
      Throws:
      IOException - Thrown if there is an IO error.
    • seek

      public long seek(long offset, SeekOrigin origin) throws IOException
      Seek to the offset provided.
      Parameters:
      offset - The position to seek to.
      origin - The type of origin SeekOrigin
      Returns:
      The new position after seeking.
      Throws:
      IOException - Thrown if there is an IO error.
    • flush

      public void flush()
      Flush the buffers to the associated file.
    • close

      public void close() throws IOException
      Close this stream and associated resources.
      Throws:
      IOException - Thrown if there is an IO error.
    • reset

      public void reset() throws IOException
      Reset the stream.
      Throws:
      IOException - Thrown if there is an IO error.