public class StorageEditor extends Object
StorageUtils to perform Files
related operations.| Modifier and Type | Field and Description |
|---|---|
static int |
COPY
Flag used to indicate that copy of file/directory should be created with
COPY_SUFFIX. |
static String |
COPY_SUFFIX
Suffix for name of file/directory when creating a copy of it passing
COPY flag to some
of this editor's methods accepting flags parameter. |
static int |
DEFAULT
Flag used to indicate that default options for storage operation should be used.
|
static int |
LARGE_BUFFER
Large buffer type for
createBuffer(int) method. |
static int |
MEDIUM_BUFFER
Medium buffer type for
createBuffer(int) method. |
static int |
OVERWRITE
Flag used to indicate that file/directory can be overwritten.
|
static int |
SMALL_BUFFER
Small buffer type for
createBuffer(int) method. |
static int |
XLARGE_BUFFER
X-Large buffer type for
createBuffer(int) method. |
static int |
XXLARGE_BUFFER
XX-Large buffer type for
createBuffer(int) method. |
| Constructor and Description |
|---|
StorageEditor() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
copyDirectoryContent(File directory)
Same as
copyDirectoryContent(int, File, File) with COPY flag
and null toDirectory parameter, so there will be created new copy of
the given directory at the same path with COPY_SUFFIX. |
boolean |
copyDirectoryContent(int flags,
File fromDirectory,
File toDirectory)
Same as
copyDirectoryContent(int, File, File, FileFilter, FilenameFilter)
with null filters. |
boolean |
copyDirectoryContent(int flags,
File fromDirectory,
File toDirectory,
FileFilter filter,
FilenameFilter nameFilter)
Copies a content from the given fromDirectory into the given toDirectory.
|
boolean |
copyFileContent(File file)
Same as
copyFileContent(int, File, File) with COPY flag and
null toFile parameter, so there will be created new copy of the given
file at the same path with COPY_SUFFIX. |
boolean |
copyFileContent(int flags,
File fromFile,
File toFile)
Copies a content from the given fromFile into the given toFile.
|
boolean |
copyFileStreams(FileInputStream inputStream,
FileOutputStream outputStream)
Same as
copyFileStreams(FileInputStream, FileOutputStream, int)
with MEDIUM_BUFFER type. |
boolean |
copyFileStreams(FileInputStream inputStream,
FileOutputStream outputStream,
byte[] buffer)
Copies a content of the given inputStream into the given outputStream
using the given buffer.
|
boolean |
copyFileStreams(FileInputStream inputStream,
FileOutputStream outputStream,
int bufferType)
Same as
copyFileStreams(FileInputStream, FileOutputStream, byte[])
with buffer obtained from createBuffer(int) for the desired bufferType. |
static byte[] |
createBuffer(int bufferType)
Creates a new bytes buffer for the specified bufferType.
|
boolean |
deleteDirectory(File directory)
Same as
deleteDirectory(File, FileFilter, FilenameFilter)
with null filters. |
boolean |
deleteDirectory(File directory,
FileFilter filter,
FilenameFilter nameFilter)
Deletes the given directory and its content (all files + subdirectories) on the file system.
|
boolean |
moveDirectoryContent(int flags,
File fromDirectory,
File toDirectory)
Same as
moveDirectoryContent(int, File, File, FileFilter, FilenameFilter)
with null filters. |
boolean |
moveDirectoryContent(int flags,
File fromDirectory,
File toDirectory,
FileFilter filter,
FilenameFilter nameFilter)
Moves a content (files + subdirectories) from the given fromDirectory into the given
toDirectory.
|
boolean |
moveFileContent(int flags,
File fromFile,
File toFile)
Moves a content from the given fromFile into the given toFile.
|
public static final int DEFAULT
public static final int OVERWRITE
public static final int COPY
COPY_SUFFIX.public static final int SMALL_BUFFER
createBuffer(int) method.
Size of buffer: 512 bytes
public static final int MEDIUM_BUFFER
createBuffer(int) method.
Size of buffer: 1024 bytes
public static final int LARGE_BUFFER
createBuffer(int) method.
Size of buffer: 2048 bytes
public static final int XLARGE_BUFFER
createBuffer(int) method.
Size of buffer: 4096 bytes
public static final int XXLARGE_BUFFER
createBuffer(int) method.
Size of buffer: 8192 bytes
public static final String COPY_SUFFIX
COPY flag to some
of this editor's methods accepting flags parameter.public static byte[] createBuffer(int bufferType)
bufferType - Type of buffer to create. One of SMALL_BUFFER, MEDIUM_BUFFER,
LARGE_BUFFER, XLARGE_BUFFER, XXLARGE_BUFFER.public boolean deleteDirectory(File directory)
deleteDirectory(File, FileFilter, FilenameFilter)
with null filters.public boolean deleteDirectory(File directory, FileFilter filter, FilenameFilter nameFilter)
directory - The desired directory to delete.filter - The filter used to delete only desired files form the requested directory.
Pass null to delete all files.nameFilter - The filter used to delete only files with desired names form the requested
directory. Pass null to delete all files.True if directory was successfully deleted, false otherwise.public boolean copyFileContent(File file) throws IOException
copyFileContent(int, File, File) with COPY flag and
null toFile parameter, so there will be created new copy of the given
file at the same path with COPY_SUFFIX.IOExceptionpublic boolean copyFileContent(int flags,
File fromFile,
File toFile)
throws IOException
flags - The flags used manage move process. See OVERWRITE, COPY.fromFile - The desired file of which content to copy.toFile - The desired file to which should be content of the requested file copied.True if file was successfully copied, false if some error
occurs during copy process or the given flags were not properly specified.FileNotFoundException - If the given fromFile doesn't exists or is not a file.IllegalArgumentException - If the given toFile is not a file but a directory.IOException - If some IO error occurs during copy process of the requested file.public boolean copyDirectoryContent(File directory) throws IOException
copyDirectoryContent(int, File, File) with COPY flag
and null toDirectory parameter, so there will be created new copy of
the given directory at the same path with COPY_SUFFIX.IOExceptionpublic boolean copyDirectoryContent(int flags,
File fromDirectory,
File toDirectory)
throws IOException
copyDirectoryContent(int, File, File, FileFilter, FilenameFilter)
with null filters.IOExceptionpublic boolean copyDirectoryContent(int flags,
File fromDirectory,
File toDirectory,
FileFilter filter,
FilenameFilter nameFilter)
throws IOException
flags - The flags used manage copy process. See OVERWRITE, COPY.fromDirectory - The desired directory of which content to copy.toDirectory - The desired directory to which should be content of the requested directory
copied.filter - The filter used to copy only desired files form the requested directory.
Pass null to copy all files.nameFilter - The filter used to copy only files with desired names form the requested
directory. Pass null to copy all files.True if directory was successfully copied, false if some error
occurs during copy process or the given flags were not properly specified.FileNotFoundException - If the given fromDirectory doesn't exists or is not a directory.IllegalArgumentException - If the given toDirectory is not a directory but a file.IOException - If some IO error occurs during copy process of the requested file.public boolean moveFileContent(int flags,
File fromFile,
File toFile)
throws IOException
This implementation actually moves content between the given files and than deletes the old one.
flags - The flags used manage move process. See OVERWRITE, COPY.fromFile - The desired file of which content to move.toFile - The desired file to which should be content of the requested file moved.True if file was successfully moved and old one deleted, false
if some error occurs during move process or the given flags were not properly specified.FileNotFoundException - If the given fromFile doesn't exists or is not a file.IllegalArgumentException - If the given toFile is not a file but a directory.IOException - If some IO error occurs during copy process of the requested file.public boolean moveDirectoryContent(int flags,
File fromDirectory,
File toDirectory)
throws IOException
moveDirectoryContent(int, File, File, FileFilter, FilenameFilter)
with null filters.IOExceptionpublic boolean moveDirectoryContent(int flags,
File fromDirectory,
File toDirectory,
FileFilter filter,
FilenameFilter nameFilter)
throws IOException
This implementation actually moves content between the given directories and than deletes the old one.
flags - The flags used manage move process. See OVERWRITE, COPY.fromDirectory - The desired directory of which content to move.toDirectory - The desired directory to which should be content of the requested directory
moved.filter - The filter used to move only desired files form the requested directory.
Pass null to move all files.nameFilter - The filter used to move only files with desired names form the requested
directory. Pass null to move all files.True if directory was successfully moved and old one deleted, false
if some error occurs during move process or the given flags were not properly specified.FileNotFoundException - If the given fromDirectory doesn't exists or is not a directory.IllegalArgumentException - If the given toDirectory is not a directory but a file.UnsupportedOperationExceptionIOException - If some IO error occurs during copy process of the requested file.public boolean copyFileStreams(FileInputStream inputStream, FileOutputStream outputStream) throws IOException
copyFileStreams(FileInputStream, FileOutputStream, int)
with MEDIUM_BUFFER type.IOExceptionpublic boolean copyFileStreams(FileInputStream inputStream, FileOutputStream outputStream, int bufferType) throws IOException
copyFileStreams(FileInputStream, FileOutputStream, byte[])
with buffer obtained from createBuffer(int) for the desired bufferType.IOExceptionpublic boolean copyFileStreams(FileInputStream inputStream, FileOutputStream outputStream, byte[] buffer) throws IOException
Note, that if the IOException occurs, the given streams will be not closed by this implementation, so it is your duty to close them in finally block of your try catch statement.
inputStream - The input stream of which content to copy.outputStream - The output stream where should be content copied.buffer - Buffer used for copy process. Larger buffer will make copy process faster,
but also more memory intensive.true if no IOException is thrown.IOException - If some input/output error occurs during copy process.