Package org.jboss.vfs
Class TempDir
- java.lang.Object
-
- org.jboss.vfs.TempDir
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class TempDir extends java.lang.Object implements java.io.CloseableA temporary directory which exists until it is closed, at which time its contents will be removed.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBooleanopenprivate TempFileProviderproviderprivate java.io.Fileroot
-
Constructor Summary
Constructors Constructor Description TempDir(TempFileProvider provider, java.io.File root)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this directory.java.io.FilecreateFile(java.lang.String relativePath, java.io.InputStream sourceData)Create a file within this temporary directory, prepopulating the file from the given input stream.protected voidfinalize()java.io.FilegetFile(java.lang.String relativePath)Get theFilefor a relative path.java.io.FilegetRoot()Get theFilethat represents the root of this temporary directory.
-
-
-
Field Detail
-
provider
private final TempFileProvider provider
-
root
private final java.io.File root
-
open
private final java.util.concurrent.atomic.AtomicBoolean open
-
-
Constructor Detail
-
TempDir
TempDir(TempFileProvider provider, java.io.File root)
-
-
Method Detail
-
getRoot
public java.io.File getRoot() throws java.io.IOExceptionGet theFilethat represents the root of this temporary directory. The returned file is only valid as long as the tempdir exists.- Returns:
- the root file
- Throws:
java.io.IOException- if the directory was closed at the time of this invocation
-
getFile
public java.io.File getFile(java.lang.String relativePath) throws java.io.IOExceptionGet theFilefor a relative path. The returned file is only valid as long as the tempdir exists.- Parameters:
relativePath- the relative path- Returns:
- the corresponding file
- Throws:
java.io.IOException- if the directory was closed at the time of this invocation
-
createFile
public java.io.File createFile(java.lang.String relativePath, java.io.InputStream sourceData) throws java.io.IOExceptionCreate a file within this temporary directory, prepopulating the file from the given input stream.- Parameters:
relativePath- the relative path namesourceData- the source input stream to use- Returns:
- the file
- Throws:
java.io.IOException- if the directory was closed at the time of this invocation or an error occurs
-
close
public void close() throws java.io.IOExceptionClose this directory. The contents of the directory will be removed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- if an I/O error occurs
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-