Deprecate functions taking charset name as string.

This commit is contained in:
Ilya Gorbunov
2015-12-21 05:17:33 +03:00
parent 68971e2162
commit ac15807ba4
6 changed files with 22 additions and 0 deletions
@@ -65,6 +65,7 @@ public fun booleanArrayOf(vararg elements: Boolean) : BooleanArray = elements
/**
* 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)
/**
@@ -69,6 +69,7 @@ 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)
/**
@@ -88,6 +89,7 @@ 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))
/**
@@ -113,6 +115,7 @@ 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))
/**
@@ -175,6 +178,7 @@ public fun File.forEachLine(charset: Charset = Charsets.UTF_8, operation: (line:
* @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)"))
public fun File.forEachLine(charset: String, operation: (line: String) -> Unit): Unit = forEachLine(Charset.forName(charset), operation)
/**
@@ -185,6 +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))"))
public fun File.readLines(charset: String): List<String> = readLines(Charset.forName(charset))
/**
@@ -72,9 +72,11 @@ 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))"))
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()
/**
@@ -91,9 +93,11 @@ 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))"))
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()
/**
@@ -116,6 +116,7 @@ public fun Reader.copyTo(out: Writer, bufferSize: Int = defaultBufferSize): Long
* @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)
/**
@@ -1,7 +1,15 @@
@file:JvmName("CharsetsKt")
package kotlin
import java.nio.charset.*
/**
* Returns a named charset with the given [charsetName] name.
*
* @throws UnsupportedCharsetException If the specified named charset is not available.
*/
public fun charset(charsetName: String): Charset = Charset.forName(charsetName)
/**
* Constant definitions for the standard [charsets](Charset). These
* charsets are guaranteed to be available on every implementation of the Java
@@ -181,6 +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))"))
public fun String(bytes: ByteArray, offset: Int, length: Int, charsetName: String): String = java.lang.String(bytes, offset, length, charsetName) as String
/**
@@ -198,6 +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))"))
public fun String(bytes: ByteArray, charsetName: String): String = java.lang.String(bytes, charsetName) as String
/**
@@ -410,6 +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))"))
public fun String.toByteArray(charset: String): ByteArray = (this as java.lang.String).getBytes(charset)
/**