|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.io.IOUtils
it.geosolutions.tools.io.file.IOUtils
public final class IOUtils
Assorted IO related utilities
Field Summary | |
---|---|
static String |
FILE_SEPARATOR
|
static long |
MAX_WAITING_TIME_FOR_LOCK
The max time the node will wait for, prior to stop to attempt for acquiring a lock on a File . |
Fields inherited from class org.apache.commons.io.IOUtils |
---|
DIR_SEPARATOR, DIR_SEPARATOR_UNIX, DIR_SEPARATOR_WINDOWS, LINE_SEPARATOR, LINE_SEPARATOR_UNIX, LINE_SEPARATOR_WINDOWS |
Method Summary | |
---|---|
static boolean |
acquireLock(Object caller,
File inputFile)
This method is responsible for checking if the input file is still being written or if its available for being parsed. |
static boolean |
acquireLock(Object caller,
File inputFile,
long maxwait)
This method is responsible for checking if the input file is still being written or if its available for being parsed. |
static void |
closeQuietly(Channel channel)
Close the specified input FileChannel |
static void |
copyChannel(int bufferSize,
ReadableByteChannel source,
WritableByteChannel destination)
Copies the content of the source channel onto the destination channel. |
static void |
copyFileChannel(int bufferSize,
FileChannel source,
FileChannel destination)
Optimize version of copy method for file channels. |
static void |
copyStream(InputStream sourceStream,
OutputStream destinationStream,
boolean closeInput,
boolean closeOutput)
Copy InputStream to OutputStream . |
static void |
copyStream(InputStream sourceStream,
OutputStream destinationStream,
int size,
boolean closeInput,
boolean closeOutput)
Copy InputStream to OutputStream . |
static File |
createTodayDirectory(File destDir)
Create a subDirectory having the actual date as name, within a specified destination directory. |
Methods inherited from class org.apache.commons.io.IOUtils |
---|
closeQuietly, closeQuietly, closeQuietly, closeQuietly, closeQuietly, closeQuietly, contentEquals, contentEquals, copy, copy, copy, copy, copy, copy, copyLarge, copyLarge, lineIterator, lineIterator, readLines, readLines, readLines, skip, skip, skipFully, skipFully, toBufferedInputStream, toByteArray, toByteArray, toByteArray, toByteArray, toByteArray, toByteArray, toCharArray, toCharArray, toCharArray, toInputStream, toInputStream, toInputStream, toInputStream, toString, toString, toString, toString, toString, toString, toString, toString, toString, write, write, write, write, write, write, write, write, write, write, write, write, write, write, write, writeLines, writeLines, writeLines |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long MAX_WAITING_TIME_FOR_LOCK
File
.
public static final String FILE_SEPARATOR
Method Detail |
---|
public static void copyChannel(int bufferSize, ReadableByteChannel source, WritableByteChannel destination) throws IOException
bufferSize
- size of the temp buffer to use for this copy.source
- the source ReadableByteChannel
.destination
- the destination WritableByteChannel
;.
IOException
- in case something bad happens.public static void copyFileChannel(int bufferSize, FileChannel source, FileChannel destination) throws IOException
bufferSize
- size of the temp buffer to use for this copy.source
- the source ReadableByteChannel
.destination
- the destination WritableByteChannel
;.
IOException
- in case something bad happens.public static void closeQuietly(Channel channel) throws IOException
FileChannel
IOException
- in case something bad happens.public static boolean acquireLock(Object caller, File inputFile) throws InterruptedException, IOException
Specifically this method tries to open up a "rw" channel on the provided
input file. If the file is still being written this operation fails with
an exception, we therefore catch this exception and sleep for
seconds as defined in the constant
#ATOMIC_WAIT
.
If after having waited for MAX_WAITING_TIME_FOR_LOCK
(which is
read from the configuration or set to the default value of
#DEFAULT_WAITING_TIME
) we have not yet acquired the channel we
skip this file but we signal this situation.
inputFile
-
true
if the lock has been successfully acquired.
false
otherwise
InterruptedException
IOException
public static void copyStream(InputStream sourceStream, OutputStream destinationStream, boolean closeInput, boolean closeOutput) throws IOException
InputStream
to OutputStream
.
sourceStream
- InputStream
to copy from.destinationStream
- OutputStream
to copy to.closeInput
- quietly close InputStream
.closeOutput
- quietly close OutputStream
IOException
- in case something bad happens.public static void copyStream(InputStream sourceStream, OutputStream destinationStream, int size, boolean closeInput, boolean closeOutput) throws IOException
InputStream
to OutputStream
.
sourceStream
- InputStream
to copy from.destinationStream
- OutputStream
to copy to.size
- size of the buffer to use internally.closeInput
- quietly close InputStream
.closeOutput
- quietly close OutputStream
IOException
- in case something bad happens.public static File createTodayDirectory(File destDir)
destDir
- the destination directory where to build the "today"
directory.
public static boolean acquireLock(Object caller, File inputFile, long maxwait) throws InterruptedException, IOException
Specifically this method tries to open up a "rw" channel on the provided
input file. If the file is still being written this operation fails with
an exception, we therefore catch this exception and sleep for
seconds as defined in the constant
#ATOMIC_WAIT
.
If after having waited for MAX_WAITING_TIME_FOR_LOCK
(which is
read from the configuration or set to the default value of
#DEFAULT_WAITING_TIME
) we have not yet acquired the channel we
skip this file but we signal this situation.
NOTE: To make use of mandatory locks, mandatory locking must be enabled
both on the file system that contains the file to be locked, and on the
file itself. Mandatory locking is enabled on a file system using the
"-o mand" option to mount(8), or the MS_MANDLOCK flag for mount(2).
Mandatory locking is enabled on a file by disabling group execute
permission on the file and enabling the set-group-ID permission bit (see
chmod(1) and chmod(2)).
caller
- inputFile
- maxwait
-
true
if the lock has been successfully acquired.
false
otherwise
InterruptedException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |