Minor: code formatting
This commit is contained in:
@@ -2,9 +2,7 @@ package kotlin.io
|
||||
|
||||
import java.io.*
|
||||
import java.nio.charset.*
|
||||
import java.util.NoSuchElementException
|
||||
import java.util.ArrayList
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,15 +51,14 @@ public val File.extension: String
|
||||
val idx = text.lastIndexOf('.')
|
||||
return if (idx >= 0) {
|
||||
text.substring(idx + 1)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given file is in the same directory or a descendant directory
|
||||
*/
|
||||
* Returns true if the given file is in the same directory or a descendant directory
|
||||
*/
|
||||
public fun File.isDescendant(file: File): Boolean {
|
||||
return file.directory.canonicalPath.startsWith(this.directory.canonicalPath)
|
||||
}
|
||||
@@ -107,7 +104,7 @@ public fun File.writeBytes(data: ByteArray): Unit {
|
||||
* Appends bytes to the contents of the file.
|
||||
*/
|
||||
public fun File.appendBytes(data: ByteArray): Unit {
|
||||
return FileOutputStream(this, true).use { it.write(data) }
|
||||
return FileOutputStream(this, true).use { it.write(data) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,25 +112,29 @@ public fun File.appendBytes(data: ByteArray): Unit {
|
||||
*
|
||||
* This method is not recommended on huge files.
|
||||
*/
|
||||
public fun File.readText(encoding:String = Charset.defaultCharset().name()) : String = readBytes().toString(encoding)
|
||||
public fun File.readText(encoding: String = Charset.defaultCharset().name()): String = readBytes().toString(encoding)
|
||||
|
||||
/**
|
||||
* Reads the entire content of the file as a String using a character encoding.
|
||||
*
|
||||
* This method is not recommended on huge files.
|
||||
*/
|
||||
public fun File.readText(encoding: Charset) : String = readBytes().toString(encoding)
|
||||
public fun File.readText(encoding: Charset): String = readBytes().toString(encoding)
|
||||
|
||||
/**
|
||||
* Writes the text as the contents of the file using the a
|
||||
* character encoding.
|
||||
*/
|
||||
public fun File.writeText(text: String, encoding: String = Charset.defaultCharset().name()): Unit { writeBytes(text.toByteArray(encoding)) }
|
||||
public fun File.writeText(text: String, encoding: String = Charset.defaultCharset().name()): Unit {
|
||||
writeBytes(text.toByteArray(encoding))
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the text as the contents of the file using a character encoding.
|
||||
*/
|
||||
public fun File.writeText(text: String, encoding: Charset): Unit { writeBytes(text.toByteArray(encoding)) }
|
||||
public fun File.writeText(text: String, encoding: Charset): Unit {
|
||||
writeBytes(text.toByteArray(encoding))
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends text to the contents of the file using a given character encoding.
|
||||
@@ -155,9 +156,9 @@ public fun File.appendText(text: String, encoding: String = Charset.defaultChars
|
||||
public fun File.copyTo(file: File, bufferSize: Int = defaultBufferSize): Long {
|
||||
file.directory.mkdirs()
|
||||
val input = FileInputStream(this)
|
||||
return input.use<FileInputStream,Long>{
|
||||
return input.use<FileInputStream, Long>{
|
||||
val output = FileOutputStream(file)
|
||||
output.use<FileOutputStream,Long>{
|
||||
output.use<FileOutputStream, Long>{
|
||||
input.copyTo(output, bufferSize)
|
||||
}
|
||||
}
|
||||
@@ -181,7 +182,7 @@ public fun File.forEachBlock(closure: (ByteArray, Int) -> Unit): Unit {
|
||||
} else if (size > 0) {
|
||||
closure(arr, size)
|
||||
}
|
||||
} while(true)
|
||||
} while (true)
|
||||
} finally {
|
||||
fis.close()
|
||||
}
|
||||
@@ -209,7 +210,7 @@ public fun File.forEachLine(charset: String = "UTF-8", closure: (line: String) -
|
||||
public fun File.readLines(charset: String = "UTF-8"): List<String> {
|
||||
val rs = ArrayList<String>()
|
||||
|
||||
this.forEachLine(charset) { (line : String) : Unit ->
|
||||
this.forEachLine(charset) {(line: String): Unit ->
|
||||
rs.add(line);
|
||||
}
|
||||
|
||||
@@ -220,7 +221,7 @@ public fun File.readLines(charset: String = "UTF-8"): List<String> {
|
||||
* Returns an array of files and directories in the directory that satisfy the specified filter.
|
||||
*/
|
||||
public fun File.listFiles(filter: (file: File) -> Boolean): Array<File>? = listFiles(
|
||||
object : FileFilter {
|
||||
override fun accept(file: File) = filter(file)
|
||||
}
|
||||
)
|
||||
object : FileFilter {
|
||||
override fun accept(file: File) = filter(file)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user