Class XIO
- java.lang.Object
-
- one.microstream.io.XIO
-
public final class XIO extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXIO.unchecked
-
Constructor Summary
Constructors Constructor Description XIO()
-
Method Summary
Modifier and Type Method Description static longappendAll(FileChannel fileChannel, ByteBuffer[] byteBuffers)Sets the passedFileChannel's position to its current length and repeatedly callsFileChannel.write(ByteBuffer[])until the last non-empty buffer has no remaining bytes.
This is necessary because JDK'sFileChannel.write(ByteBuffer[])seems to arbitrarily stop processing the passedByteBuffers even though they have remaining bytes left to be written.static longappendAllGuaranteed(FileChannel fileChannel, ByteBuffer[] byteBuffers)CallsappendAll(FileChannel,ByteBuffer[]), thenFileChannel.force(boolean), then validates if the actual new file size is really exactely what it should be based on old file size and the amount of bytes written.static StringbuildFilePath(String... items)static <C extends Closeable>
Cclose(C closable, Throwable suppressed)static booleandelete(Path path)static ByteBufferdetermineLastNonEmpty(ByteBuffer[] byteBuffers)static <P extends Path>
PensureDirectory(P directory)static <P extends Path>
PensureDirectoryAndFile(P file)static <P extends Path>
PensureFile(P file)static StringensureNormalizedPathSeperators(String path)static StringensureTrailingSlash(String path)static <P extends Path>
PensureWriteableFile(P file)static booleanexists(Path path)static StringgetFileName(Path file)static StringgetFilePath(Path file)Providing only the abused moreless debug-information method #toString is a horrible misconception since it conveys no clear message which string is desired.static booleanhasNoFiles(Path directory)static booleanisDirectory(Path path)static <C extends Consumer<? super Path>>
CiterateEntries(Path directory, C logic)Warning: this (because of using Files.newDirectoryStream) does some weird file opening/locking stuff.static <C extends Consumer<? super Path>>
CiterateEntries(Path directory, C logic, Predicate<? super Path> selector)Warning: this (because of using Files.newDirectoryStream) does some weird file opening/locking stuff.static longlastModified(Path file)static Path[]listEntries(Path directory)static <C extends XAddingCollection<? super Path>>
ClistEntries(Path directory, C target)static <C extends XAddingCollection<? super Path>>
ClistEntries(Path directory, C target, Predicate<? super Path> selector)static Path[]listEntries(Path directory, Predicate<? super Path> selector)static voidmergeBinary(Iterable<Path> sourceFiles, Path targetFile)static voidmergeBinary(Iterable<Path> sourceFiles, Path targetFile, Predicate<? super Path> selector)static voidmove(Path sourceFile, Path targetFile)static FileChannelopenFileChannelReading(Path file)static FileChannelopenFileChannelReading(Path file, OpenOption... options)static FileChannelopenFileChannelRW(Path file)static FileChannelopenFileChannelRW(Path file, OpenOption... options)static FileChannelopenFileChannelWriting(Path file)static FileChannelopenFileChannelWriting(Path file, OpenOption... options)static PathPath(String path)static PathPath(String... items)static PathPath(Path parent, String... items)static <T> TperformClosingOperation(FileChannel fileChannel, IoOperationSR<FileChannel,T> operation)static ByteBufferread(FileChannel fileChannel)static ByteBufferread(FileChannel fileChannel, long filePosition, long length)static longread(FileChannel fileChannel, ByteBuffer targetBuffer)static longread(FileChannel fileChannel, ByteBuffer targetBuffer, long filePosition, long length)static ByteBufferread(Path file)static byte[]read_bytes(Path file)static <T> TreadOneShot(Path file, IoOperationSR<FileChannel,T> operation)static StringreadString(String filePath)Extreme convenience method.static StringreadString(String filePath, Charset charSet)Extreme convenience method.static StringreadString(Path file)static StringreadString(Path file, Charset charSet)static StringtoAbsoluteNormalizedPath(Path file)static voidunchecked(IoOperation operation)static <T> Tunchecked(IoOperationR<T> operation)static <S> voidunchecked(IoOperationS<S> operation, S subject)static <S,R>
Runchecked(IoOperationSR<S,R> operation, S subject)static ByteBufferwrapInDirectByteBuffer(byte[] bytes)static longwrite(FileChannel fileChannel, ByteBuffer buffer)static longwrite(Path file, byte[] bytes)static longwrite(Path file, String string)static longwrite(Path file, String string, Charset charset)static longwrite(Path file, ByteBuffer buffer)static longwriteAppending(FileChannel fileChannel, ByteBuffer buffer)static longwriteAppending(Path file, byte[] bytes)static longwriteAppending(Path file, String string)static longwriteAppending(Path file, String string, Charset charset)static longwriteAppending(Path file, ByteBuffer buffer)static <T> TwriteOneShot(Path file, IoOperationSR<FileChannel,T> operation)static longwritePositioned(FileChannel fileChannel, long filePosition, ByteBuffer buffer)static longwritePositioned(Path file, long filePosition, byte[] bytes)static longwritePositioned(Path file, long filePosition, String string)static longwritePositioned(Path file, long filePosition, String string, Charset charset)static longwritePositioned(Path file, long filePosition, ByteBuffer buffer)
-
-
-
Method Detail
-
unchecked
public static void unchecked(IoOperation operation) throws IORuntimeException
- Throws:
IORuntimeException
-
unchecked
public static <T> T unchecked(IoOperationR<T> operation) throws IORuntimeException
- Throws:
IORuntimeException
-
unchecked
public static <S> void unchecked(IoOperationS<S> operation, S subject) throws IORuntimeException
- Throws:
IORuntimeException
-
unchecked
public static <S,R> R unchecked(IoOperationSR<S,R> operation, S subject) throws IORuntimeException
- Throws:
IORuntimeException
-
close
public static final <C extends Closeable> C close(C closable, Throwable suppressed) throws IOException
- Throws:
IOException
-
close
public static final <C extends AutoCloseable> C close(C closable, Throwable suppressed) throws Exception
- Throws:
Exception
-
ensureNormalizedPathSeperators
public static final String ensureNormalizedPathSeperators(String path)
-
Path
public static final Path Path(Path parent, String... items)
Creates a sub-path under the passedparentPathinside the sameFileSystem.Note that this is fundamentally different to
Path(String...)orPaths.get(String,String...)since those two end up usingFileSystems.getDefault(), no matter theFileSystemthat the passed parentPathis associated with.
-
getFilePath
public static String getFilePath(Path file)
Providing only the abused moreless debug-information method #toString is a horrible misconception since it conveys no clear message which string is desired. Why are the JDK guys so horribly bad at designing clean Java code structure? Why?- Parameters:
file-- Returns:
-
isDirectory
public static boolean isDirectory(Path path) throws IOException
- Throws:
IOException
-
exists
public static boolean exists(Path path) throws IOException
- Throws:
IOException
-
delete
public static final boolean delete(Path path) throws IOException
- Throws:
IOException
-
listEntries
public static Path[] listEntries(Path directory) throws IOException
- Throws:
IOException
-
listEntries
public static Path[] listEntries(Path directory, Predicate<? super Path> selector) throws IOException
- Throws:
IOException
-
listEntries
public static <C extends XAddingCollection<? super Path>> C listEntries(Path directory, C target) throws IOException
- Throws:
IOException
-
listEntries
public static <C extends XAddingCollection<? super Path>> C listEntries(Path directory, C target, Predicate<? super Path> selector) throws IOException
- Throws:
IOException
-
iterateEntries
public static <C extends Consumer<? super Path>> C iterateEntries(Path directory, C logic) throws IOException
Warning: this (because of using Files.newDirectoryStream) does some weird file opening/locking stuff.Also see: https://stackoverflow.com/questions/48311252/a-bit-strange-behaviour-of-files-delete-and-files-deleteifexists
- Type Parameters:
C-- Parameters:
directory-logic-- Returns:
- Throws:
IOException
-
iterateEntries
public static <C extends Consumer<? super Path>> C iterateEntries(Path directory, C logic, Predicate<? super Path> selector) throws IOException
Warning: this (because of using Files.newDirectoryStream) does some weird file opening/locking stuff.Also see: https://stackoverflow.com/questions/48311252/a-bit-strange-behaviour-of-files-delete-and-files-deleteifexists
- Type Parameters:
C-- Parameters:
directory-logic-selector-- Returns:
- Throws:
IOException
-
hasNoFiles
public static boolean hasNoFiles(Path directory) throws IOException
- Throws:
IOException
-
lastModified
public static final long lastModified(Path file) throws IOException
- Throws:
IOException
-
ensureDirectory
public static final <P extends Path> P ensureDirectory(P directory) throws IOException
- Throws:
IOException
-
ensureDirectoryAndFile
public static final <P extends Path> P ensureDirectoryAndFile(P file) throws IOException
- Throws:
IOException
-
ensureFile
public static final <P extends Path> P ensureFile(P file) throws IOException
- Throws:
IOException
-
ensureWriteableFile
public static final <P extends Path> P ensureWriteableFile(P file) throws IOException, FilePathException
- Throws:
IOExceptionFilePathException
-
openFileChannelReading
public static FileChannel openFileChannelReading(Path file) throws IOException
- Throws:
IOException
-
openFileChannelWriting
public static FileChannel openFileChannelWriting(Path file) throws IOException
- Throws:
IOException
-
openFileChannelRW
public static FileChannel openFileChannelRW(Path file) throws IOException
- Throws:
IOException
-
openFileChannelReading
public static FileChannel openFileChannelReading(Path file, OpenOption... options) throws IOException
- Throws:
IOException
-
openFileChannelWriting
public static FileChannel openFileChannelWriting(Path file, OpenOption... options) throws IOException
- Throws:
IOException
-
openFileChannelRW
public static FileChannel openFileChannelRW(Path file, OpenOption... options) throws IOException
- Throws:
IOException
-
readOneShot
public static final <T> T readOneShot(Path file, IoOperationSR<FileChannel,T> operation) throws IOException
- Throws:
IOException
-
readString
public static String readString(String filePath) throws IOException
Extreme convenience method. Normally, methods handling files should not accept file path strings, but only properly typed file instances likePath. However, for a convenience method, there is not much safety won writingreadString(Path("./my/path/myFile.txt")), only verbosity.
So when already using a convenience method, anyway, why not make it really convienent and accept file path strings right away?- Parameters:
filePath-- Returns:
- Throws:
IOException
-
readString
public static String readString(String filePath, Charset charSet) throws IOException
Extreme convenience method. Normally, methods handling files should not accept file path strings, but only properly typed file instances likePath. However, for a convenience method, there is not much safety won writingreadString(Path("./my/path/myFile.txt")), only verbosity.
So when already using a convenience method, anyway, why not make it really convienent and accept file path strings right away?- Parameters:
filePath-charSet-- Returns:
- Throws:
IOException
-
readString
public static String readString(Path file) throws IOException
- Throws:
IOException
-
readString
public static String readString(Path file, Charset charSet) throws IOException
- Throws:
IOException
-
read_bytes
public static byte[] read_bytes(Path file) throws IOException
- Throws:
IOException
-
read
public static ByteBuffer read(Path file) throws IOException
- Throws:
IOException
-
writeOneShot
public static final <T> T writeOneShot(Path file, IoOperationSR<FileChannel,T> operation) throws IOException
- Throws:
IOException
-
write
public static final long write(Path file, String string) throws IOException
- Throws:
IOException
-
write
public static final long write(Path file, String string, Charset charset) throws IOException
- Throws:
IOException
-
write
public static final long write(Path file, byte[] bytes) throws IOException
- Throws:
IOException
-
write
public static long write(Path file, ByteBuffer buffer) throws IOException
- Throws:
IOException
-
writePositioned
public static final long writePositioned(Path file, long filePosition, String string) throws IOException
- Throws:
IOException
-
writePositioned
public static final long writePositioned(Path file, long filePosition, String string, Charset charset) throws IOException
- Throws:
IOException
-
writePositioned
public static final long writePositioned(Path file, long filePosition, byte[] bytes) throws IOException
- Throws:
IOException
-
writePositioned
public static long writePositioned(Path file, long filePosition, ByteBuffer buffer) throws IOException
- Throws:
IOException
-
writeAppending
public static final long writeAppending(Path file, String string) throws IOException
- Throws:
IOException
-
writeAppending
public static final long writeAppending(Path file, String string, Charset charset) throws IOException
- Throws:
IOException
-
writeAppending
public static final long writeAppending(Path file, byte[] bytes) throws IOException
- Throws:
IOException
-
writeAppending
public static long writeAppending(Path file, ByteBuffer buffer) throws IOException
- Throws:
IOException
-
mergeBinary
public static final void mergeBinary(Iterable<Path> sourceFiles, Path targetFile, Predicate<? super Path> selector)
-
move
public static void move(Path sourceFile, Path targetFile) throws IOException, RuntimeException
- Throws:
IOExceptionRuntimeException
-
determineLastNonEmpty
public static ByteBuffer determineLastNonEmpty(ByteBuffer[] byteBuffers)
-
wrapInDirectByteBuffer
public static final ByteBuffer wrapInDirectByteBuffer(byte[] bytes) throws IOException
- Throws:
IOException
-
appendAll
public static long appendAll(FileChannel fileChannel, ByteBuffer[] byteBuffers) throws IOException
Sets the passedFileChannel's position to its current length and repeatedly callsFileChannel.write(ByteBuffer[])until the last non-empty buffer has no remaining bytes.
This is necessary because JDK'sFileChannel.write(ByteBuffer[])seems to arbitrarily stop processing the passedByteBuffers even though they have remaining bytes left to be written.The reason for this behavior is unknown, but looking at countless other issues in the JDK code, one might guess... .
- Parameters:
fileChannel-byteBuffers-- Throws:
IOException
-
appendAllGuaranteed
public static long appendAllGuaranteed(FileChannel fileChannel, ByteBuffer[] byteBuffers) throws IOException
CallsappendAll(FileChannel,ByteBuffer[]), thenFileChannel.force(boolean), then validates if the actual new file size is really exactely what it should be based on old file size and the amount of bytes written.In short: this method "guarantees" that every byte contained in the passed
ByteBuffers was appended to the passedFileChanneland actually reached the physical file.- Parameters:
fileChannel-byteBuffers-- Throws:
IOException
-
writeAppending
public static long writeAppending(FileChannel fileChannel, ByteBuffer buffer) throws IOException
- Throws:
IOException
-
writePositioned
public static long writePositioned(FileChannel fileChannel, long filePosition, ByteBuffer buffer) throws IOException
- Throws:
IOException
-
write
public static long write(FileChannel fileChannel, ByteBuffer buffer) throws IOException
- Throws:
IOException
-
performClosingOperation
public static final <T> T performClosingOperation(FileChannel fileChannel, IoOperationSR<FileChannel,T> operation) throws IOException
- Throws:
IOException
-
read
public static ByteBuffer read(FileChannel fileChannel) throws IOException
- Throws:
IOException
-
read
public static ByteBuffer read(FileChannel fileChannel, long filePosition, long length) throws IOException
- Throws:
IOException
-
read
public static long read(FileChannel fileChannel, ByteBuffer targetBuffer) throws IOException
- Throws:
IOException
-
read
public static long read(FileChannel fileChannel, ByteBuffer targetBuffer, long filePosition, long length) throws IOException
- Throws:
IOException
-
-