Class AndroidFileStream

java.lang.Object
RandomAccessStream
com.mku.android.fs.streams.AndroidFileStream

public class AndroidFileStream extends RandomAccessStream
Class is a stream implementation wrapper for java streams that are retrieved from AndroidFile which support external SD cards.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    boolean
    True if the stream is readable.
    boolean
    True if the stream is seekable (random access).
    boolean
    True if the stream is writeable.
    void
    Close the stream.
    void
    Flush the buffers to the stream.
    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 stream into the buffer.
    long
    seek(long offset, SeekOrigin origin)
    Seek to the requested position.
    void
    setLength(long value)
    Set the length of the stream.
    void
    setPosition(long value)
    Set the current position of the stream.
    void
    write(byte[] buffer, int offset, int count)
    Write the data buffer to the stream.

    Methods inherited from class java.lang.Object

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

    • AndroidFileStream

      public AndroidFileStream(AndroidFile file, String mode) throws FileNotFoundException
      Construct a file stream from an AndroidFile. This will create a wrapper stream that will route read() and write() to the Android FileChannel
      Parameters:
      file - The AndroidFile that will be used to get the read/write stream
      mode - The mode "r" for read "rw" for write
      Throws:
      FileNotFoundException - Thrown if file is not found
  • Method Details

    • canRead

      public boolean canRead()
      True if the stream is readable.
      Returns:
      True if readable
    • canWrite

      public boolean canWrite()
      True if the stream is writeable.
      Returns:
      True if writeable
    • canSeek

      public boolean canSeek()
      True if the stream is seekable (random access).
      Returns:
      True if seekable
    • getLength

      public long getLength()
      Get the length of the stream.
      Returns:
      The length
    • getPosition

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

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

      public void setLength(long value) throws IOException
      Set the length of the stream.
      Parameters:
      value - The length.
      Throws:
      IOException - Thrown if error during IO
    • read

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

      public void write(byte[] buffer, int offset, int count) throws IOException
      Write the data buffer to the stream.
      Parameters:
      buffer - The buffer to read the contents from.
      offset - The position the reading will start from.
      count - The count of bytes to be read from the buffer.
      Throws:
      IOException - Thrown if error during IO
    • seek

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

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

      public void close() throws IOException
      Close the stream.
      Throws:
      IOException - Thrown if error during IO