package io
Various io-related helper methods and classes.
- Source
- package.scala
- Note
The implementations of the methods rely on Java NIO(2).
- Alphabetic
- By Inheritance
- io
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- class FailAfterByteArrayOutputStream extends ByteArrayOutputStream
A
java.io.ByteArrayOutputStream
that throws anIOException
after writing some bytes, if the given boundary (failAfter
) is surpassed. - case class OpeningFileFailedException(file: File, cause: Throwable) extends Exception with Product with Serializable
Exception that is thrown if the OS cannot/does not know how/is not able to open the respective file.
Value Members
- def open(file: File): Unit
- def process[C <: Closeable, T](closable: C)(r: (C) => T): T
This function takes a
Closeable
resource and a functionr
that will process theCloseable
resource.This function takes a
Closeable
resource and a functionr
that will process theCloseable
resource. This function takes care of the correct handling ofCloseable
resources. Whenr
has finished processing the resource or throws an exception, the resource is closed.- closable
The
Closeable
resource.- r
The function that processes the
resource
.
- Note
If
closable
isnull
,null
is passed tor
.
- def processSource[C <: Source, T](source: C)(r: (C) => T): T
This function takes a
Source
object and a functionr
that will process the source.This function takes a
Source
object and a functionr
that will process the source. This function takes care of the correct handling of resources. Whenr
has finished processing the source or throws an exception, the source is closed.- Note
If
source
isnull
,null
is passed tor
.
- def sanitizeFileName(fileName: String): String
Replaces characters in the given file name (segment) that are (potentially) problematic on some file system and also shortens the filename
Replaces characters in the given file name (segment) that are (potentially) problematic on some file system and also shortens the filename
- fileName
The filename or a suffix/prefix thereof which should be sanitized.
- returns
The sanitized file name.
- See also
For more information visit https://en.wikipedia.org/wiki/Filename
- def write(data: IterableOnce[Array[Byte]], path: Path): Unit
- def write(data: Array[Byte], path: Path): Unit
A simple wrapper for
java.nio.Files.write(Path,byte[])
. - def write(data: IterableOnce[String], filenamePrefix: String, filenameSuffix: String): Path
- def write(data: String, filenamePrefix: String, filenameSuffix: String): Path
- def writeAndOpen(data: String, filenamePrefix: String, filenameSuffix: String): File
Writes the given string (
data
) to a temporary file using the given prefix and suffix.Writes the given string (
data
) to a temporary file using the given prefix and suffix. Afterwards the system's native application that claims to be able to handle files with the given suffix is opened. If this fails, the string is printed to the console.The string is always written using UTF-8 as the encoding.
- filenamePrefix
A string the identifies the content of the file. (E.g., "ClassHierarchy" or "CHACallGraph")
- filenameSuffix
The suffix of the file that identifies the used file format. (E.g., ".txt")
- returns
The name of the file if it was possible to write the file and open the native application.
- Annotations
- @throws("if it is not possible to create a temporary file") @throws("if it is not possible to open the file")
Exemplary usage:
try { util.writeAndOpen("The Message", "Result", ".txt") } catch { case OpeningFileFailedException(file, _) => Console.err.println("Details can be found in: "+file.toString)
Example: - def writeAndOpen(node: Node, filenamePrefix: String, filenameSuffix: String): File
Writes the XML document to a temporary file and opens the file in the OS's default application.
Writes the XML document to a temporary file and opens the file in the OS's default application.
- filenamePrefix
A string the identifies the content of the file. (E.g., "ClassHierarchy" or "CHACallGraph")
- filenameSuffix
The suffix of the file that identifies the used file format. (E.g., ".xhtml")
- returns
The name of the file if it was possible to write the file and open the native application.
- Annotations
- @throws("if it is not possible to create a temporary file") @throws("if it is not possible to open the file")
- def writeGZip(data: IterableOnce[Array[Byte]], path: Path): Unit
- def writeGZip(data: Array[Byte], path: Path): Unit
- def writeGZip(data: IterableOnce[String], filenamePrefix: String, filenameSuffix: String): Path
- def writeGZip(data: String, filenamePrefix: String, filenameSuffix: String): Path
- object JARsFileFilter extends FileFilter