Package com.pdftools.toolbox.sys
Interface Stream
-
- All Superinterfaces:
java.lang.AutoCloseable
- All Known Implementing Classes:
FileStream,MemoryStream
public interface Stream extends java.lang.AutoCloseableThe unified stream interface for reading and writing data. Java's stream interfaces cannot be used, because they are lacking two important features:- The PDF file format is based on random access. Java streams have only limited support for this.
- The ability to read from an output stream is crucial for processing large PDF files.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Close the stream and release all associated resources.longgetLength()Get the length of the stream in bytesintread(byte[] buffer, int offset, int length)Read from the streambooleanseek(long position)Set byte positionlongtell()Get current byte positionvoidwrite(byte[] buffer, int offset, int length)Write to the stream
-
-
-
Method Detail
-
getLength
long getLength() throws java.io.IOExceptionGet the length of the stream in bytes- Returns:
- the length of the stream in bytes
- Throws:
java.io.IOException
-
seek
boolean seek(long position) throws java.io.IOExceptionSet byte position- Parameters:
position- The new position of the stream (-1 for EOS)- Returns:
- true if successful
- Throws:
java.io.IOException
-
tell
long tell() throws java.io.IOException
Get current byte position- Returns:
- byte position, -1 if position unknown
- Throws:
java.io.IOException
-
read
int read(byte[] buffer, int offset, int length) throws java.io.IOExceptionRead from the stream- Parameters:
buffer- The buffer where the data is writtenoffset- The starting element in the bufferlength- The maximum number of bytes to be read- Returns:
- The actual number of bytes read (-1 if EOS)
- Throws:
java.io.IOException
-
write
void write(byte[] buffer, int offset, int length) throws java.io.IOExceptionWrite to the stream- Parameters:
buffer- The buffer where the data liesoffset- The starting element in the bufferlength- The maximum number of bytes to write- Throws:
java.io.IOException
-
close
void close() throws java.io.IOExceptionClose the stream and release all associated resources.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.io.IOException
-
-