Skip to content

Instantly share code, notes, and snippets.

@thuytrinh
Last active September 21, 2018 13:56
Show Gist options
  • Select an option

  • Save thuytrinh/cb79bc9e156d0cdf1def13aa1aab44ef to your computer and use it in GitHub Desktop.

Select an option

Save thuytrinh/cb79bc9e156d0cdf1def13aa1aab44ef to your computer and use it in GitHub Desktop.

Revisions

  1. Thuy Trinh revised this gist Sep 21, 2018. No changes.
  2. Thuy Trinh revised this gist Sep 21, 2018. 1 changed file with 16 additions and 2 deletions.
    18 changes: 16 additions & 2 deletions OkioTest.kt
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,28 @@
    import okio.GzipSink
    import okio.GzipSource
    import okio.Okio
    import org.assertj.core.api.Assertions.assertThat
    import org.junit.Test
    import java.io.File

    class OkioTest {
    @Test
    fun `should compress file properly`() {
    val originalFile = File("(ʘ‿ʘ)")
    val zipFile = File("(ʘ‿ʘ).gz")

    Okio.sink(originalFile).use { fileSink ->
    // Write & zip the content to the file.
    Okio.sink(zipFile).use { fileSink ->
    Okio.buffer(GzipSink(fileSink)).use { bufferedSink ->
    bufferedSink.writeUtf8("。◕‿◕。\n")
    bufferedSink.writeUtf8("ಠoಠ\n")
    bufferedSink.writeUtf8("♥‿♥\n")
    }
    }

    // Decompress the file and read its content.
    val content: String? = GzipSource(Okio.source(zipFile)).use { fileSource ->
    Okio.buffer(fileSource).use { bufferedSource -> bufferedSource.readUtf8() }
    }
    assertThat(content).isEqualTo("。◕‿◕。\n" + "ಠoಠ\n" + "♥‿♥\n")
    }
    }
  3. Thuy Trinh created this gist Sep 21, 2018.
    14 changes: 14 additions & 0 deletions OkioTest.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    class OkioTest {
    @Test
    fun `should compress file properly`() {
    val originalFile = File("(ʘ‿ʘ)")

    Okio.sink(originalFile).use { fileSink ->
    Okio.buffer(GzipSink(fileSink)).use { bufferedSink ->
    bufferedSink.writeUtf8("。◕‿◕。\n")
    bufferedSink.writeUtf8("ಠoಠ\n")
    bufferedSink.writeUtf8("♥‿♥\n")
    }
    }
    }
    }