CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-kotlin--kotlin-stdlib-jdk7

Kotlin Standard Library JDK 7 extension providing Path utilities and platform-specific implementations for Java NIO and JDK 7+ features

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Kotlin Standard Library JDK 7 Extension

The Kotlin Standard Library JDK 7 extension provides comprehensive Path utilities using Java NIO APIs introduced in JDK 7 and higher. It offers a complete set of extension functions for java.nio.file.Path that enable idiomatic Kotlin file system operations, I/O, directory traversal, and more.

Package Information

  • Package Name: kotlin-stdlib-jdk7
  • Package Type: maven
  • Group ID: org.jetbrains.kotlin
  • Language: Kotlin
  • Installation: implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:2.2.0'

Note: The Java 9 module kotlin.stdlib.jdk7 is deprecated and empty. For Java 9+ module systems, use kotlin.stdlib instead which transitively includes this functionality.

Core Imports

import kotlin.io.path.*
import java.nio.file.Path
import java.nio.file.Paths

For specific functionality:

import kotlin.io.path.exists
import kotlin.io.path.createDirectories
import kotlin.io.path.readText
import kotlin.io.path.writeText
import kotlin.io.path.copyToRecursively
import kotlin.io.path.walk

Basic Usage

import kotlin.io.path.*
import java.nio.file.Paths

// Create and manipulate paths
val path = Paths.get("/home/user/documents/file.txt")
val filename = path.name                    // "file.txt"
val extension = path.extension              // "txt"
val parent = path.parent                    // Path to "/home/user/documents"

// Check file existence and properties
if (path.exists()) {
    println("File size: ${path.fileSize()} bytes")
    println("Is readable: ${path.isReadable()}")
    println("Is directory: ${path.isDirectory()}")
}

// Create directories and files
val newDir = Paths.get("/tmp/myapp")
newDir.createDirectories()

val configFile = newDir / "config.txt"
configFile.writeText("Setting=Value")

// Read and write files
val content = configFile.readText()
println("Config content: $content")

// List directory contents
newDir.listDirectoryEntries("*.txt").forEach { file ->
    println("Found text file: ${file.name}")
}

Architecture

The kotlin-stdlib-jdk7 extension is built around several key components:

  • Path Extensions: Extension properties and functions for java.nio.file.Path providing idiomatic Kotlin operations
  • File I/O Operations: Stream-based and convenience methods for reading/writing files with charset support
  • Directory Operations: Creation, listing, and traversal of directory structures
  • Tree Walking: Comprehensive directory tree traversal with multiple options (breadth/depth-first, link following)
  • Recursive Operations: Experimental APIs for recursive copying and deletion with error handling
  • Platform Implementations: JDK 7+ specific implementations including Android compatibility

Capabilities

Path Operations

Core path manipulation including resolution, relativization, and property access for robust file system navigation.

val Path.name: String
val Path.nameWithoutExtension: String
val Path.extension: String
val Path.pathString: String
val Path.invariantSeparatorsPathString: String

fun Path.absolute(): Path
fun Path.relativeTo(base: Path): Path
operator fun Path.div(other: Path): Path
operator fun Path.div(other: String): Path

fun Path(path: String): Path
fun Path(base: String, vararg subpaths: String): Path
fun URI.toPath(): Path

Path Operations

File System Operations

File and directory operations including existence checks, creation, deletion, copying, and attribute management.

fun Path.exists(vararg options: LinkOption): Boolean
fun Path.isDirectory(vararg options: LinkOption): Boolean
fun Path.isRegularFile(vararg options: LinkOption): Boolean

fun Path.createFile(vararg attributes: FileAttribute<*>): Path
fun Path.createDirectory(vararg attributes: FileAttribute<*>): Path
fun Path.createDirectories(vararg attributes: FileAttribute<*>): Path

fun Path.copyTo(target: Path, overwrite: Boolean = false): Path
fun Path.moveTo(target: Path, overwrite: Boolean = false): Path
fun Path.deleteExisting()
fun Path.deleteIfExists(): Boolean

fun Path.listDirectoryEntries(glob: String = "*"): List<Path>

File System Operations

File I/O Operations

Comprehensive file input/output operations including streams, readers/writers, and convenience methods for text and binary data.

fun Path.inputStream(vararg options: OpenOption): InputStream
fun Path.outputStream(vararg options: OpenOption): OutputStream
fun Path.reader(charset: Charset = Charsets.UTF_8, vararg options: OpenOption): InputStreamReader
fun Path.bufferedReader(charset: Charset = Charsets.UTF_8, bufferSize: Int = DEFAULT_BUFFER_SIZE, vararg options: OpenOption): BufferedReader

fun Path.readText(charset: Charset = Charsets.UTF_8): String
fun Path.writeText(text: CharSequence, charset: Charset = Charsets.UTF_8, vararg options: OpenOption)
fun Path.readBytes(): ByteArray
fun Path.writeBytes(array: ByteArray, vararg options: OpenOption)

fun Path.readLines(charset: Charset = Charsets.UTF_8): List<String>
fun Path.writeLines(lines: Iterable<CharSequence>, charset: Charset = Charsets.UTF_8, vararg options: OpenOption): Path

File I/O Operations

Tree Traversal Operations

Advanced directory tree traversal with walking sequences and customizable file visitor patterns for complex file operations.

fun Path.walk(vararg options: PathWalkOption): Sequence<Path>
fun Path.visitFileTree(visitor: FileVisitor<Path>, maxDepth: Int = Int.MAX_VALUE, followLinks: Boolean = false)
fun Path.visitFileTree(maxDepth: Int = Int.MAX_VALUE, followLinks: Boolean = false, builderAction: FileVisitorBuilder.() -> Unit)

fun fileVisitor(builderAction: FileVisitorBuilder.() -> Unit): FileVisitor<Path>

enum class PathWalkOption {
    INCLUDE_DIRECTORIES,
    BREADTH_FIRST, 
    FOLLOW_LINKS
}

Tree Traversal Operations

Recursive Operations

Experimental APIs for recursive file operations with comprehensive error handling and customizable behaviors.

@ExperimentalPathApi
fun Path.copyToRecursively(
    target: Path,
    onError: (source: Path, target: Path, exception: Exception) -> OnErrorResult = { _, _, exception -> throw exception },
    followLinks: Boolean,
    overwrite: Boolean
): Path

@ExperimentalPathApi
fun Path.deleteRecursively()

Recursive Operations

Types

@ExperimentalPathApi
annotation class ExperimentalPathApi

@SinceKotlin("2.1")
enum class PathWalkOption {
    INCLUDE_DIRECTORIES,
    BREADTH_FIRST,
    FOLLOW_LINKS
}

@ExperimentalPathApi
enum class OnErrorResult {
    SKIP_SUBTREE,
    TERMINATE
}

@ExperimentalPathApi
enum class CopyActionResult {
    CONTINUE,
    SKIP_SUBTREE,
    TERMINATE
}

@ExperimentalPathApi
interface CopyActionContext {
    fun Path.copyToIgnoringExistingDirectory(target: Path, followLinks: Boolean): CopyActionResult
}

@SinceKotlin("2.1")
interface FileVisitorBuilder {
    fun onPreVisitDirectory(function: (directory: Path, attributes: BasicFileAttributes) -> FileVisitResult)
    fun onVisitFile(function: (file: Path, attributes: BasicFileAttributes) -> FileVisitResult)
    fun onVisitFileFailed(function: (file: Path, exception: IOException) -> FileVisitResult)  
    fun onPostVisitDirectory(function: (directory: Path, exception: IOException?) -> FileVisitResult)
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.jetbrains.kotlin/kotlin-stdlib-jdk7@2.2.x
Publish Source
CLI
Badge
tessl/maven-org-jetbrains-kotlin--kotlin-stdlib-jdk7 badge