Package com.mku.android.streams
Class AndroidFileStream
java.lang.Object
com.mku.streams.RandomAccessStream
com.mku.android.streams.AndroidFileStream
Class is a stream implementation wrapper for java streams that are retrieved from AndroidFile
which support external SD cards.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.mku.streams.RandomAccessStream
RandomAccessStream.SeekOrigin
-
Constructor Summary
ConstructorDescriptionAndroidFileStream
(AndroidFile file, String mode) Construct a file stream from an AndroidFile. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRead()
True if the stream is readable.boolean
canSeek()
True if the stream is seekable (random access).boolean
canWrite()
True if the stream is writeable.void
close()
Close the stream.void
flush()
Flush the buffers to the stream.long
Get the current position of the stream.long
length()
Get the length of the stream.int
read
(byte[] buffer, int offset, int count) Read data from the stream into the buffer.long
seek
(long offset, RandomAccessStream.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 com.mku.streams.RandomAccessStream
copyTo, copyTo, copyTo
-
Constructor Details
-
AndroidFileStream
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 streammode
- 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.- Specified by:
canRead
in classRandomAccessStream
- Returns:
- True if readable
-
canWrite
public boolean canWrite()True if the stream is writeable.- Specified by:
canWrite
in classRandomAccessStream
- Returns:
- True if writeable
-
canSeek
public boolean canSeek()True if the stream is seekable (random access).- Specified by:
canSeek
in classRandomAccessStream
- Returns:
- True if seekable
-
length
public long length()Get the length of the stream.- Specified by:
length
in classRandomAccessStream
- Returns:
- The length
-
getPosition
Get the current position of the stream.- Specified by:
getPosition
in classRandomAccessStream
- Returns:
- The current position
- Throws:
IOException
- Thrown if error during IO
-
setPosition
Set the current position of the stream.- Specified by:
setPosition
in classRandomAccessStream
- Parameters:
value
- The new position.- Throws:
IOException
- Thrown if error during IO
-
setLength
Set the length of the stream.- Specified by:
setLength
in classRandomAccessStream
- Parameters:
value
- The length.- Throws:
IOException
- Thrown if error during IO
-
read
Read data from the stream into the buffer.- Specified by:
read
in classRandomAccessStream
- Parameters:
buffer
- The buffer to read intooffset
- The offset to start reading intocount
- The number of bytes to read- Returns:
- The number of bytes read.
- Throws:
IOException
- Thrown if error during IO
-
write
Write the data buffer to the stream.- Specified by:
write
in classRandomAccessStream
- 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
Seek to the requested position.- Specified by:
seek
in classRandomAccessStream
- 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.- Specified by:
flush
in classRandomAccessStream
-
close
Close the stream.- Specified by:
close
in classRandomAccessStream
- Throws:
IOException
- Thrown if error during IO
-