Class VirtualContainer
java.lang.Object
org.ofdrw.pkg.container.VirtualContainer
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
AnnotsDir, DocDir, OFDDir, PageDir, PagesDir, ResDir, SignDir, SignsDir, TempsDir
-
Constructor Summary
ConstructorsConstructorDescriptionVirtualContainer(Path fullDir) 通过完整路径构造一个虚拟容器VirtualContainer(Path parent, String dirName) 创建一个虚拟容器 -
Method Summary
Modifier and TypeMethodDescriptionaddRaw(String fileName, InputStream in) 向虚拟容器中直接加入流类型资源voidclean()删除整个虚拟容器voidclose()voiddeleteFile(String fileName) 删除文件boolean判断文件或对象是否存在booleanDeprecated.voidflush()将缓存中的对象写入到文件系统中flushContainerByName(String name) 从缓存中刷新指定容器到文件系统中flushFileByName(String name) 从缓存将指定对象写入到文件系统中获取在容器中的绝对路径<R extends VirtualContainer>
RgetContainer(String name, Function<Path, R> mapper) 获取虚拟容器获取虚拟容器的名称获取虚拟容器所处的文件系统路径获取容器中的文件对象通过路径获取文件org.dom4j.Element通过文件名获取元素对象org.dom4j.Element通过路径获取元素获取该容器所属容器获取当前容器完整路径<R extends VirtualContainer>
RobtainContainer(String name, Function<Path, R> mapper) 获取一个虚拟容器对象void向虚拟容器中加入文件voidputFile(String fileName, InputStream in) 向虚拟容器中加入文件向虚拟容器中加入文件putFileWithPath(Path file) 向虚拟容器中加入文件,并获取文件在容器中的绝对路径向虚拟容器加入对象setContainerPath(String actualFullPath) 修正容器的文件系统路径与名称protected VirtualContainersetParent(VirtualContainer parent) 设置所属容器使目录与文件缓存与当前文件系统保持一致(仅用于读取方向)
-
Constructor Details
-
VirtualContainer
通过完整路径构造一个虚拟容器- Parameters:
fullDir- 容器完整路径- Throws:
IllegalArgumentException- 参数错误
-
VirtualContainer
创建一个虚拟容器- Parameters:
parent- 根目录dirName- 新建目录的名称- Throws:
IllegalArgumentException- 参数异常
-
-
Method Details
-
getContainerName
-
syncCacheWithFileSystem
使目录与文件缓存与当前文件系统保持一致(仅用于读取方向)用于兼容文档中路径大小写与压缩包内实际路径不一致的情况: 当按文档路径精确定位容器失败、而按大小写不敏感方式命中实际目录时, 需要把缓存中不存在的名称键清理掉,否则后续按实际目录名查找会被 先前写入的旧键阻断(缓存按名称命中前会先检查目录是否存在)。
该方法只清理键名与文件系统不一致的缓存项,不会创建任何目录或文件。
- Returns:
- this
-
getSysAbsPath
-
setContainerPath
修正容器的文件系统路径与名称用于兼容文档中路径大小写与压缩包内实际路径不一致的情况: 虚拟容器按文档中的名称创建时,其系统路径使用的是文档中的大小写, 在大小写敏感的文件系统上无法访问到实际目录,这里按实际存在的路径修正。
该方法不创建目录、不改变容器缓存,仅修正路径与名称。
- Parameters:
actualFullPath- 实际存在的目录路径(绝对路径)- Returns:
- this
- Throws:
IllegalArgumentException- 参数为空或目录不存在
-
putFile
向虚拟容器中加入文件- Parameters:
file- 文件路径对象- Returns:
- this
- Throws:
IOException- IO异常
-
putFileWithPath
向虚拟容器中加入文件,并获取文件在容器中的绝对路径- Parameters:
file- 文件路径对象- Returns:
- null 或 文件在容器中的绝对路径
- Throws:
IOException- IO异常
-
addRaw
向虚拟容器中直接加入流类型资源根据提供文件名称创建文件
输入流内容将直接写入文件内,不做检查
若文件已经存在,那么将会覆盖原文件!
- Parameters:
fileName- 文件名称in- 输入流,流的关闭应由调用者负责- Returns:
- this
- Throws:
IOException- 文件复制异常
-
putObj
向虚拟容器加入对象- Parameters:
fileName- 文件名element- 元素对象- Returns:
- this
-
getObj
通过路径获取元素例如:
当前
/Doc_0/Pages,获取 /Doc_0/Pages/Page_0/Content.xml 结果 Page Element
当前
/Doc_0/Tpl 结果 获取 /Doc_0/Pages/Page_0/Content.xml 结果 null
当前
/Doc_0/Pages 结果 获取 Page_0/Content.xml 结果 Page Element
- Parameters:
loc- 元素所在路径,支持相对路径,若是绝对路径且不在当前容器中,那么返回null- Returns:
- 元素对象,不存在返回null
- Throws:
org.dom4j.DocumentException- 元素序列化异常
-
getFile
通过路径获取文件注意在文档尚未关闭之前,获取的元素对象是缓存的,此时若获取文件将会出现 FileNotFoundException。
获取获取时若使用绝对路径,与当前目录没有相同的前缀则返回null。
例如:
当前
/Doc_0/Pages,获取 /Doc_0/Pages/Page_0/Content.xml 结果 Content.xml
当前
/Doc_0/Pages,获取 /Doc_0/Pages/Page_0/Content.xml 结果 null
当前
/Doc_0/Pages,获取 Page_0/Content.xml 结果 Content.xml
- Parameters:
loc- 文件路径,可以是相对路径,也可以是绝对路径。- Returns:
- 文件路径 或 文件不存在返回null。
-
getObj
public org.dom4j.Element getObj(String fileName) throws FileNotFoundException, org.dom4j.DocumentException 通过文件名获取元素对象- Parameters:
fileName- 文件名- Returns:
- 元素对象(不含代理)
- Throws:
FileNotFoundException- 文件不存在org.dom4j.DocumentException- 元素序列化异常
-
getFile
获取容器中的文件对象- Parameters:
fileName- 文件名称- Returns:
- 文件路径对象
- Throws:
FileNotFoundException- 文件不存在
-
obtainContainer
获取一个虚拟容器对象如果容器存在,那么取出元素
如果容器不存在,那么创建一个新的对象
- Type Parameters:
R- 容器子类- Parameters:
name- 容器名称mapper- 容器构造器引用- Returns:
- 新建或已经存在的容器
-
getContainer
public <R extends VirtualContainer> R getContainer(String name, Function<Path, R> mapper) throws FileNotFoundException获取虚拟容器- Type Parameters:
R- 容器子类- Parameters:
name- 容器名称mapper- 容器构造器引用- Returns:
- 容器对象
- Throws:
FileNotFoundException- 文件不存在
-
getParent
-
setParent
设置所属容器- Parameters:
parent- 容器- Returns:
- this
-
getContainerPath
-
exit
Deprecated.判断文件或对象是否存在(错误的函数名称)- Parameters:
fileName- 文件名称- Returns:
- true - 存在;false - 不存在
-
exist
判断文件或对象是否存在- Parameters:
fileName- 文件名称- Returns:
- true - 存在;false - 不存在
-
deleteFile
删除文件注意该方法只能删除当前容器中的文件,不能删除子容器中的文件。
- Parameters:
fileName- 文件名称- Throws:
IOException- 文件删除异常
-
clean
public void clean()删除整个虚拟容器 -
flush
-
flushContainerByName
从缓存中刷新指定容器到文件系统中- Parameters:
name- 容器名称- Returns:
- this
- Throws:
IOException- 写入文件IO异常
-
flushFileByName
从缓存将指定对象写入到文件系统中- Parameters:
name- 文件名称- Returns:
- this
- Throws:
IOException- 写入文件IO异常
-
getAbsLoc
-
putFile
向虚拟容器中加入文件- Parameters:
fileName- 文件名称in- 输入流,流的关闭应由调用者负责- Throws:
IOException- 文件复制异常
-
putFile
向虚拟容器中加入文件- Parameters:
fileName- 文件名称data- 数据内容- Throws:
IOException- 文件写入异常
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
exist(String)