public class FileHandler
extends java.lang.Object
FileHandler
represents a file handle.
FileHandler class offers different methods to create a file handle.
It can be constructed by the following way.
Example:
FileHandler fileHandle = FileHandler.create(fileName, fileModes);
Modifier and Type | Field and Description |
---|---|
static int |
FILEMODE_READONLY
Read-only mode.
|
static int |
FILEMODE_TRUNCATE
Clear existing contents, size of file is set to 0, for writing mode only.
|
static int |
FILEMODE_WRITE
Write mode, create automatically if a file doesn't exist.
|
Modifier and Type | Method and Description |
---|---|
static FileHandler |
create(byte[] buffer,
int fileModes)
Create a memory-based
FileHandler object. |
static FileHandler |
create(java.lang.String fileName,
int fileModes)
Create a
FileHandler object from the specific file path. |
long |
getHandle()
Get the file handle.
|
int |
getSize()
Get the actual size of current
FileHandler object. |
byte[] |
read(int offset,
int size)
Read buffer(represented as byte array) from the specific file which is related with current
FileHandler object. |
void |
release()
Release current
FileHandler object. |
public static final int FILEMODE_WRITE
public static final int FILEMODE_READONLY
public static final int FILEMODE_TRUNCATE
public long getHandle()
public static FileHandler create(java.lang.String fileName, int fileModes) throws PDFException
FileHandler
object from the specific file path.fileName
- A file path string including file name.fileModes
- Indicate a file mode. It should be one of the following value:FileHandler
object.PDFException
- PDFException.ERRCODE_ERROR
if the function
cannot create file object because of any reasons. For example,
a file is not existing.PDFException.ERRCODE_XXX
.PDFException
public static FileHandler create(byte[] buffer, int fileModes) throws PDFException
FileHandler
object.
The memory-based file handler is either for reading or writing purpose,
not for both reading and writing.buffer
- A memory block to access data. It should be valid.fileModes
- Indicate a file mode. It should be one of the following values:FileHandler
object.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public void release() throws PDFException
FileHandler
object.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public int getSize() throws PDFException
FileHandler
object.FileHandler
object.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public byte[] read(int offset, int size) throws PDFException
FileHandler
object.
This function is only useful when current FileHandler
object is created
by function create(String, int)
.
offset
- An integer value that specifies the offset, at which to start storing characters.size
- Number of characters to read.FileHandler
object.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException