Package com.pdftools.sys
Class FileStream
- java.lang.Object
-
- com.pdftools.sys.FileStream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileStream.ModeThe file access mode.
-
Constructor Summary
Constructors Constructor Description FileStream(java.io.File file, FileStream.Mode mode)Create a new file stream from a file.FileStream(java.io.RandomAccessFile raFile)Create a new file stream from aRandomAccessFile.FileStream(java.lang.String filename, FileStream.Mode mode)Create a new file stream from a file name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the file stream.voidcopy(Stream stream)Copy the content from another stream.longgetLength()Get the length of the stream in bytes.java.io.RandomAccessFileGetRandomAccessFile()Get the underlyingRandomAccessFile.intread(byte[] buffer, int offset, int length)Read from the stream.booleanseek(long position)Set byte position.voidsetLength(long length)Set the length of the stream in bytes.longtell()Get current byte position.voidwrite(byte[] buffer, int offset, int length)Write to the stream.
-
-
-
Constructor Detail
-
FileStream
public FileStream(java.io.File file, FileStream.Mode mode) throws java.io.IOExceptionCreate a new file stream from a file. This constructor works similarly to the constructor of the underlyingjava.io.RandomAccessFile.- Parameters:
file- The file to be openedmode- The open mode of the file- Throws:
java.io.IOException- See Also:
RandomAccessFile(java.io.File, String)
-
FileStream
public FileStream(java.lang.String filename, FileStream.Mode mode) throws java.io.IOExceptionCreate a new file stream from a file name. This constructor works similarly to the constructor of the underlyingjava.io.RandomAccessFile.- Parameters:
filename- The name of the file to be openedmode- The open mode of the file- Throws:
java.io.IOException- See Also:
RandomAccessFile(java.io.File, String)
-
FileStream
public FileStream(java.io.RandomAccessFile raFile)
Create a new file stream from aRandomAccessFile. ATTENTION: Opening aRandomAccessFilein "rw" mode does not delete the current content of the file, so be sure that you delete it yourself if needed (which is mostly the case).- Parameters:
raFile- The underlyingRandomAccessFile- See Also:
RandomAccessFile
-
-
Method Detail
-
GetRandomAccessFile
public java.io.RandomAccessFile GetRandomAccessFile()
Get the underlyingRandomAccessFile.- Returns:
- The underlying
RandomAccessFile
-
getLength
public long getLength() throws java.io.IOExceptionGet the length of the stream in bytes.
-
setLength
public void setLength(long length) throws java.io.IOExceptionSet the length of the stream in bytes.- Parameters:
length- the length of the stream in bytes- Throws:
java.io.IOException
-
seek
public boolean seek(long position) throws java.io.IOExceptionSet byte position.
-
tell
public long tell() throws java.io.IOExceptionGet current byte position.
-
read
public int read(byte[] buffer, int offset, int length) throws java.io.IOExceptionRead from the stream.
-
write
public void write(byte[] buffer, int offset, int length) throws java.io.IOExceptionWrite to the stream.
-
copy
public void copy(Stream stream) throws java.io.IOException
Copy the content from another stream.- Parameters:
stream- The stream from which the content is copied- Throws:
java.io.IOException
-
-