Package com.helger.io.file
Class FileChannelHelper
java.lang.Object
com.helger.io.file.FileChannelHelper
Miscellaneous
FileChannel utility methods.- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable FileChannelgetFileReadChannel(@NonNull File aFile) Get a read-onlyFileChannelfor the passed file.static @Nullable FileChannelgetFileReadChannel(@NonNull String sFilename) Get a read-onlyFileChannelfor the passed filename.static longgetFileSize(@Nullable FileChannel aChannel) Get the size of the file represented by the passed channel.static @Nullable FileChannelgetFileWriteChannel(@NonNull File aFile) Get a writableFileChannelfor the passed file using the default append mode.static @Nullable FileChannelgetFileWriteChannel(@NonNull File aFile, @NonNull com.helger.base.io.EAppend eAppend) Get a writableFileChannelfor the passed file.static @Nullable FileChannelgetFileWriteChannel(@NonNull String sFilename) Get a writableFileChannelfor the passed filename using the default append mode.static @Nullable FileChannelgetFileWriteChannel(@NonNull String sFilename, @NonNull com.helger.base.io.EAppend eAppend) Get a writableFileChannelfor the passed filename.static @Nullable InputStreamgetInputStream(@NonNull File aFile) Get an input stream for the passed file.static @Nullable InputStreamgetMappedInputStream(@NonNull File aFile) Get an input stream to the specified file, using memory mapping.static @Nullable OutputStreamgetMappedOutputStream(@NonNull File aFile) Get a memory-mapped output stream for the passed file using the default append mode.static @Nullable OutputStreamgetMappedOutputStream(@NonNull File aFile, @NonNull com.helger.base.io.EAppend eAppend) Get a memory-mapped output stream for the passed file.static @Nullable OutputStreamgetMappedOutputStream(@NonNull String sFilename) Get a memory-mapped output stream for the passed filename using the default append mode.static @Nullable OutputStreamgetMappedOutputStream(@NonNull String sFilename, @NonNull com.helger.base.io.EAppend eAppend) Get a memory-mapped output stream for the passed filename.
-
Method Details
-
getFileSize
Get the size of the file represented by the passed channel.- Parameters:
aChannel- The file channel to get the size of. May benull.- Returns:
- The file size in bytes, or -1 if the channel is
nullor an I/O error occurred.
-
getInputStream
Get an input stream for the passed file. If the file is larger than 1 MB, a memory-mapped input stream is used; otherwise a regularFileInputStreamis returned.- Parameters:
aFile- The file to read. May not benull.- Returns:
nullif the file does not exist or cannot be opened.
-
getFileReadChannel
Get a read-onlyFileChannelfor the passed filename.- Parameters:
sFilename- The name of the file to open. May not benull.- Returns:
nullif the file could not be opened.
-
getFileReadChannel
Get a read-onlyFileChannelfor the passed file.- Parameters:
aFile- The file to open. May not benull.- Returns:
nullif the file could not be opened.
-
getMappedInputStream
Get an input stream to the specified file, using memory mapping. If memory mapping fails, a regularFileInputStreamis returned.- Parameters:
aFile- The file to use. May not benull.- Returns:
- The Input stream to use.
-
getFileWriteChannel
Get a writableFileChannelfor the passed filename using the default append mode.- Parameters:
sFilename- The name of the file to open. May not benull.- Returns:
nullif the file could not be opened.
-
getFileWriteChannel
public static @Nullable FileChannel getFileWriteChannel(@NonNull String sFilename, @NonNull com.helger.base.io.EAppend eAppend) Get a writableFileChannelfor the passed filename.- Parameters:
sFilename- The name of the file to open. May not benull.eAppend- Appending mode. May not benull.- Returns:
nullif the file could not be opened.
-
getFileWriteChannel
Get a writableFileChannelfor the passed file using the default append mode.- Parameters:
aFile- The file to open. May not benull.- Returns:
nullif the file could not be opened.
-
getFileWriteChannel
public static @Nullable FileChannel getFileWriteChannel(@NonNull File aFile, @NonNull com.helger.base.io.EAppend eAppend) Get a writableFileChannelfor the passed file.- Parameters:
aFile- The file to open. May not benull.eAppend- Appending mode. May not benull.- Returns:
nullif the file could not be opened.
-
getMappedOutputStream
Get a memory-mapped output stream for the passed filename using the default append mode.- Parameters:
sFilename- The name of the file to open. May not benull.- Returns:
nullif the file could not be opened or mapped.
-
getMappedOutputStream
public static @Nullable OutputStream getMappedOutputStream(@NonNull String sFilename, @NonNull com.helger.base.io.EAppend eAppend) Get a memory-mapped output stream for the passed filename.- Parameters:
sFilename- The name of the file to open. May not benull.eAppend- Appending mode. May not benull.- Returns:
nullif the file could not be opened or mapped.
-
getMappedOutputStream
Get a memory-mapped output stream for the passed file using the default append mode.- Parameters:
aFile- The file to open. May not benull.- Returns:
nullif the file could not be opened or mapped.
-
getMappedOutputStream
public static @Nullable OutputStream getMappedOutputStream(@NonNull File aFile, @NonNull com.helger.base.io.EAppend eAppend) Get a memory-mapped output stream for the passed file. If memory mapping fails, a regularFileOutputStreamis returned as a fallback.- Parameters:
aFile- The file to open. May not benull.eAppend- Appending mode. May not benull.- Returns:
nullif the file could not be opened.
-