Package com.mku.streams
Class MemoryStream
- java.lang.Object
- 
- com.mku.streams.RandomAccessStream
- 
- com.mku.streams.MemoryStream
 
 
- 
 public class MemoryStream extends RandomAccessStream Memory Stream for seeking, reading, and writing to a memory buffer (modeled after C# MemoryStream). If the memory buffer is not specified then an internal resizable buffer will be created.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class com.mku.streams.RandomAccessStreamRandomAccessStream.SeekOrigin
 
- 
 - 
Constructor SummaryConstructors Constructor Description MemoryStream()Create a memory stream.MemoryStream(byte[] bytes)Create a memory stream.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRead()Check if the stream is readable.booleancanSeek()Check if the stream is seekable.booleancanWrite()Check if the stream is writable.voidclose()Close any resources the stream is using.voidflush()Flush 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 a sequence of bytes into the provided buffer.longseek(long offset, RandomAccessStream.SeekOrigin origin)Seek to a position in the stream.voidsetLength(long value)Changes the length of the stream.voidsetPosition(long value)Changes the current position of the stream.byte[]toArray()Convert the stream to an array:voidwrite(byte[] buffer, int offset, int count)Write a sequence of bytes into the stream.- 
Methods inherited from class com.mku.streams.RandomAccessStreamcopyTo, copyTo, copyTo
 
- 
 
- 
- 
- 
Method Detail- 
canReadpublic boolean canRead() Description copied from class:RandomAccessStreamCheck if the stream is readable.- Specified by:
- canReadin class- RandomAccessStream
- Returns:
- If the stream can be used for reading.
 
 - 
canWritepublic boolean canWrite() Description copied from class:RandomAccessStreamCheck if the stream is writable.- Specified by:
- canWritein class- RandomAccessStream
- Returns:
- If the stream can be used for writing.
 
 - 
canSeekpublic boolean canSeek() Description copied from class:RandomAccessStreamCheck if the stream is seekable.- Specified by:
- canSeekin class- RandomAccessStream
- Returns:
- If the stream is seekable.
 
 - 
getLengthpublic long getLength() Description copied from class:RandomAccessStreamGet the length of the stream.- Specified by:
- getLengthin class- RandomAccessStream
- Returns:
- The length of the stream.
 
 - 
getPositionpublic long getPosition() Description copied from class:RandomAccessStreamGet the current position of the stream.- Specified by:
- getPositionin class- RandomAccessStream
- Returns:
- The position of the stream.
 
 - 
setPositionpublic void setPosition(long value) Changes the current position of the stream. For more options use seek() method.- Specified by:
- setPositionin class- RandomAccessStream
- Parameters:
- value- The new position of the stream.
 
 - 
setLengthpublic void setLength(long value) Changes the length of the stream. The capacity of the stream might also change if the value is lesser than the current capacity.- Specified by:
- setLengthin class- RandomAccessStream
- Parameters:
- value- The new file length.
 
 - 
readpublic int read(byte[] buffer, int offset, int count) throws java.io.IOExceptionRead a sequence of bytes into the provided buffer.- Specified by:
- readin class- RandomAccessStream
- Parameters:
- buffer- The buffer to write the bytes that are read from the stream.
- offset- The offset of the buffer that will be used to write the bytes.
- count- The length of the bytes that can be read from the stream and written to the buffer.
- Returns:
- The number of bytes read.
- Throws:
- java.io.IOException- Thrown if there is an IO error.
 
 - 
writepublic void write(byte[] buffer, int offset, int count)Write a sequence of bytes into the stream.- Specified by:
- writein class- RandomAccessStream
- Parameters:
- buffer- The buffer that the bytes will be read from.
- offset- The position offset that will be used to read from the buffer.
- count- The number of bytes that will be written to the stream.
 
 - 
seekpublic long seek(long offset, RandomAccessStream.SeekOrigin origin)Seek to a position in the stream.- Specified by:
- seekin class- RandomAccessStream
- Parameters:
- offset- The offset to use.
- origin- Possible Values: Begin, Current, End
- Returns:
- The new position after seeking.
 
 - 
flushpublic void flush() Flush the stream. Not-Applicable for memory stream.- Specified by:
- flushin class- RandomAccessStream
 
 - 
closepublic void close() Close any resources the stream is using. Not-Applicable for memory stream.- Specified by:
- closein class- RandomAccessStream
 
 - 
toArraypublic byte[] toArray() Convert the stream to an array:- Returns:
- A byte array containing the data from the stream.
 
 
- 
 
-