fileutils
package fileutils
- Alphabetic
- By Inheritance
- fileutils
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
def
appendToFile(file: File, data: String): Unit
Appends text to file.
Appends text to file. Opens a new java.io.FileWriter on every call.
-
def
appendToFile(fileName: String, textData: String): Unit
Appends text to file.
Appends text to file. Opens a new java.io.FileWriter on every call.
-
def
cat(in: Iterable[File], out: File, header: Int = 0): Unit
Concatenates text files together, dropping header lines for each, except the first.
- def createSource(s: File)(implicit codec: Codec): BufferedSource
-
def
createSourceFromZippedFile(file: String, bufferSize: Int = io.Source.DefaultBufSize)(implicit codec: Codec): BufferedSource
Returns a scala.io.Source from the given GZipped file.
- def createSymbolicLink(from: File, to: File): File
-
def
exec(pb: ProcessBuilder, atMost: Duration = Duration.Inf, retries: Int = 0)(stdOutFunc: (String) ⇒ Unit = x: String =>)(implicit stdErrFunc: (String) ⇒ Unit = (x: String) => ()): Int
Execute command with user function to process each line of output.
Execute command with user function to process each line of output.
Based on from http://www.jroller.com/thebugslayer/entry/executing_external_system_commands_in Creates 3 new threads: one for the stdout, one for the stderror, and one waits for the exit code.
- pb
Description of the executable process
- atMost
Maximum time to wait for the process to complete. Default infinite.
- returns
Exit code of the process.
-
def
execGetStreamsAndCode(pb: ProcessBuilder, unsuccessfulOnErrorStream: Boolean = true, atMost: Duration = Duration.Inf, retries: Int = 0): (List[String], List[String], Boolean)
Execute command.
Execute command. Returns stdout and stderr as strings, and true if it was successful.
A process is considered successful if its exit code is 0 and the error stream is empty. The latter criterion can be disabled with the unsuccessfulOnErrorStream parameter.
- pb
The process description.
- unsuccessfulOnErrorStream
if true, then the process is considered as a failure if its stderr is not empty.
- atMost
max waiting time.
- returns
(stdout,stderr,success) triples
-
def
execGetStreamsAndCodeWithLog(pb: ProcessBuilder, unsuccessfulOnErrorStream: Boolean = true, atMost: Duration = Duration.Inf, retries: Int = 0)(implicit log: AnyRef { ... /* 2 definitions in type refinement */ }): (List[String], List[String], Boolean)
Execute command.
Execute command. Returns stdout and stderr as strings, and true if it was successful. Also writes to log.
A process is considered successful if its exit code is 0 and the error stream is empty. The latter criterion can be disabled with the unsuccessfulOnErrorStream parameter.
- pb
The process description.
- unsuccessfulOnErrorStream
if true, then the process is considered as a failure if its stderr is not empty.
- atMost
max waiting time.
- log
A logger.
- returns
(stdout,stderr,success) triples
-
def
fileIsEmpty(file: File): Boolean
Returns true if file is empty.
-
def
getFileReader(fileName: File): BufferedReader
Returns a java.io.BufferedReader.
-
def
getFileWriter(fileName: File, append: Boolean = false): BufferedWriter
Returns a java.io.BufferedWriter.
-
def
isGZipFile(file: File): Boolean
Returns true if the file is GZipped.
-
def
isGZipFile(file: String): Boolean
Returns true if the file is GZipped.
-
def
openFileInputStream[T](fileName: File)(func: (BufferedInputStream) ⇒ T): T
Opens a buffered java.io.BufferedInputStream on the file.
Opens a buffered java.io.BufferedInputStream on the file. Closes it after the block is executed.
- def openFileInputStreamMaybeZipped[T](file: File)(func: (InputStream) ⇒ T): T
-
def
openFileOutputStream[T](func: (BufferedOutputStream) ⇒ T): (File, T)
Opens a buffered java.io.BufferedOutputStream on the file.
Opens a buffered java.io.BufferedOutputStream on the file. Closes it after the block is executed.
-
def
openFileOutputStream[T](fileName: File, append: Boolean = false)(func: (BufferedOutputStream) ⇒ T): T
Opens a buffered java.io.BufferedOutputStream on the file.
Opens a buffered java.io.BufferedOutputStream on the file. Closes it after the block is executed.
-
def
openFileReader[T](fileName: File)(func: (BufferedReader) ⇒ T): T
Opens a buffered java.io.BufferedReader on the file.
Opens a buffered java.io.BufferedReader on the file. Closes it after the block is executed.
- def openFileWriter[T](func: (BufferedWriter) ⇒ T): (File, T)
-
def
openFileWriter[T](fileName: File, append: Boolean = false)(func: (BufferedWriter) ⇒ T): T
Opens a java.io.BufferedWriter on the file.
Opens a java.io.BufferedWriter on the file. Closes it after the block is executed.
-
def
openSource[A](s: File)(f: (Source) ⇒ A)(implicit codec: Codec): A
Opens a scala.io.Source, executes the block, then closes the source.
Opens a scala.io.Source, executes the block, then closes the source.
- s
Path of the file
-
def
openSource[A](s: String)(f: (Source) ⇒ A)(implicit codec: Codec): A
Opens a scala.io.Source, executes the block, then closes the source.
Opens a scala.io.Source, executes the block, then closes the source.
- s
Path of the file
-
def
openUnbufferedFileWriter[T](fileName: File, append: Boolean = false)(func: (Writer) ⇒ T): T
Opens an unbuffered java.io.Writer on the file.
Opens an unbuffered java.io.Writer on the file. Closes it after the block is executed.
-
def
openZippedFileInputStream[T](fileName: File)(func: (InputStream) ⇒ T): T
Opens a java.io.OutputStream which writes GZip compressed data to the given path.
Opens a java.io.OutputStream which writes GZip compressed data to the given path. Closes it after the block is executed.
- def openZippedFileOutputStream[T](func: (OutputStream) ⇒ T): (File, T)
-
def
openZippedFileOutputStream[T](fileName: File, append: Boolean = false)(func: (OutputStream) ⇒ T): T
Opens a java.io.OutputStream which writes GZip compressed data to the given path.
Opens a java.io.OutputStream which writes GZip compressed data to the given path. Closes it after the block is executed.
-
def
openZippedFileReader[T](fileName: File)(func: (BufferedReader) ⇒ T): T
Opens a java.io.BufferedReader on a GZipped file.
Opens a java.io.BufferedReader on a GZipped file. Closes it after the block is executed.
- def openZippedFileWriter[T](func: (Writer) ⇒ T): (File, T)
-
def
openZippedFileWriter[T](fileName: File, append: Boolean = false)(func: (Writer) ⇒ T): T
Opens a java.io.BufferedWriter which writes GZip compressed data to the given path.
Opens a java.io.BufferedWriter which writes GZip compressed data to the given path. Closes it after the block is executed.
-
def
putBesides(filesWithExtensions: (File, String)*): File
Creates symbolic links with the same basename but different extensions.
Creates symbolic links with the same basename but different extensions.
- filesWithExtensions
files with the needed extensions
- returns
A temporary File which points to the common part of the symbolic links paths.
-
def
readBinaryFile(f: File): Array[Byte]
Reads file contents into a bytearray.
-
def
readBinaryFile(fileName: String): Array[Byte]
Reads file contents into a bytearray.
-
def
readBinaryStream(f: InputStream): Array[Byte]
Reads file contents into a bytearray.
- def readLines(s: File): Vector[String]
- def readLines(s: String): Vector[String]
-
def
readStreamAndClose(is: InputStream): Iterator[Byte] { ... /* 2 definitions in type refinement */ }
Returns an iterator on the InputStream's data.
Returns an iterator on the InputStream's data.
Closes the stream when read through.
-
def
searchForFileInPath(fileName: String): Boolean
Searches $PATH for the specified file
- implicit def stringSeqToProcess(command: Seq[String]): ProcessBuilder
- implicit def stringToProcess(command: String): ProcessBuilder
-
def
useResource[A <: AnyRef { def close(): Unit }, B](param: A)(f: (A) ⇒ B): B
Returns the result of the block, and closes the resource.
Returns the result of the block, and closes the resource.
- param
closeable resource
- f
block using the resource
-
def
using[A <: AnyRef { def close(): Unit }, B]: (A) ⇒ ((A) ⇒ B) ⇒ B
Alias for useResource
-
def
writeBinaryToFile(file: File, data: Array[Byte]): Unit
Writes binary data to file.
-
def
writeBinaryToFile(fileName: String, data: Array[Byte]): Unit
Writes binary data to file.
- def writeBinaryToTempFile(data: Array[Byte]): File
-
def
writeByteBufferToFile(file: File, buff: ByteBuffer): Unit
Writes the ByteBuffer's contents to a file.
-
def
writeByteBufferToFile(fileName: String, buff: ByteBuffer): Unit
Writes the ByteBuffer's contents to a file.
-
def
writeToFile(file: File, data: String): Unit
Writes text data to file.
-
def
writeToFile(fileName: String, data: String): Unit
Writes text data to file.
- def writeToTempFile(data: String): File
- object TempFile