Class 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 Detail

      • AndroidFileStream

        public AndroidFileStream​(AndroidFile file,
                                 java.lang.String mode)
                          throws java.io.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:
        java.io.FileNotFoundException - Thrown if file is not found
    • Method Detail

      • canRead

        public boolean canRead()
        True if the stream is readable.
        Specified by:
        canRead in class RandomAccessStream
        Returns:
        True if readable
      • canWrite

        public boolean canWrite()
        True if the stream is writeable.
        Specified by:
        canWrite in class RandomAccessStream
        Returns:
        True if writeable
      • canSeek

        public boolean canSeek()
        True if the stream is seekable (random access).
        Specified by:
        canSeek in class RandomAccessStream
        Returns:
        True if seekable
      • getLength

        public long getLength()
        Get the length of the stream.
        Specified by:
        getLength in class RandomAccessStream
        Returns:
        The length
      • getPosition

        public long getPosition()
                         throws java.io.IOException
        Get the current position of the stream.
        Specified by:
        getPosition in class RandomAccessStream
        Returns:
        The current position
        Throws:
        java.io.IOException - Thrown if error during IO
      • setPosition

        public void setPosition​(long value)
                         throws java.io.IOException
        Set the current position of the stream.
        Specified by:
        setPosition in class RandomAccessStream
        Parameters:
        value - The new position.
        Throws:
        java.io.IOException - Thrown if error during IO
      • setLength

        public void setLength​(long value)
                       throws java.io.IOException
        Set the length of the stream.
        Specified by:
        setLength in class RandomAccessStream
        Parameters:
        value - The length.
        Throws:
        java.io.IOException - Thrown if error during IO
      • read

        public int read​(byte[] buffer,
                        int offset,
                        int count)
                 throws java.io.IOException
        Read data from the stream into the buffer.
        Specified by:
        read in class RandomAccessStream
        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:
        java.io.IOException - Thrown if error during IO
      • write

        public void write​(byte[] buffer,
                          int offset,
                          int count)
                   throws java.io.IOException
        Write the data buffer to the stream.
        Specified by:
        write in class RandomAccessStream
        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:
        java.io.IOException - Thrown if error during IO
      • seek

        public long seek​(long offset,
                         RandomAccessStream.SeekOrigin origin)
                  throws java.io.IOException
        Seek to the requested position.
        Specified by:
        seek in class RandomAccessStream
        Parameters:
        offset - The new position.
        origin - The origin type.
        Returns:
        The current position after seeking
        Throws:
        java.io.IOException - Thrown if error during IO
      • close

        public void close()
                   throws java.io.IOException
        Close the stream.
        Specified by:
        close in class RandomAccessStream
        Throws:
        java.io.IOException - Thrown if error during IO