Package com.pdftools.sys
Class FileStream
- java.lang.Object
-
- com.pdftools.sys.FileStream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileStream.Mode
The 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 void
close()
Close the file stream.void
copy(Stream stream)
Copy the content from another stream.long
getLength()
Get the length of the stream in bytes.java.io.RandomAccessFile
GetRandomAccessFile()
Get the underlyingRandomAccessFile
.int
read(byte[] buffer, int offset, int length)
Read from the stream.boolean
seek(long position)
Set byte position.void
setLength(long length)
Set the length of the stream in bytes.long
tell()
Get current byte position.void
write(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.IOException
Create 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.IOException
Create 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 aRandomAccessFile
in "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.IOException
Get the length of the stream in bytes.
-
setLength
public void setLength(long length) throws java.io.IOException
Set 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.IOException
Set byte position.
-
tell
public long tell() throws java.io.IOException
Get current byte position.
-
read
public int read(byte[] buffer, int offset, int length) throws java.io.IOException
Read from the stream.
-
write
public void write(byte[] buffer, int offset, int length) throws java.io.IOException
Write 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
-
-