Package com.pdftools.sys
Class MemoryStream
- java.lang.Object
-
- com.pdftools.sys.MemoryStream
-
-
Constructor Summary
Constructors Constructor Description MemoryStream()
Create a new memory stream with initial capacity of 0.MemoryStream(byte[] buffer)
Create a new memory stream by copying from a buffer.MemoryStream(byte[] buffer, int offset, int length)
Create a new memory stream by copying from a buffer.MemoryStream(Stream stream)
Create a new memory stream by copying a stream.MemoryStream(java.io.InputStream inStream)
Create a new memory stream by copying the given stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the stream and release all associated resources.long
getLength()
Get the length of the stream in bytes.int
read(byte[] buffer)
Read from the stream.int
read(byte[] buffer, int offset, int length)
Read from the stream.boolean
seek(long position)
Set byte position.long
tell()
Get current byte position.byte[]
toByteArray()
Creates a newly allocated byte array.int
transferFrom(java.io.InputStream inStream)
Read data from the input stream and write it to this stream.long
transferTo(java.io.OutputStream outStream)
Read data from this stream and write it to the output stream.void
write(byte[] buffer, int offset, int length)
Write to the stream.
-
-
-
Constructor Detail
-
MemoryStream
public MemoryStream()
Create a new memory stream with initial capacity of 0.
-
MemoryStream
public MemoryStream(byte[] buffer, int offset, int length)
Create a new memory stream by copying from a buffer.- Parameters:
buffer
- The buffer from which the initial data is copiedoffset
- The offset where the first byte from the buffer is copiedlength
- The number of bytes that are copied from the buffer
-
MemoryStream
public MemoryStream(byte[] buffer)
Create a new memory stream by copying from a buffer.- Parameters:
buffer
- The buffer from which the initial data is copied
-
MemoryStream
public MemoryStream(Stream stream) throws java.io.IOException
Create a new memory stream by copying a stream.- Parameters:
stream
- The stream from which the initial data is copied- Throws:
java.io.IOException
- if an I/O error occurs
-
MemoryStream
public MemoryStream(java.io.InputStream inStream) throws java.io.IOException
Create a new memory stream by copying the given stream.- Parameters:
inStream
- The stream from which the initial data is copied- Throws:
java.io.IOException
- if an I/O error occurs
-
-
Method Detail
-
getLength
public long getLength()
Get the length of the stream in bytes.
-
seek
public boolean seek(long position)
Set byte position.
-
tell
public long tell()
Get current byte position.
-
read
public int read(byte[] buffer, int offset, int length)
Read from the stream.
-
read
public int read(byte[] buffer)
Read from the stream.- Parameters:
buffer
- The buffer where the data is written to- Returns:
- The actual number of bytes read (-1 if EOS)
-
toByteArray
public byte[] toByteArray()
Creates a newly allocated byte array. Its size is the current size of this stream and the contents have been copied into it.- Returns:
- The current contents of this stream as a byte array.
- Throws:
java.lang.OutOfMemoryError
- if an array larger than 2GB would be required to store the bytes.
-
transferFrom
public int transferFrom(java.io.InputStream inStream) throws java.io.IOException
Read data from the input stream and write it to this stream. The data is appended at the stream's current byte position.- Parameters:
inStream
- The stream from which the data is copied- Returns:
- The actual number of transferred bytes
- Throws:
java.io.IOException
- if an I/O error occurs
-
transferTo
public long transferTo(java.io.OutputStream outStream) throws java.io.IOException
Read data from this stream and write it to the output stream. The data is read starting from the stream's current byte position. In order to read the entire stream, make sure to first position the stream at the beginning usingseek(0)
.- Parameters:
outStream
- The stream to which the data is copied- Returns:
- The actual number of transfered bytes
- Throws:
java.io.IOException
- if an I/O error occurs
-
write
public void write(byte[] buffer, int offset, int length)
Write to the stream.
-
-