Package com.mku.android.fs.streams
Class AndroidFileStream
- java.lang.Object
-
- com.mku.streams.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.mku.streams.RandomAccessStream
RandomAccessStream.SeekOrigin
-
-
Constructor Summary
Constructors Constructor Description AndroidFileStream(AndroidFile file, java.lang.String mode)Construct a file stream from an AndroidFile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRead()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.longgetLength()Get the length of the stream.longgetPosition()Get the current position of the stream.intread(byte[] buffer, int offset, int count)Read data from the stream into the buffer.longseek(long offset, RandomAccessStream.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.-
Methods inherited from class com.mku.streams.RandomAccessStream
copyTo, copyTo, copyTo
-
-
-
-
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 streammode- 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:
canReadin classRandomAccessStream- Returns:
- True if readable
-
canWrite
public boolean canWrite()
True if the stream is writeable.- Specified by:
canWritein classRandomAccessStream- Returns:
- True if writeable
-
canSeek
public boolean canSeek()
True if the stream is seekable (random access).- Specified by:
canSeekin classRandomAccessStream- Returns:
- True if seekable
-
getLength
public long getLength()
Get the length of the stream.- Specified by:
getLengthin classRandomAccessStream- Returns:
- The length
-
getPosition
public long getPosition() throws java.io.IOExceptionGet the current position of the stream.- Specified by:
getPositionin classRandomAccessStream- Returns:
- The current position
- Throws:
java.io.IOException- Thrown if error during IO
-
setPosition
public void setPosition(long value) throws java.io.IOExceptionSet the current position of the stream.- Specified by:
setPositionin classRandomAccessStream- Parameters:
value- The new position.- Throws:
java.io.IOException- Thrown if error during IO
-
setLength
public void setLength(long value) throws java.io.IOExceptionSet the length of the stream.- Specified by:
setLengthin classRandomAccessStream- 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.IOExceptionRead data from the stream into the buffer.- Specified by:
readin 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:
java.io.IOException- Thrown if error during IO
-
write
public void write(byte[] buffer, int offset, int count) throws java.io.IOExceptionWrite the data buffer to the stream.- Specified by:
writein 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:
java.io.IOException- Thrown if error during IO
-
seek
public long seek(long offset, RandomAccessStream.SeekOrigin origin) throws java.io.IOExceptionSeek to the requested position.- Specified by:
seekin classRandomAccessStream- Parameters:
offset- The new position.origin- The origin type.- Returns:
- The current position after seeking
- Throws:
java.io.IOException- Thrown if error during IO
-
flush
public void flush()
Flush the buffers to the stream.- Specified by:
flushin classRandomAccessStream
-
close
public void close() throws java.io.IOExceptionClose the stream.- Specified by:
closein classRandomAccessStream- Throws:
java.io.IOException- Thrown if error during IO
-
-