Use default param to String encoding name instead of using extra overloaded method.
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
c3b46341d7
commit
f7099a5b6a
@@ -146,8 +146,7 @@ public inline fun CharSequence.toString() : String? = (this as java.lang.CharSeq
|
|||||||
public inline fun CharSequence.length() : Int = (this as java.lang.CharSequence).length()
|
public inline fun CharSequence.length() : Int = (this as java.lang.CharSequence).length()
|
||||||
|
|
||||||
|
|
||||||
public inline fun String.toByteArray():ByteArray = (this as java.lang.String).getBytes()
|
public inline fun String.toByteArray(encoding: String = java.nio.charset.Charset.defaultCharset()!!.name()):ByteArray = (this as java.lang.String).getBytes(encoding)
|
||||||
public inline fun String.toByteArray(encoding: String):ByteArray = (this as java.lang.String).getBytes(encoding)
|
|
||||||
public inline fun String.toByteArray(encoding: java.nio.charset.Charset):ByteArray = (this as java.lang.String).getBytes(encoding)
|
public inline fun String.toByteArray(encoding: java.nio.charset.Charset):ByteArray = (this as java.lang.String).getBytes(encoding)
|
||||||
|
|
||||||
public inline fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this)
|
public inline fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this)
|
||||||
|
|||||||
@@ -114,15 +114,7 @@ public fun File.appendBytes(data: ByteArray): Unit {
|
|||||||
*
|
*
|
||||||
* This method is not recommended on huge files.
|
* This method is not recommended on huge files.
|
||||||
*/
|
*/
|
||||||
public fun File.readText(encoding:String) : String = readBytes().toString(encoding)
|
public fun File.readText(encoding:String = java.nio.charset.Charset.defaultCharset()!!.name()) : String = readBytes().toString(encoding)
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the entire content of the file as a String using the default platform
|
|
||||||
* character encoding.
|
|
||||||
*
|
|
||||||
* This method is not recommended on huge files.
|
|
||||||
*/
|
|
||||||
public fun File.readText() : String = readBytes().toString()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the entire content of the file as a String using a character encoding.
|
* Reads the entire content of the file as a String using a character encoding.
|
||||||
@@ -135,13 +127,7 @@ public fun File.readText(encoding:Charset) : String = readBytes().toString(encod
|
|||||||
* Writes the text as the contents of the file using the a
|
* Writes the text as the contents of the file using the a
|
||||||
* character encoding.
|
* character encoding.
|
||||||
*/
|
*/
|
||||||
public fun File.writeText(text: String, encoding:String): Unit { writeBytes(text.toByteArray(encoding)) }
|
public fun File.writeText(text: String, encoding:String = java.nio.charset.Charset.defaultCharset()!!.name()): Unit { writeBytes(text.toByteArray(encoding)) }
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes the text as the contents of the file using the default platform
|
|
||||||
* character encoding.
|
|
||||||
*/
|
|
||||||
public fun File.writeText(text: String): Unit { writeBytes(text.toByteArray()) }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the text as the contents of the file using a character encoding.
|
* Writes the text as the contents of the file using a character encoding.
|
||||||
@@ -158,17 +144,10 @@ public fun File.appendText(text: String, encoding: Charset): Unit {
|
|||||||
/**
|
/**
|
||||||
* Appends text to the contents of the file using a character encoding.
|
* Appends text to the contents of the file using a character encoding.
|
||||||
*/
|
*/
|
||||||
public fun File.appendText(text: String, encoding: String): Unit {
|
public fun File.appendText(text: String, encoding: String = java.nio.charset.Charset.defaultCharset()!!.name()): Unit {
|
||||||
appendBytes(text.toByteArray(encoding))
|
appendBytes(text.toByteArray(encoding))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends text to the contents of the file using default platform character encoding.
|
|
||||||
*/
|
|
||||||
public fun File.appendText(text: String): Unit {
|
|
||||||
appendBytes(text.toByteArray())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies this file to the given output file, returning the number of bytes copied
|
* Copies this file to the given output file, returning the number of bytes copied
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -319,14 +319,7 @@ public fun Reader.copyTo(out: Writer, bufferSize: Int = defaultBufferSize): Long
|
|||||||
*
|
*
|
||||||
* This method is not recommended on huge files.
|
* This method is not recommended on huge files.
|
||||||
*/
|
*/
|
||||||
public fun URL.readText(encoding: String): String = readBytes().toString(encoding)
|
public fun URL.readText(encoding: String = java.nio.charset.Charset.defaultCharset()!!.name()): String = readBytes().toString(encoding)
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the entire content of the URL as a String with default character set name
|
|
||||||
*
|
|
||||||
* This method is not recommended on huge files.
|
|
||||||
*/
|
|
||||||
public fun URL.readText(): String = readBytes().toString()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the entire content of the URL as a String with the specified character encoding.
|
* Reads the entire content of the URL as a String with the specified character encoding.
|
||||||
|
|||||||
Reference in New Issue
Block a user