Package com.mku.file
Class JavaFileStream
java.lang.Object
com.mku.streams.RandomAccessStream
com.mku.file.JavaFileStream
An advanced Salmon File Stream implementation for java files.
This class is used internally for random file access of physical (real) files.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.mku.streams.RandomAccessStream
RandomAccessStream.SeekOrigin
-
Constructor Summary
ConstructorDescriptionJavaFileStream
(JavaFile file, String mode) Construct a file stream from a JavaFile. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRead()
True if stream can read from file.boolean
canSeek()
True if stream can seek.boolean
canWrite()
True if stream can write to file.void
close()
Close this stream and associated resources.void
flush()
Flush the buffers to the associated file.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 file stream into the buffer provided.long
seek
(long offset, RandomAccessStream.SeekOrigin origin) Seek to the offset provided.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 from the buffer provided into the stream.Methods inherited from class com.mku.streams.RandomAccessStream
copyTo, copyTo, copyTo
-
Constructor Details
-
JavaFileStream
Construct a file stream from a JavaFile. This will create a wrapper stream that will route read() and write() to the FileChannel- Parameters:
file
- The JavaFile that will be used to get the read/write streammode
- The mode "r" for read "rw" for write- Throws:
FileNotFoundException
- Thrown if file not found
-
-
Method Details
-
canRead
public boolean canRead()True if stream can read from file.- Specified by:
canRead
in classRandomAccessStream
- Returns:
- True if readable
-
canWrite
public boolean canWrite()True if stream can write to file.- Specified by:
canWrite
in classRandomAccessStream
- Returns:
- True if writable
-
canSeek
public boolean canSeek()True if stream can seek.- Specified by:
canSeek
in classRandomAccessStream
- Returns:
- True if seekable
-
length
public long length()Get the length of the stream. This is the same as the backed file.- Specified by:
length
in classRandomAccessStream
- Returns:
- The file stream length
-
getPosition
Get the current position of the stream.- Specified by:
getPosition
in classRandomAccessStream
- Returns:
- The current position
- Throws:
IOException
- Thrown if there is an IO error.
-
setPosition
Set the current position of the stream.- Specified by:
setPosition
in classRandomAccessStream
- Parameters:
value
- The new position.- Throws:
IOException
- Thrown if there is an IO error.
-
setLength
Set the length of the stream. This is applicable for write streams only.- Specified by:
setLength
in classRandomAccessStream
- Parameters:
value
- The new length.- Throws:
IOException
- Thrown if there is an IO error.
-
read
Read data from the file stream into the buffer provided.- Specified by:
read
in classRandomAccessStream
- Parameters:
buffer
- The buffer to write the data.offset
- The offset of the buffer to start writing the data.count
- The maximum number of bytes to read from.- Returns:
- The bytes read
- Throws:
IOException
- Thrown if there is an IO error.
-
write
Write the data from the buffer provided into the stream.- Specified by:
write
in classRandomAccessStream
- Parameters:
buffer
- The buffer to read the data from.offset
- The offset of the buffer to start reading the data.count
- The maximum number of bytes to read from the buffer.- Throws:
IOException
- Thrown if there is an IO error.
-
seek
Seek to the offset provided.- Specified by:
seek
in classRandomAccessStream
- Parameters:
offset
- The position to seek to.origin
- The type of originRandomAccessStream.SeekOrigin
- Returns:
- The new position after seeking.
- Throws:
IOException
- Thrown if there is an IO error.
-
flush
public void flush()Flush the buffers to the associated file.- Specified by:
flush
in classRandomAccessStream
-
close
Close this stream and associated resources.- Specified by:
close
in classRandomAccessStream
- Throws:
IOException
- Thrown if there is an IO error.
-