Package com.mku.fs.stream
Class WSFileStream
- java.lang.Object
-
- com.mku.streams.RandomAccessStream
-
- com.mku.fs.stream.WSFileStream
-
public class WSFileStream extends RandomAccessStream
File stream implementation for web service files.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.mku.streams.RandomAccessStream
RandomAccessStream.SeekOrigin
-
-
Field Summary
Fields Modifier and Type Field Description CloseableHttpClientclient
-
Constructor Summary
Constructors Constructor Description WSFileStream(WSFile file, java.lang.String mode)Construct a file stream from a JavaFile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRead()Check if stream can read from file.booleancanSeek()Check if stream can seek.booleancanWrite()Check if stream can write to file.voidclose()Close this stream and associated resources.voidflush()Flush the buffers to the associated file.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 file stream into the buffer provided.voidreset()longseek(long offset, RandomAccessStream.SeekOrigin origin)Seek to the offset provided.voidsetLength(long value)Set the length of the stream.voidsetMaxNetBytesSkip(long maxNetBytesSkip)Maximum amount of bytes allowed to skip forwards when seeking otherwise will open a new connectionvoidsetPosition(long value)Set the current position of the stream.voidwrite(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 Detail
-
WSFileStream
public WSFileStream(WSFile file, java.lang.String mode) throws java.io.FileNotFoundException
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:
java.io.FileNotFoundException- Thrown if file not found
-
-
Method Detail
-
setMaxNetBytesSkip
public void setMaxNetBytesSkip(long maxNetBytesSkip)
Maximum amount of bytes allowed to skip forwards when seeking otherwise will open a new connection- Parameters:
maxNetBytesSkip- The maximum number of bytes to skip
-
canRead
public boolean canRead()
Check if stream can read from file.- Specified by:
canReadin classRandomAccessStream- Returns:
- True if readable
-
canWrite
public boolean canWrite()
Check if stream can write to file.- Specified by:
canWritein classRandomAccessStream- Returns:
- True if writable
-
canSeek
public boolean canSeek()
Check if stream can seek.- Specified by:
canSeekin classRandomAccessStream- Returns:
- True if seekable
-
getLength
public long getLength()
Get the length of the stream. This is the same as the backed file.- Specified by:
getLengthin classRandomAccessStream- Returns:
- The file stream 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 there is an IO error.
-
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 there is an IO error.
-
setLength
public void setLength(long value) throws java.io.IOExceptionSet the length of the stream. This is applicable for write streams only.- Specified by:
setLengthin classRandomAccessStream- Parameters:
value- The new length.- Throws:
java.io.IOException- Thrown if there is an IO error.
-
read
public int read(byte[] buffer, int offset, int count) throws java.io.IOExceptionRead data from the file stream into the buffer provided.- Specified by:
readin 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:
java.io.IOException- Thrown if there is an IO error.
-
write
public void write(byte[] buffer, int offset, int count) throws java.io.IOExceptionWrite the data from the buffer provided into the stream.- Specified by:
writein 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:
java.io.IOException- Thrown if there is an IO error.
-
seek
public long seek(long offset, RandomAccessStream.SeekOrigin origin) throws java.io.IOExceptionSeek to the offset provided.- Specified by:
seekin classRandomAccessStream- Parameters:
offset- The position to seek to.origin- The type of originRandomAccessStream.SeekOrigin- Returns:
- The new position after seeking.
- Throws:
java.io.IOException- Thrown if there is an IO error.
-
flush
public void flush()
Flush the buffers to the associated file.- Specified by:
flushin classRandomAccessStream
-
close
public void close() throws java.io.IOExceptionClose this stream and associated resources.- Specified by:
closein classRandomAccessStream- Throws:
java.io.IOException- Thrown if there is an IO error.
-
reset
public void reset() throws java.io.IOException- Throws:
java.io.IOException
-
-