Added @NotNull annotation for Charset.defaultCharset().
Other code cleanup.
This commit is contained in:
@@ -138,5 +138,8 @@
|
||||
<item name="java.nio.charset.UnmappableCharacterException java.lang.String getMessage()">
|
||||
<annotation name="org.jetbrains.annotations.NotNull"/>
|
||||
</item>
|
||||
<item name="java.nio.charset.Charset java.nio.charset.Charset defaultCharset()">
|
||||
<annotation name="org.jetbrains.annotations.NotNull"/>
|
||||
</item>
|
||||
</root>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
import java.util.LinkedList
|
||||
import java.nio.charset.Charset
|
||||
|
||||
public inline fun String.lastIndexOf(str: String) : Int = (this as java.lang.String).lastIndexOf(str)
|
||||
|
||||
@@ -62,11 +63,11 @@ public inline fun String.endsWith(ch: Char) : Boolean = (this as java.lang.Strin
|
||||
|
||||
public inline fun String(bytes : ByteArray, offset : Int, length : Int, charsetName : String) : String = java.lang.String(bytes, offset, length, charsetName) as String
|
||||
|
||||
public inline fun String(bytes : ByteArray, offset : Int, length : Int, charset : java.nio.charset.Charset) : String = java.lang.String(bytes, offset, length, charset) as String
|
||||
public inline fun String(bytes : ByteArray, offset : Int, length : Int, charset : Charset) : String = java.lang.String(bytes, offset, length, charset) as String
|
||||
|
||||
public inline fun String(bytes : ByteArray, charsetName : String) : String = java.lang.String(bytes, charsetName) as String
|
||||
|
||||
public inline fun String(bytes : ByteArray, charset : java.nio.charset.Charset) : String = java.lang.String(bytes, charset) as String
|
||||
public inline fun String(bytes : ByteArray, charset : Charset) : String = java.lang.String(bytes, charset) as String
|
||||
|
||||
public inline fun String(bytes : ByteArray, i : Int, i1 : Int) : String = java.lang.String(bytes, i, i1) as String
|
||||
|
||||
@@ -98,7 +99,7 @@ public inline fun String.contentEquals(cs : CharSequence) : Boolean = (this as j
|
||||
|
||||
public inline fun String.contentEquals(sb : StringBuffer) : Boolean = (this as java.lang.String).contentEquals(sb)
|
||||
|
||||
public inline fun String.getBytes(charset : java.nio.charset.Charset) : ByteArray = (this as java.lang.String).getBytes(charset)
|
||||
public inline fun String.getBytes(charset : Charset) : ByteArray = (this as java.lang.String).getBytes(charset)
|
||||
|
||||
public inline fun String.getBytes(charsetName : String) : ByteArray = (this as java.lang.String).getBytes(charsetName)
|
||||
|
||||
@@ -146,8 +147,8 @@ 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 String.toByteArray(encoding: String = java.nio.charset.Charset.defaultCharset()!!.name()):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: String = Charset.defaultCharset().name()): ByteArray = (this as java.lang.String).getBytes(encoding)
|
||||
public inline fun String.toByteArray(encoding: Charset): ByteArray = (this as java.lang.String).getBytes(encoding)
|
||||
|
||||
public inline fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this)
|
||||
public inline fun String.toShort() : Short = java.lang.Short.parseShort(this)
|
||||
|
||||
@@ -114,25 +114,25 @@ public fun File.appendBytes(data: ByteArray): Unit {
|
||||
*
|
||||
* This method is not recommended on huge files.
|
||||
*/
|
||||
public fun File.readText(encoding:String = java.nio.charset.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 = java.nio.charset.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.
|
||||
@@ -144,7 +144,7 @@ public fun File.appendText(text: String, encoding: Charset): Unit {
|
||||
/**
|
||||
* Appends text to the contents of the file using a character encoding.
|
||||
*/
|
||||
public fun File.appendText(text: String, encoding: String = java.nio.charset.Charset.defaultCharset()!!.name()): Unit {
|
||||
public fun File.appendText(text: String, encoding: String = Charset.defaultCharset().name()): Unit {
|
||||
appendBytes(text.toByteArray(encoding))
|
||||
}
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ public fun Reader.copyTo(out: Writer, bufferSize: Int = defaultBufferSize): Long
|
||||
*
|
||||
* This method is not recommended on huge files.
|
||||
*/
|
||||
public fun URL.readText(encoding: String = java.nio.charset.Charset.defaultCharset()!!.name()): String = readBytes().toString(encoding)
|
||||
public fun URL.readText(encoding: String = Charset.defaultCharset().name()): String = readBytes().toString(encoding)
|
||||
|
||||
/**
|
||||
* Reads the entire content of the URL as a String with the specified character encoding.
|
||||
|
||||
Reference in New Issue
Block a user