Skip to content

Commit

Permalink
Deprecate IOUtils, replacing it with extensions.
Browse files Browse the repository at this point in the history
Change name of next version.

Signed-off-by: Julien Guerinet <julien@guerinet.com>
  • Loading branch information
jguerinet committed Apr 14, 2018
1 parent 9fa2bee commit f04911e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
43 changes: 43 additions & 0 deletions io/src/main/java/com/guerinet/suitcase/io/ContextExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2016-2018 Julien Guerinet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.guerinet.suitcase.io

import android.content.Context
import android.support.annotation.RawRes
import okio.BufferedSource
import okio.Okio
import java.io.IOException

/**
* Context extensions for IO operations
* @author Julien Guerinet
* @since 2.4.0
*/

/**
* Returns a [BufferedSource] for a file with the given [fileId] within the raw folder
*/
fun Context.sourceFromRaw(@RawRes fileId: Int): BufferedSource =
Okio.buffer(Okio.source(resources.openRawResource(fileId)))

/**
* Attempts to read and return a String from a file with the given [fileId] within the raw folder.
* Throws an [IOException] if there was an error during the read
*/
@Throws(IOException::class)
fun Context.stringFromRaw(@RawRes fileId: Int): String =
sourceFromRaw(fileId).readUtf8()
15 changes: 6 additions & 9 deletions io/src/main/java/com/guerinet/suitcase/io/IOUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 Julien Guerinet
* Copyright 2016-2018 Julien Guerinet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,25 +18,23 @@ package com.guerinet.suitcase.io

import android.content.Context
import android.support.annotation.RawRes
import okio.BufferedSource
import okio.Okio
import java.io.IOException

/**
* Static utility methods for any IO operations
* @author Julien Guerinet
* @since 2.0.0
*/
@Deprecated("Replaced with extensions")
object IOUtils {

/**
* @return A BufferedSource for a file with the given [fileId] in the raw folder, using the app
* [context]
*/
@JvmStatic
fun sourceFromRaw(context: Context, @RawRes fileId: Int): BufferedSource {
return Okio.buffer(Okio.source(context.resources.openRawResource(fileId)))
}
@Deprecated("Replaced with extension", ReplaceWith("context.sourceFromRaw(fileId)"))
fun sourceFromRaw(context: Context, @RawRes fileId: Int) = context.sourceFromRaw(fileId)

/**
* @return A String for a file with the given [fileId] in the raw folder, using the app
Expand All @@ -45,7 +43,6 @@ object IOUtils {
*/
@Throws(IOException::class)
@JvmStatic
fun stringFromRaw(context: Context, @RawRes fileId: Int): String {
return sourceFromRaw(context, fileId).readUtf8()
}
@Deprecated("Replaced with extension", ReplaceWith("context.stringFromRaw(fileId)"))
fun stringFromRaw(context: Context, @RawRes fileId: Int) = context.stringFromRaw(fileId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.support.v4.app.ActivityCompat
/**
* [Activity] extensions
* @author Julien Guerinet
* @since 2.3.2
* @since 2.4.0
*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.net.ConnectivityManager
/**
* [ConnectivityManager] extensions
* @author Julien Guerinet
* @since 2.3.2
* @since 2.4.0
*/

/**
Expand Down

0 comments on commit f04911e

Please sign in to comment.