Package com.mku.android.fs.streams
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
ConstructorsConstructorDescriptionAndroidFileStream(AndroidFile file, String mode) Construct a file stream from an AndroidFile. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanRead()True if the stream is readable.booleancanSeek()True if the stream is seekable (random access).booleancanWrite()True if the stream is writeable.voidclose()Close the stream.voidflush()Flush the buffers to the stream.longGet the length of the stream.longGet the current position of the stream.intread(byte[] buffer, int offset, int count) Read data from the stream into the buffer.longseek(long offset, SeekOrigin origin) Seek to the requested position.voidsetLength(long value) Set the length of the stream.voidsetPosition(long value) Set the current position of the stream.voidwrite(byte[] buffer, int offset, int count) Write the data buffer to the stream.
-
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.- 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
Get the current position of the stream.- Returns:
- The current position
- Throws:
IOException- Thrown if error during IO
-
setPosition
Set the current position of the stream.- Parameters:
value- The new position.- Throws:
IOException- Thrown if error during IO
-
setLength
Set the length of the stream.- Parameters:
value- The length.- Throws:
IOException- Thrown if error during IO
-
read
Read data from the stream into the buffer.- 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.- 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.- 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
Close the stream.- Throws:
IOException- Thrown if error during IO
-