public class FileHandler extends Object implements IScopeProvider
FileSender
and
FilePipe
, allows to write to or read from a file.
Actions take place on the file specified by the fileName attribute (or when not available the fileNameSessionKey, when fileNameSessionKey is empty too the input of the pipe is used as file name). When a directory is not specified, the fileName is expected to include the directory.
When a file needs to be created and both the fileName and the directory are not specified a temporary file is created as specified by the java.io.File.createTempFile method using the string "ibis" as a prefix and a suffix as specified bij the writeSuffix attribute. If only the directory is specified, the temporary file is created the same way except that the temporary file is created in the specified directory.
The pipe also support base64 en- and decoding.
name | type | remarks |
---|---|---|
writeSuffix | String | When a parameter with name writeSuffix is present, it is used instead of the writeSuffix specified by the attribute |
Modifier and Type | Class and Description |
---|---|
protected static interface |
FileHandler.TransformerAction
The pipe supports several actions.
|
protected static interface |
FileHandler.TransformerActionWithInputTypeStream |
protected static interface |
FileHandler.TransformerActionWithOutputTypeStream |
Modifier and Type | Field and Description |
---|---|
protected String |
actions |
protected static byte[] |
BOM_UTF_8 |
protected String |
charset |
protected boolean |
createDirectory |
protected boolean |
deleteEmptyDirectory |
protected String |
directory |
protected byte[] |
eolArray |
protected String |
filename |
protected String |
filenameSessionKey |
protected String |
fileSource |
protected org.apache.logging.log4j.Logger |
log |
protected String |
outputType |
protected boolean |
skipBOM |
protected boolean |
streamResultToServlet |
protected boolean |
testCanWrite |
protected boolean |
testExists |
protected List |
transformers |
protected boolean |
writeLineSeparator |
protected String |
writeSuffix |
Constructor and Description |
---|
FileHandler() |
Modifier and Type | Method and Description |
---|---|
void |
configure() |
String |
getActions() |
String |
getDirectory() |
String |
getFilename() |
String |
getFilenameSessionKey() |
protected String |
getLogPrefix(PipeLineSession session) |
String |
getWriteSuffix() |
Object |
handle(Message input,
PipeLineSession session,
ParameterList paramList) |
boolean |
isCreateDirectory() |
boolean |
isDeleteEmptyDirectory() |
boolean |
isSkipBOM() |
boolean |
isStreamResultToServlet() |
boolean |
isTestCanWrite() |
boolean |
isTestExists() |
boolean |
isWriteLineSeparator() |
void |
setActions(String actions)
Sets actions the pipe has to perform.
|
void |
setCharset(String charset)
the charset to be used when transforming a string to a byte array and/or the other way around
|
void |
setCreateDirectory(boolean b)
when set to
true , the directory to read from or write to is created if it does not exist |
void |
setDeleteEmptyDirectory(boolean b)
(only used when actions=delete) when set to
true , the directory from which a file is deleted is also deleted when it contains no other files |
void |
setDirectory(String directory)
Sets the directory in which the file resides or has to be created
|
void |
setFilename(String filename)
Sets filename of the file that is written
|
void |
setFileName(String filename)
Deprecated.
|
void |
setFilenameSessionKey(String filenameSessionKey)
Sets filenameSessionKey the session key that contains the name of the file to be created (only used if filename is not set)
|
void |
setFileNameSessionKey(String filenameSessionKey)
Deprecated.
|
void |
setFileSource(String fileSource)
either
filesystem or classpath (classpath will only work for actions 'read' and 'info' and for 'info' only when resources are available as a file (i.e. |
void |
setOutputType(String outputType)
either
string , bytes , stream or base64 |
void |
setSkipBOM(boolean b)
when set to
true , a possible bytes order mark (bom) at the start of the file is skipped (only used for the action read and encoding uft-8) |
void |
setStreamResultToServlet(boolean b)
(only used when outputtype=stream) if set, the result is streamed to the httpservletresponse object
|
void |
setTestCanWrite(boolean b)
when set to
true , a test is performed to find out if a temporary file can be created and deleted in the specified directory (only used if directory is set and combined with the action write, write_append or create) |
void |
setTestExists(boolean testExists)
test if the specified directory exists at configure()
|
void |
setWriteLineSeparator(boolean b)
when set to
true , a line separator is written after the content is written |
void |
setWriteSuffix(String suffix)
Sets suffix of the file that is written (only used if filename and filenamesession are not set)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConfigurationClassLoader
protected org.apache.logging.log4j.Logger log
protected static final byte[] BOM_UTF_8
protected String charset
protected String outputType
protected String fileSource
protected String actions
protected String directory
protected String writeSuffix
protected String filename
protected String filenameSessionKey
protected boolean createDirectory
protected boolean writeLineSeparator
protected boolean testExists
protected boolean testCanWrite
protected boolean skipBOM
protected boolean deleteEmptyDirectory
protected boolean streamResultToServlet
protected List transformers
protected byte[] eolArray
public void configure() throws ConfigurationException
ConfigurationException
IPipe.configure()
public Object handle(Message input, PipeLineSession session, ParameterList paramList) throws Exception
Exception
protected String getLogPrefix(PipeLineSession session)
public void setCharset(String charset)
public void setOutputType(String outputType)
string
, bytes
, stream
or base64
public void setFileSource(String fileSource)
filesystem
or classpath
(classpath will only work for actions 'read' and 'info' and for 'info' only when resources are available as a file (i.e. doesn't work for resources in jar files and war files which are deployed without being extracted by the application server))public void setActions(String actions)
Dir2Xml
). If a directory is not specified, the fileName is expected to include the directorypublic String getActions()
public void setDirectory(String directory)
public String getDirectory()
public void setWriteSuffix(String suffix)
public String getWriteSuffix()
@Deprecated @ConfigurationWarning(value="attribute \'fileName\' is replaced with \'filename\'") public void setFileName(String filename)
public void setFilename(String filename)
public String getFilename()
@Deprecated @ConfigurationWarning(value="attribute \'fileNameSessionKey\' is replaced with \'filenameSessionKey\'") public void setFileNameSessionKey(String filenameSessionKey)
public void setFilenameSessionKey(String filenameSessionKey)
public String getFilenameSessionKey()
public void setTestExists(boolean testExists)
public boolean isTestExists()
public void setCreateDirectory(boolean b)
true
, the directory to read from or write to is created if it does not existpublic boolean isCreateDirectory()
public void setWriteLineSeparator(boolean b)
true
, a line separator is written after the content is writtenpublic boolean isWriteLineSeparator()
public void setTestCanWrite(boolean b)
true
, a test is performed to find out if a temporary file can be created and deleted in the specified directory (only used if directory is set and combined with the action write, write_append or create)public boolean isTestCanWrite()
public void setSkipBOM(boolean b)
true
, a possible bytes order mark (bom) at the start of the file is skipped (only used for the action read and encoding uft-8)public boolean isSkipBOM()
public void setDeleteEmptyDirectory(boolean b)
true
, the directory from which a file is deleted is also deleted when it contains no other filespublic boolean isDeleteEmptyDirectory()
public void setStreamResultToServlet(boolean b)
public boolean isStreamResultToServlet()
Copyright © 2023 Frank!Framework. All rights reserved.