PathMethods
Provides extension methods for java.nio.file.Path
.
- See also:
FileMethods
Value members
Concrete methods
Appends contents of supplied InputStream to file.
Appends contents of supplied InputStream to file.
- Returns:
path
Appends contents of supplied Reader to file.
Appends contents of supplied Reader to file.
- Returns:
path
Appends supplied source to file.
Appends supplied source to file.
- Returns:
path
- Throws:
- IOException
if source is same as target
Filters lines in file using supplied predicate.
Filters lines in file using supplied predicate.
- Value parameters:
- p
predicate
Builds collection using elements mapped from files in directory.
Builds collection using elements mapped from files in directory.
- Value parameters:
- f
function
- Throws:
- java.io.IOException
if path is not to a directory
Builds collection using elements mapped from lines in file.
Builds collection using elements mapped from lines in file.
- Value parameters:
- f
function
Folds files in directory to single value using given initial value and binary operator.
Folds files in directory to single value using given initial value and binary operator.
- Value parameters:
- init
initial value
- op
binary operator
- Returns:
init
if no files; otherwise, last value returned fromop
- Throws:
- java.io.IOException
if path is not to a directory
Folds lines in file to single value using given initial value and binary operator.
Folds lines in file to single value using given initial value and binary operator.
- Value parameters:
- init
initial value
- op
binary operator
- Returns:
init
if file is empty; otherwise, last value returned fromop
Opens directory stream to path and invokes supplied function for each file in directory.
Opens directory stream to path and invokes supplied function for each file in directory.
- Value parameters:
- f
function
- Throws:
- java.io.IOException
if path is not to a directory
Reads file at path and invokes supplied function for each line.
Reads file at path and invokes supplied function for each line.
The line content, excluding line separator, is passed to function.
- Value parameters:
- f
function
Invokes supplied function for each file in directory satisfying glob.
Invokes supplied function for each file in directory satisfying glob.
- Value parameters:
- f
function
- glob
glob pattern
- Throws:
- java.io.IOException
if path is not to a directory
Maps each file in directory using supplied function.
Maps each file in directory using supplied function.
- Value parameters:
- f
function
- Throws:
- java.io.IOException
if path is not to a directory
Maps each line in file using supplied function.
Maps each line in file using supplied function.
- Value parameters:
- f
function
Opens FileChannel to file at path and passes it to supplied function. Channel is closed on function's return.
Opens FileChannel to file at path and passes it to supplied function. Channel is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function
Opens DataInput to file at path and passes it to supplied function. Underlying input stream is closed on function's return.
Opens DataInput to file at path and passes it to supplied function. Underlying input stream is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function
Opens DataOutput to file at path and passes it to supplied function. Underlying output stream is closed on function's return.
Opens DataOutput to file at path and passes it to supplied function. Underlying output stream is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function
Opens InputStream to file at path and passes it to supplied function. Input stream is closed on function's return.
Opens InputStream to file at path and passes it to supplied function. Input stream is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function
Opens OutputStream to file at path and passes it to supplied function. Output stream is closed on function's return.
Opens OutputStream to file at path and passes it to supplied function. Output stream is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function
Opens PrintWriter to file at path and passes it to supplied function. Writer is closed on function's return.
Opens PrintWriter to file at path and passes it to supplied function. Writer is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function
Opens BufferedReader to file at path and passes it to supplied function. Reader is closed on function's return.
Opens BufferedReader to file at path and passes it to supplied function. Reader is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function
Walks file tree starting at path and invokes supplied visitor function for each event encountered.
Walks file tree starting at path and invokes supplied visitor function for each event encountered.
If supplied visitor does not handle an event, then it is treated as if
it returned FileVisitResult.CONTINUE
.
import java.nio.file.{ FileVisitResult, Paths }
import little.io.FileVisitEvent.{ PreVisitDirectory, VisitFile }
import little.io.PathMethods
val sourceDir = Paths.get("src")
sourceDir.withVisitor {
case PreVisitDirectory(dir, attrs) =>
if dir.getFileName.toString == "test" then
FileVisitResult.SKIP_SUBTREE
else
println(s"Listing files in ${dir.getFileName} directory...")
FileVisitResult.CONTINUE
case VisitFile(file, attrs) =>
println(s"${file.getFileName} is ${attrs.size} bytes.")
FileVisitResult.CONTINUE
}
- Value parameters:
- visitor
file visitor
Watchs file at path for specified events.
Watchs file at path for specified events.
- Value parameters:
- events
kinds of events to watch
- watcher
event watcher
- Returns:
watch handle
Opens BufferedWriter to file at path and passes it to supplied function. Writer is closed on function's return.
Opens BufferedWriter to file at path and passes it to supplied function. Writer is closed on function's return.
- Value parameters:
- f
function
- options
open options
- Returns:
value from supplied function