Created
February 10, 2016 10:55
-
-
Save gtomek/72e0c1b4198f76ea90f5 to your computer and use it in GitHub Desktop.
Read files with Okio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Utils for I/O operations. | |
* <p/> | |
* Created by Tomek on 09/06/15. | |
*/ | |
public class IoUtils { | |
/** | |
* Reads file and returns a String. | |
* | |
* @param file | |
* @throws IOException | |
*/ | |
public static String readFile(File file) throws IOException { | |
BufferedSource source = Okio.buffer(FileSystem.SYSTEM.source(file)); | |
String result = source.readUtf8(); | |
source.close(); | |
return result; | |
} | |
/** | |
* Reads InputStream and returns a String. | |
* | |
* @param file | |
* @throws IOException | |
*/ | |
public static String readFile(InputStream stream) throws IOException { | |
BufferedSource source = Okio.buffer(Okio.source(stream)); | |
String result = source.readUtf8(); | |
source.close(); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, i little bit improved this util, see https://gist.github.com/ultraon/c6397dfb23de2f260f81e6946ad5adc2