diff --git a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt index 67855076eb7..bcadb2ff368 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/debugger/KotlinDebuggerTestBase.kt @@ -406,7 +406,7 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() { val sourceFiles = runReadAction { FilenameIndex.getAllFilesByExt(project, "kt").filter { it.name.contains(fileName) && - it.contentsToByteArray().toString("UTF-8").contains(lineMarker) + it.contentsToByteArray().toString(Charsets.UTF_8).contains(lineMarker) } } diff --git a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt index 3fa4a51e6bc..47bbb87b1f9 100644 --- a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt +++ b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt @@ -9,8 +9,8 @@ import java.nio.charset.Charset /** * Converts the contents of this byte array to a string using the specified [charset]. */ -@Deprecated("Use ByteArray.toString(Charset) instead.", ReplaceWith("this.toString(charset(charset))")) -public fun ByteArray.toString(charset: String): String = String(this, charset) +@Deprecated("Use ByteArray.toString(Charset) instead.", ReplaceWith("this.toString(charset(charset))"), level = DeprecationLevel.ERROR) +public fun ByteArray.toString(charset: String): String = String(this, charset(charset)) /** * Converts the contents of this byte array to a string using the specified [charset]. diff --git a/libraries/stdlib/src/kotlin/io/FileReadWrite.kt b/libraries/stdlib/src/kotlin/io/FileReadWrite.kt index a25db96f5b2..4bd25f047de 100644 --- a/libraries/stdlib/src/kotlin/io/FileReadWrite.kt +++ b/libraries/stdlib/src/kotlin/io/FileReadWrite.kt @@ -69,8 +69,8 @@ public fun File.appendBytes(array: ByteArray): Unit = FileOutputStream(this, tru * @param charset character set to use. * @return the entire content of this file as a String. */ -@Deprecated("Use File.readText(Charset) instead.", ReplaceWith("this.readText(charset(charset))")) -public fun File.readText(charset: String): String = readBytes().toString(charset) +@Deprecated("Use File.readText(Charset) instead.", ReplaceWith("this.readText(charset(charset))"), level = DeprecationLevel.ERROR) +public fun File.readText(charset: String): String = readBytes().toString(charset(charset)) /** * Gets the entire content of this file as a String using UTF-8 or specified [charset]. @@ -89,8 +89,8 @@ public fun File.readText(charset: Charset = Charsets.UTF_8): String = readBytes( * @param text text to write into file. * @param charset character set to use. */ -@Deprecated("Use File.writeText(String, Charset) instead.", ReplaceWith("this.writeText(text, charset(charset))")) -public fun File.writeText(text: String, charset: String): Unit = writeBytes(text.toByteArray(charset)) +@Deprecated("Use File.writeText(String, Charset) instead.", ReplaceWith("this.writeText(text, charset(charset))"), level = DeprecationLevel.ERROR) +public fun File.writeText(text: String, charset: String): Unit = writeBytes(text.toByteArray(charset(charset))) /** * Sets the content of this file as [text] encoded using UTF-8 or specified [charset]. @@ -115,8 +115,8 @@ public fun File.appendText(text: String, charset: Charset = Charsets.UTF_8): Uni * @param text text to append to file. * @param charset character set to use. */ -@Deprecated("Use File.appendText(String, Charset) instead.", ReplaceWith("this.appendText(text, charset(charset))")) -public fun File.appendText(text: String, charset: String): Unit = appendBytes(text.toByteArray(charset)) +@Deprecated("Use File.appendText(String, Charset) instead.", ReplaceWith("this.appendText(text, charset(charset))"), level = DeprecationLevel.ERROR) +public fun File.appendText(text: String, charset: String): Unit = appendBytes(text.toByteArray(charset(charset))) /** * Reads file by byte blocks and calls [action] for each block read. @@ -178,7 +178,7 @@ public fun File.forEachLine(charset: Charset = Charsets.UTF_8, action: (line: St * @param charset character set to use. * @param operation function to process file lines. */ -@Deprecated("Use File.forEachLine(Charset, operation) instead.", ReplaceWith("this.forEachLine(charset(charset), operation)")) +@Deprecated("Use File.forEachLine(Charset, operation) instead.", ReplaceWith("this.forEachLine(charset(charset), operation)"), level = DeprecationLevel.ERROR) public fun File.forEachLine(charset: String, operation: (line: String) -> Unit): Unit = forEachLine(Charset.forName(charset), operation) /** @@ -189,7 +189,7 @@ public fun File.forEachLine(charset: String, operation: (line: String) -> Unit): * @param charset character set to use. * @return list of file lines. */ -@Deprecated("Use File.readLines(Charset) instead.", ReplaceWith("this.readLines(charset(charset))")) +@Deprecated("Use File.readLines(Charset) instead.", ReplaceWith("this.readLines(charset(charset))"), level = DeprecationLevel.ERROR) public fun File.readLines(charset: String): List = readLines(Charset.forName(charset)) /** diff --git a/libraries/stdlib/src/kotlin/io/IOStreams.kt b/libraries/stdlib/src/kotlin/io/IOStreams.kt index 2e94e7ae5bc..a2603d42d5d 100644 --- a/libraries/stdlib/src/kotlin/io/IOStreams.kt +++ b/libraries/stdlib/src/kotlin/io/IOStreams.kt @@ -69,12 +69,12 @@ public fun InputStream.reader(charset: Charset = Charsets.UTF_8): InputStreamRea public fun InputStream.bufferedReader(charset: Charset = Charsets.UTF_8): BufferedReader = reader(charset).buffered() /** Creates a reader on this input stream using the specified [charset]. */ -@Deprecated("Use InputStream.reader(Charset) instead.", ReplaceWith("this.reader(charset(charset))")) +@Deprecated("Use InputStream.reader(Charset) instead.", ReplaceWith("this.reader(charset(charset))"), level = DeprecationLevel.ERROR) public fun InputStream.reader(charset: String): InputStreamReader = InputStreamReader(this, charset) /** Creates a buffered reader on this input stream using the specified [charset]. */ -@Deprecated("Use InputStream.bufferedReader(Charset) instead.", ReplaceWith("this.bufferedReader(charset(charset))")) -public fun InputStream.bufferedReader(charset: String): BufferedReader = reader(charset).buffered() +@Deprecated("Use InputStream.bufferedReader(Charset) instead.", ReplaceWith("this.bufferedReader(charset(charset))"), level = DeprecationLevel.ERROR) +public fun InputStream.bufferedReader(charset: String): BufferedReader = reader(charset(charset)).buffered() /** * Creates a buffered output stream wrapping this stream. @@ -90,12 +90,12 @@ public fun OutputStream.writer(charset: Charset = Charsets.UTF_8): OutputStreamW public fun OutputStream.bufferedWriter(charset: Charset = Charsets.UTF_8): BufferedWriter = writer(charset).buffered() /** Creates a writer on this output stream using the specified [charset]. */ -@Deprecated("Use OutputStream.writer(Charset) instead.", ReplaceWith("this.writer(charset(charset))")) +@Deprecated("Use OutputStream.writer(Charset) instead.", ReplaceWith("this.writer(charset(charset))"), level = DeprecationLevel.ERROR) public fun OutputStream.writer(charset: String): OutputStreamWriter = OutputStreamWriter(this, charset) /** Creates a buffered writer on this output stream using the specified [charset]. */ -@Deprecated("Use OutputStream.bufferedWriter(Charset) instead.", ReplaceWith("this.bufferedWriter(charset(charset))")) -public fun OutputStream.bufferedWriter(charset: String): BufferedWriter = writer(charset).buffered() +@Deprecated("Use OutputStream.bufferedWriter(Charset) instead.", ReplaceWith("this.bufferedWriter(charset(charset))"), level = DeprecationLevel.ERROR) +public fun OutputStream.bufferedWriter(charset: String): BufferedWriter = writer(charset(charset)).buffered() /** * Copies this stream to the given output stream, returning the number of bytes copied diff --git a/libraries/stdlib/src/kotlin/io/ReadWrite.kt b/libraries/stdlib/src/kotlin/io/ReadWrite.kt index c5c410b72df..b2bb58d93a1 100644 --- a/libraries/stdlib/src/kotlin/io/ReadWrite.kt +++ b/libraries/stdlib/src/kotlin/io/ReadWrite.kt @@ -127,8 +127,8 @@ public fun Reader.copyTo(out: Writer, bufferSize: Int = DEFAULT_BUFFER_SIZE): Lo * @param charset a character set to use. * @return a string with this URL entire content. */ -@Deprecated("Use URL.readText(Charset) instead.", ReplaceWith("this.readText(charset(charset))")) -public fun URL.readText(charset: String): String = readBytes().toString(charset) +@Deprecated("Use URL.readText(Charset) instead.", ReplaceWith("this.readText(charset(charset))"), level = DeprecationLevel.ERROR) +public fun URL.readText(charset: String): String = readBytes().toString(charset(charset)) /** * Reads the entire content of this URL as a String using UTF-8 or the specified [charset]. diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index a2eb4e6ceba..f817560cedb 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -181,7 +181,7 @@ public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean * @param length the number of bytes to be converted. * @param charsetName the name of the character set to use. */ -@Deprecated("Use String(bytes, offset, length, Charset) instead.", ReplaceWith("String(bytes, offset, length, charset(charsetName))")) +@Deprecated("Use String(bytes, offset, length, Charset) instead.", ReplaceWith("String(bytes, offset, length, charset(charsetName))"), level = DeprecationLevel.ERROR) public fun String(bytes: ByteArray, offset: Int, length: Int, charsetName: String): String = java.lang.String(bytes, offset, length, charsetName) as String /** @@ -199,7 +199,7 @@ public fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): * Converts the data from the specified array of bytes to characters using the specified character set * and returns the conversion result as a string. */ -@Deprecated("Use String(bytes, Charset) instead.", ReplaceWith("String(bytes, charset(charsetName))")) +@Deprecated("Use String(bytes, Charset) instead.", ReplaceWith("String(bytes, charset(charsetName))"), level = DeprecationLevel.ERROR) public fun String(bytes: ByteArray, charsetName: String): String = java.lang.String(bytes, charsetName) as String /** @@ -412,7 +412,7 @@ public operator fun CharSequence.get(start: Int, end: Int): CharSequence = subSe /** * Encodes the contents of this string using the specified character set and returns the resulting byte array. */ -@Deprecated("Use String.toByteArray(Charset) instead.", ReplaceWith("this.toByteArray(charset(charset))")) +@Deprecated("Use String.toByteArray(Charset) instead.", ReplaceWith("this.toByteArray(charset(charset))"), level = DeprecationLevel.ERROR) public fun String.toByteArray(charset: String): ByteArray = (this as java.lang.String).getBytes(charset) /** diff --git a/libraries/stdlib/test/io/Files.kt b/libraries/stdlib/test/io/Files.kt index 1229b2a01c2..82b2b776855 100644 --- a/libraries/stdlib/test/io/Files.kt +++ b/libraries/stdlib/test/io/Files.kt @@ -352,19 +352,19 @@ class FilesTest { @test fun testCopyTo() { val srcFile = createTempFile() val dstFile = createTempFile() - srcFile.writeText("Hello, World!", "UTF8") + srcFile.writeText("Hello, World!") assertFailsWith(FileAlreadyExistsException::class) { srcFile.copyTo(dstFile) } var len = srcFile.copyTo(dstFile, overwrite = true) assertEquals(13L, len) - assertEquals(srcFile.readText(), dstFile.readText("UTF8")) + assertEquals(srcFile.readText(), dstFile.readText(Charsets.UTF_8)) assertTrue(dstFile.delete()) len = srcFile.copyTo(dstFile) assertEquals(13L, len) - assertEquals(srcFile.readText("UTF8"), dstFile.readText()) + assertEquals(srcFile.readText(Charsets.UTF_8), dstFile.readText()) assertTrue(dstFile.delete()) dstFile.mkdir() @@ -395,7 +395,7 @@ class FilesTest { val srcFile = createTempFile() val dstFile = createTempFile(directory = currentDir) try { - srcFile.writeText("Hello, World!", "UTF8") + srcFile.writeText("Hello, World!", Charsets.UTF_8) dstFile.delete() val dstRelative = File(dstFile.name) diff --git a/libraries/stdlib/test/io/ReadWrite.kt b/libraries/stdlib/test/io/ReadWrite.kt index 2cd09ebb14a..4351ce2ec66 100644 --- a/libraries/stdlib/test/io/ReadWrite.kt +++ b/libraries/stdlib/test/io/ReadWrite.kt @@ -15,12 +15,12 @@ fun sample(): Reader = StringReader("Hello\nWorld"); class ReadWriteTest { @test fun testAppendText() { val file = File.createTempFile("temp", System.nanoTime().toString()) - file.writeText("Hello\n", "UTF8") - file.appendText("World\n", "UTF8") + file.writeText("Hello\n") + file.appendText("World\n") file.appendText("Again") assertEquals("Hello\nWorld\nAgain", file.readText()) - assertEquals(listOf("Hello", "World", "Again"), file.readLines("UTF8")) + assertEquals(listOf("Hello", "World", "Again"), file.readLines(Charsets.UTF_8)) file.deleteOnExit() } @@ -145,7 +145,7 @@ class ReadWriteTest { val url = URL("http://kotlinlang.org") val text = url.readText() assertFalse(text.isEmpty()) - val text2 = url.readText("UTF8") + val text2 = url.readText(charset("UTF8")) assertFalse(text2.isEmpty()) } } diff --git a/libraries/stdlib/test/text/StringJVMTest.kt b/libraries/stdlib/test/text/StringJVMTest.kt index 53fdbfc74cc..a4d90116807 100644 --- a/libraries/stdlib/test/text/StringJVMTest.kt +++ b/libraries/stdlib/test/text/StringJVMTest.kt @@ -74,10 +74,8 @@ class StringJVMTest { } @test fun toByteArrayEncodings() { - val s = "hello" - val defaultCharset = java.nio.charset.Charset.defaultCharset()!! - assertEquals(String(s.toByteArray()), String(s.toByteArray(defaultCharset))) - assertEquals(String(s.toByteArray()), String(s.toByteArray(defaultCharset.name()))) + val s = "hello®" + assertEquals(String(s.toByteArray()), String(s.toByteArray(Charsets.UTF_8))) } @test fun toCharArray() {