[
  {
    "path": ".editorconfig",
    "content": "root = true\n\n[*]\nindent_size = 2\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\nmax_line_length=100\n\n[*.{kt,kts}]\nij_kotlin_imports_layout = *\nij_kotlin_allow_trailing_comma = true\nij_kotlin_allow_trailing_comma_on_call_site = true\nktlint_code_style = intellij_idea\n"
  },
  {
    "path": ".gitattributes",
    "content": "* text=auto eol=lf\n\n*.bat text eol=crlf\n*.jar binary\n"
  },
  {
    "path": ".github/renovate.json5",
    "content": "{\n  $schema: 'https://docs.renovatebot.com/renovate-schema.json',\n  extends: [\n    'config:recommended',\n  ],\n  ignorePresets: [\n    // Ensure we get the latest version and are not pinned to old versions.\n    'workarounds:javaLTSVersions',\n  ],\n  customManagers: [\n    // Update .java-version file with the latest JDK version.\n    {\n      customType: 'regex',\n      fileMatch: [\n        '\\\\.java-version$',\n      ],\n      matchStrings: [\n        '(?<currentValue>.*)\\\\n',\n      ],\n      datasourceTemplate: 'java-version',\n      depNameTemplate: 'java',\n      // Only write the major version.\n      extractVersionTemplate: '^(?<version>\\\\d+)',\n    },\n  ],\n}\n"
  },
  {
    "path": ".github/workflows/.java-version",
    "content": "24\n"
  },
  {
    "path": ".github/workflows/build.yaml",
    "content": "name: build\n\non:\n  pull_request:\n  push:\n    branches:\n      - '*'\n    tags:\n      - '*'\n\njobs:\n  build:\n    runs-on: macos-latest\n    steps:\n      - uses: actions/checkout@v5\n      - uses: actions/setup-java@v4\n        with:\n          distribution: 'zulu'\n          java-version-file: .github/workflows/.java-version\n      - uses: gradle/actions/setup-gradle@v4\n      - run: ./gradlew build\n\n  publish:\n    needs: build\n    if: github.repository == 'JakeWharton/byteunits'\n    runs-on: macos-latest\n    steps:\n      - uses: actions/checkout@v5\n      - uses: actions/setup-java@v4\n        with:\n          distribution: 'zulu'\n          java-version-file: .github/workflows/.java-version\n      - uses: gradle/actions/setup-gradle@v4\n      - name: Extract release notes\n        id: release_notes\n        if: startsWith(github.ref, 'refs/tags/')\n        uses: ffurrer2/extract-release-notes@v2\n      - name: Create Release\n        if: startsWith(github.ref, 'refs/tags/')\n        uses: softprops/action-gh-release@v2\n        with:\n          body: ${{ steps.release_notes.outputs.release_notes }}\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n      - name: Publish Artifacts\n        run: ./gradlew publish\n        if: github.ref == 'refs/heads/trunk'\n        env:\n          ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}\n          ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}\n"
  },
  {
    "path": ".gitignore",
    "content": "# Eclipse\n.classpath\n.project\n.settings\neclipsebin\n\n# Ant\nbin\ngen\nbuild\nout\nlib\n\n# Gradle\n.gradle\n\n# Maven\ntarget\npom.xml.*\nrelease.properties\n\n# IntelliJ\n.idea\n*.iml\n*.iws\n*.ipr\nclasses\n\n.DS_Store\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "Change Log\n==========\n\nVersion 0.9.1 *(2015-06-26)*\n----------------------------\n\n * New: `format` static methods on `DecimalByteUnit`, `BinaryByteUnit`, and `BitUnit` for creating\n   human-readable strings of the value (e.g., \"2 GB\").\n\n\nVersion 0.9.0 *(2014-07-20)*\n----------------------------\n\nInitial version.\n"
  },
  {
    "path": "LICENSE.txt",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "Byte Units\n==========\n\nUtility classes for converting between granularities of SI and IEC byte units\nand bit units.\n\n**Deprecated!** Prefer https://github.com/saket/byte-size instead.\n\n\n\nExample Usage\n-------------\n\nWhat's the difference in hard drive space between perception and actual?\n```java\nlong perception = BinaryByteUnit.TEBIBYTES.toBytes(2);\nlong usable = DecimalByteUnit.TERABYTES.toBytes(2);\nlong lost = BinaryByteUnit.BYTES.toGibibytes(perception - usable);\nSystem.out.println(lost + \" GiB lost on a 2TB drive.\");\n```\n\nMethod parameter for specifying a resource size.\n```java\npublic void installDiskCache(long count, ByteUnit unit) {\n  long size = unit.toBytes(count);\n  // TODO Install disk cache of 'size' bytes.\n}\n```\n\nPrint human-readable strings for byte and bit amounts.\n```java\nlong bytes = 2 * 1024 * 1024 * 1024;\nSystem.out.println(BinaryByteUnit.format(bytes));\n```\n\n\n\nDownload\n--------\n\nGrab the [latest .jar][1] or add via Gradle:\n```groovy\nimplementation 'com.jakewharton.byteunits:byteunits:0.9.1'\n```\nor Maven:\n```xml\n<dependency>\n  <groupId>com.jakewharton.byteunits</groupId>\n  <artifactId>byteunits</artifactId>\n  <version>0.9.1</version>\n</dependency>\n```\n\nSnapshots of the development version are available in [Sonatype's `snapshots` repository][snap].\n\n\n\nLicense\n-------\n\n    Copyright 2014 Jake Wharton\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n\n\n\n [1]: https://search.maven.org/remote_content?g=com.jakewharton.byteunits&a=byteunits&v=LATEST\n [snap]: https://oss.sonatype.org/content/repositories/snapshots/\n"
  },
  {
    "path": "build.gradle",
    "content": "import org.jetbrains.kotlin.gradle.dsl.JvmTarget\nimport org.jetbrains.kotlin.gradle.tasks.KotlinCompile\n\nbuildscript {\n  dependencies {\n    classpath libs.kotlin.gradlePlugin\n    classpath libs.mavenPublishPlugin\n    classpath libs.spotlessPlugin\n    classpath libs.animalSnifferPlugin\n  }\n  repositories {\n    mavenCentral()\n  }\n}\n\napply plugin: 'org.jetbrains.kotlin.multiplatform'\napply plugin: 'com.vanniktech.maven.publish'\napply plugin: 'com.diffplug.spotless'\napply plugin: 'ru.vyarus.animalsniffer'\n\nkotlin {\n  jvm()\n\n  sourceSets {\n    commonTest {\n      dependencies {\n        implementation 'org.jetbrains.kotlin:kotlin-test'\n      }\n    }\n  }\n}\n\ntasks.withType(KotlinCompile).configureEach {\n  compilerOptions {\n    jvmTarget = JvmTarget.JVM_1_8\n    freeCompilerArgs.addAll([\n      '-progressive',\n      '-Xjvm-default=all',\n    ])\n  }\n}\n\ntasks.withType(JavaCompile).configureEach {\n  sourceCompatibility = JavaVersion.VERSION_1_8.toString()\n  targetCompatibility = JavaVersion.VERSION_1_8.toString()\n}\n\nspotless {\n  kotlin {\n    ktlint(libs.ktlint.get().version)\n      .editorConfigOverride([\n        // Making something an expression body should be a choice around readability.\n        'ktlint_standard_function-expression-body': 'disabled',\n      ])\n    target 'src/**/*.kt'\n  }\n}\n\ndependencies {\n  signature 'org.codehaus.mojo.signature:java18:1.0@signature'\n  signature 'net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature'\n}\n"
  },
  {
    "path": "gradle/libs.versions.toml",
    "content": "[libraries]\nkotlin-gradlePlugin = \"org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.10\"\n\nktlint = \"com.pinterest.ktlint:ktlint-cli:1.7.1\"\nmavenPublishPlugin = \"com.vanniktech:gradle-maven-publish-plugin:0.34.0\"\nspotlessPlugin = \"com.diffplug.spotless:spotless-plugin-gradle:7.2.1\"\nanimalSnifferPlugin = \"ru.vyarus:gradle-animalsniffer-plugin:2.0.1\"\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "distributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-9.0.0-bin.zip\nnetworkTimeout=10000\nvalidateDistributionUrl=true\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\n"
  },
  {
    "path": "gradle.properties",
    "content": "GROUP=com.jakewharton.byteunits\nVERSION_NAME=0.9.2-SNAPSHOT\n\nPOM_ARTIFACT_ID=byteunits\nPOM_NAME=Byte Units\nPOM_DESCRIPTION=Utility classes for converting between granularities of SI and IEC byte units and bit units.\n\nPOM_URL=http://github.com/JakeWharton/byteunits\nPOM_SCM_URL=https://github.com/vanniktech/byteunits\nPOM_SCM_CONNECTION=scm:git:git://github.com/JakeWharton/byteunits.git\nPOM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/JakeWharton/byteunits.git\n\nPOM_LICENCE_NAME=The Apache Software License, Version 2.0\nPOM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt\nPOM_LICENCE_DIST=repo\n\nPOM_DEVELOPER_ID=jakewharton\nPOM_DEVELOPER_NAME=Jake Wharton\nPOM_INCEPTION_YEAR=2014\n\nkotlin.mpp.stability.nowarn=true\n\nmavenCentralPublishing=true\nmavenCentralAutomaticPublishing=true\nsignAllPublications=true\n"
  },
  {
    "path": "gradlew",
    "content": "#!/bin/sh\n\n#\n# Copyright © 2015 the original authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n# SPDX-License-Identifier: Apache-2.0\n#\n\n##############################################################################\n#\n#   Gradle start up script for POSIX generated by Gradle.\n#\n#   Important for running:\n#\n#   (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is\n#       noncompliant, but you have some other compliant shell such as ksh or\n#       bash, then to run this script, type that shell name before the whole\n#       command line, like:\n#\n#           ksh Gradle\n#\n#       Busybox and similar reduced shells will NOT work, because this script\n#       requires all of these POSIX shell features:\n#         * functions;\n#         * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,\n#           «${var#prefix}», «${var%suffix}», and «$( cmd )»;\n#         * compound commands having a testable exit status, especially «case»;\n#         * various built-in commands including «command», «set», and «ulimit».\n#\n#   Important for patching:\n#\n#   (2) This script targets any POSIX shell, so it avoids extensions provided\n#       by Bash, Ksh, etc; in particular arrays are avoided.\n#\n#       The \"traditional\" practice of packing multiple parameters into a\n#       space-separated string is a well documented source of bugs and security\n#       problems, so this is (mostly) avoided, by progressively accumulating\n#       options in \"$@\", and eventually passing that to Java.\n#\n#       Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,\n#       and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;\n#       see the in-line comments for details.\n#\n#       There are tweaks for specific operating systems such as AIX, CygWin,\n#       Darwin, MinGW, and NonStop.\n#\n#   (3) This script is generated from the Groovy template\n#       https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt\n#       within the Gradle project.\n#\n#       You can find Gradle at https://github.com/gradle/gradle/.\n#\n##############################################################################\n\n# Attempt to set APP_HOME\n\n# Resolve links: $0 may be a link\napp_path=$0\n\n# Need this for daisy-chained symlinks.\nwhile\n    APP_HOME=${app_path%\"${app_path##*/}\"}  # leaves a trailing /; empty if no leading path\n    [ -h \"$app_path\" ]\ndo\n    ls=$( ls -ld \"$app_path\" )\n    link=${ls#*' -> '}\n    case $link in             #(\n      /*)   app_path=$link ;; #(\n      *)    app_path=$APP_HOME$link ;;\n    esac\ndone\n\n# This is normally unused\n# shellcheck disable=SC2034\nAPP_BASE_NAME=${0##*/}\n# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)\nAPP_HOME=$( cd -P \"${APP_HOME:-./}\" > /dev/null && printf '%s\\n' \"$PWD\" ) || exit\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=maximum\n\nwarn () {\n    echo \"$*\"\n} >&2\n\ndie () {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n} >&2\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\nnonstop=false\ncase \"$( uname )\" in                #(\n  CYGWIN* )         cygwin=true  ;; #(\n  Darwin* )         darwin=true  ;; #(\n  MSYS* | MINGW* )  msys=true    ;; #(\n  NONSTOP* )        nonstop=true ;;\nesac\n\nCLASSPATH=\"\\\\\\\"\\\\\\\"\"\n\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=$JAVA_HOME/jre/sh/java\n    else\n        JAVACMD=$JAVA_HOME/bin/java\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=java\n    if ! command -v java >/dev/null 2>&1\n    then\n        die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nfi\n\n# Increase the maximum file descriptors if we can.\nif ! \"$cygwin\" && ! \"$darwin\" && ! \"$nonstop\" ; then\n    case $MAX_FD in #(\n      max*)\n        # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.\n        # shellcheck disable=SC2039,SC3045\n        MAX_FD=$( ulimit -H -n ) ||\n            warn \"Could not query maximum file descriptor limit\"\n    esac\n    case $MAX_FD in  #(\n      '' | soft) :;; #(\n      *)\n        # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.\n        # shellcheck disable=SC2039,SC3045\n        ulimit -n \"$MAX_FD\" ||\n            warn \"Could not set maximum file descriptor limit to $MAX_FD\"\n    esac\nfi\n\n# Collect all arguments for the java command, stacking in reverse order:\n#   * args from the command line\n#   * the main class name\n#   * -classpath\n#   * -D...appname settings\n#   * --module-path (only if needed)\n#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.\n\n# For Cygwin or MSYS, switch paths to Windows format before running java\nif \"$cygwin\" || \"$msys\" ; then\n    APP_HOME=$( cygpath --path --mixed \"$APP_HOME\" )\n    CLASSPATH=$( cygpath --path --mixed \"$CLASSPATH\" )\n\n    JAVACMD=$( cygpath --unix \"$JAVACMD\" )\n\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    for arg do\n        if\n            case $arg in                                #(\n              -*)   false ;;                            # don't mess with options #(\n              /?*)  t=${arg#/} t=/${t%%/*}              # looks like a POSIX filepath\n                    [ -e \"$t\" ] ;;                      #(\n              *)    false ;;\n            esac\n        then\n            arg=$( cygpath --path --ignore --mixed \"$arg\" )\n        fi\n        # Roll the args list around exactly as many times as the number of\n        # args, so each arg winds up back in the position where it started, but\n        # possibly modified.\n        #\n        # NB: a `for` loop captures its iteration list before it begins, so\n        # changing the positional parameters here affects neither the number of\n        # iterations, nor the values presented in `arg`.\n        shift                   # remove old arg\n        set -- \"$@\" \"$arg\"      # push replacement arg\n    done\nfi\n\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS='\"-Xmx64m\" \"-Xms64m\"'\n\n# Collect all arguments for the java command:\n#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,\n#     and any embedded shellness will be escaped.\n#   * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be\n#     treated as '${Hostname}' itself on the command line.\n\nset -- \\\n        \"-Dorg.gradle.appname=$APP_BASE_NAME\" \\\n        -classpath \"$CLASSPATH\" \\\n        -jar \"$APP_HOME/gradle/wrapper/gradle-wrapper.jar\" \\\n        \"$@\"\n\n# Stop when \"xargs\" is not available.\nif ! command -v xargs >/dev/null 2>&1\nthen\n    die \"xargs is not available\"\nfi\n\n# Use \"xargs\" to parse quoted args.\n#\n# With -n1 it outputs one arg per line, with the quotes and backslashes removed.\n#\n# In Bash we could simply go:\n#\n#   readarray ARGS < <( xargs -n1 <<<\"$var\" ) &&\n#   set -- \"${ARGS[@]}\" \"$@\"\n#\n# but POSIX shell has neither arrays nor command substitution, so instead we\n# post-process each arg (as a line of input to sed) to backslash-escape any\n# character that might be a shell metacharacter, then use eval to reverse\n# that process (while maintaining the separation between arguments), and wrap\n# the whole thing up as a single \"set\" statement.\n#\n# This will of course break if any of these variables contains a newline or\n# an unmatched quote.\n#\n\neval \"set -- $(\n        printf '%s\\n' \"$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\" |\n        xargs -n1 |\n        sed ' s~[^-[:alnum:]+,./:=@_]~\\\\&~g; ' |\n        tr '\\n' ' '\n    )\" '\"$@\"'\n\nexec \"$JAVACMD\" \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@rem\r\n@rem Copyright 2015 the original author or authors.\r\n@rem\r\n@rem Licensed under the Apache License, Version 2.0 (the \"License\");\r\n@rem you may not use this file except in compliance with the License.\r\n@rem You may obtain a copy of the License at\r\n@rem\r\n@rem      https://www.apache.org/licenses/LICENSE-2.0\r\n@rem\r\n@rem Unless required by applicable law or agreed to in writing, software\r\n@rem distributed under the License is distributed on an \"AS IS\" BASIS,\r\n@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n@rem See the License for the specific language governing permissions and\r\n@rem limitations under the License.\r\n@rem\r\n@rem SPDX-License-Identifier: Apache-2.0\r\n@rem\r\n\r\n@if \"%DEBUG%\"==\"\" @echo off\r\n@rem ##########################################################################\r\n@rem\r\n@rem  Gradle startup script for Windows\r\n@rem\r\n@rem ##########################################################################\r\n\r\n@rem Set local scope for the variables with windows NT shell\r\nif \"%OS%\"==\"Windows_NT\" setlocal\r\n\r\nset DIRNAME=%~dp0\r\nif \"%DIRNAME%\"==\"\" set DIRNAME=.\r\n@rem This is normally unused\r\nset APP_BASE_NAME=%~n0\r\nset APP_HOME=%DIRNAME%\r\n\r\n@rem Resolve any \".\" and \"..\" in APP_HOME to make it shorter.\r\nfor %%i in (\"%APP_HOME%\") do set APP_HOME=%%~fi\r\n\r\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r\nset DEFAULT_JVM_OPTS=\"-Xmx64m\" \"-Xms64m\"\r\n\r\n@rem Find java.exe\r\nif defined JAVA_HOME goto findJavaFromJavaHome\r\n\r\nset JAVA_EXE=java.exe\r\n%JAVA_EXE% -version >NUL 2>&1\r\nif %ERRORLEVEL% equ 0 goto execute\r\n\r\necho. 1>&2\r\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2\r\necho. 1>&2\r\necho Please set the JAVA_HOME variable in your environment to match the 1>&2\r\necho location of your Java installation. 1>&2\r\n\r\ngoto fail\r\n\r\n:findJavaFromJavaHome\r\nset JAVA_HOME=%JAVA_HOME:\"=%\r\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\r\n\r\nif exist \"%JAVA_EXE%\" goto execute\r\n\r\necho. 1>&2\r\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2\r\necho. 1>&2\r\necho Please set the JAVA_HOME variable in your environment to match the 1>&2\r\necho location of your Java installation. 1>&2\r\n\r\ngoto fail\r\n\r\n:execute\r\n@rem Setup the command line\r\n\r\nset CLASSPATH=\r\n\r\n\r\n@rem Execute Gradle\r\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" -jar \"%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\" %*\r\n\r\n:end\r\n@rem End local scope for the variables with windows NT shell\r\nif %ERRORLEVEL% equ 0 goto mainEnd\r\n\r\n:fail\r\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r\nrem the _cmd.exe /c_ return code!\r\nset EXIT_CODE=%ERRORLEVEL%\r\nif %EXIT_CODE% equ 0 set EXIT_CODE=1\r\nif not \"\"==\"%GRADLE_EXIT_CONSOLE%\" exit %EXIT_CODE%\r\nexit /b %EXIT_CODE%\r\n\r\n:mainEnd\r\nif \"%OS%\"==\"Windows_NT\" endlocal\r\n\r\n:omega\r\n"
  },
  {
    "path": "settings.gradle",
    "content": "pluginManagement {\n  repositories {\n    mavenCentral()\n    google()\n    gradlePluginPortal()\n  }\n}\n\ndependencyResolutionManagement {\n  repositories {\n    mavenCentral()\n  }\n}\n"
  },
  {
    "path": "src/jvmMain/kotlin/com/jakewharton/byteunits/BinaryByteUnit.kt",
    "content": "package com.jakewharton.byteunits\n\nimport java.text.DecimalFormat\nimport java.text.NumberFormat\n\n/**\n * A [BinaryByteUnit] represents power-of-two byte sizes at a given unit of granularity and\n * provides utility methods to convert across units. A [BinaryByteUnit] does not maintain\n * byte size information, but only helps organize and use byte size representations that may be\n * maintained separately across various contexts.\n */\nenum class BinaryByteUnit : ByteUnit {\n  /** Byte unit representing one byte. */\n  BYTES {\n    override fun convert(sourceCount: Long, sourceUnit: BinaryByteUnit) =\n      sourceUnit.toBytes(sourceCount)\n\n    override fun toBytes(count: Long) = count\n\n    override fun toKibibytes(count: Long) = count / (KB / B)\n\n    override fun toMebibytes(count: Long) = count / (MB / B)\n\n    override fun toGibibytes(count: Long) = count / (GB / B)\n\n    override fun toTebibytes(count: Long) = count / (TB / B)\n\n    override fun toPebibytes(count: Long) = count / (PB / B)\n  },\n\n  /** A byte unit representing 1024 bytes. */\n  KIBIBYTES {\n    override fun convert(sourceCount: Long, sourceUnit: BinaryByteUnit) =\n      sourceUnit.toKibibytes(sourceCount)\n\n    override fun toBytes(count: Long) = checkedMultiply(count, KB / B, MAX / (KB / B))\n\n    override fun toKibibytes(count: Long) = count\n\n    override fun toMebibytes(count: Long) = count / (MB / KB)\n\n    override fun toGibibytes(count: Long) = count / (GB / KB)\n\n    override fun toTebibytes(count: Long) = count / (TB / KB)\n\n    override fun toPebibytes(count: Long) = count / (PB / KB)\n  },\n\n  /** A byte unit representing 1024 kibibytes. */\n  MEBIBYTES {\n    override fun convert(sourceCount: Long, sourceUnit: BinaryByteUnit) =\n      sourceUnit.toMebibytes(sourceCount)\n\n    override fun toBytes(count: Long) = checkedMultiply(count, MB / B, MAX / (MB / B))\n\n    override fun toKibibytes(count: Long) = checkedMultiply(count, MB / KB, MAX / (MB / KB))\n\n    override fun toMebibytes(count: Long) = count\n\n    override fun toGibibytes(count: Long) = count / (GB / MB)\n\n    override fun toTebibytes(count: Long) = count / (TB / MB)\n\n    override fun toPebibytes(count: Long) = count / (PB / MB)\n  },\n\n  /** A byte unit representing 1024 mebibytes. */\n  GIBIBYTES {\n    override fun convert(sourceCount: Long, sourceUnit: BinaryByteUnit) =\n      sourceUnit.toGibibytes(sourceCount)\n\n    override fun toBytes(count: Long) = checkedMultiply(count, GB / B, MAX / (GB / B))\n\n    override fun toKibibytes(count: Long) = checkedMultiply(count, GB / KB, MAX / (GB / KB))\n\n    override fun toMebibytes(count: Long) = checkedMultiply(count, GB / MB, MAX / (GB / MB))\n\n    override fun toGibibytes(count: Long) = count\n\n    override fun toTebibytes(count: Long) = count / (TB / GB)\n\n    override fun toPebibytes(count: Long) = count / (PB / GB)\n  },\n\n  /** A byte unit representing 1024 gibibytes. */\n  TEBIBYTES {\n    override fun convert(sourceCount: Long, sourceUnit: BinaryByteUnit) =\n      sourceUnit.toTebibytes(sourceCount)\n\n    override fun toBytes(count: Long) = checkedMultiply(count, TB / B, MAX / (TB / B))\n\n    override fun toKibibytes(count: Long) = checkedMultiply(count, TB / KB, MAX / (TB / KB))\n\n    override fun toMebibytes(count: Long) = checkedMultiply(count, TB / MB, MAX / (TB / MB))\n\n    override fun toGibibytes(count: Long) = checkedMultiply(count, TB / GB, MAX / (TB / GB))\n\n    override fun toTebibytes(count: Long) = count\n\n    override fun toPebibytes(count: Long) = count / (PB / TB)\n  },\n\n  /** A byte unit representing 1024 tebibytes. */\n  PEBIBYTES {\n    override fun convert(sourceCount: Long, sourceUnit: BinaryByteUnit) =\n      sourceUnit.toPebibytes(sourceCount)\n\n    override fun toBytes(count: Long) = checkedMultiply(count, PB / B, MAX / (PB / B))\n\n    override fun toKibibytes(count: Long) = checkedMultiply(count, PB / KB, MAX / (PB / KB))\n\n    override fun toMebibytes(count: Long) = checkedMultiply(count, PB / MB, MAX / (PB / MB))\n\n    override fun toGibibytes(count: Long) = checkedMultiply(count, PB / GB, MAX / (PB / GB))\n\n    override fun toTebibytes(count: Long) = checkedMultiply(count, PB / TB, MAX / (PB / TB))\n\n    override fun toPebibytes(count: Long) = count\n  },\n  ;\n\n  /**\n   * Converts the given size in the given unit to this unit. Conversions from finer to coarser\n   * granularities truncate, so lose precision. For example, converting from `999` bytes to\n   * kibibytes results in `0`. Conversions from coarser to finer granularities with arguments\n   * that would numerically overflow saturate to [Long.MIN_VALUE] if negative or\n   * [Long.MAX_VALUE] if positive.\n   *\n   *\n   * For example, to convert 10 kilobytes to bytes, use:\n   * `ByteUnit.KIBIBYTES.convert(10, ByteUnit.BYTES)`\n   *\n   * [sourceCount] the size in the given [sourceUnit].\n   * [sourceUnit] the unit of the [sourceCount] argument.\n   * @return the converted size in this unit, or [Long.MIN_VALUE] if conversion would\n   * negatively overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun convert(sourceCount: Long, sourceUnit: BinaryByteUnit): Long\n\n  /**\n   * Equivalent to [KIBIBYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toKibibytes(count: Long): Long\n\n  /**\n   * Equivalent to [MEBIBYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toMebibytes(count: Long): Long\n\n  /**\n   * Equivalent to [GIBIBYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toGibibytes(count: Long): Long\n\n  /**\n   * Equivalent to [TEBIBYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toTebibytes(count: Long): Long\n\n  /**\n   * Equivalent to [PEBIBYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toPebibytes(count: Long): Long\n\n  companion object {\n    private const val B = 1L\n    private const val KB = B * 1024L\n    private const val MB = KB * 1024L\n    private const val GB = MB * 1024L\n    private const val TB = GB * 1024L\n    private const val PB = TB * 1024L\n    private const val MAX = Long.MAX_VALUE\n    private val UNITS = arrayOf(\"B\", \"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\")\n\n    /**\n     * Return `bytes` as human-readable size string (e.g., \"1.2 GiB\". This will use a\n     * [DecimalFormat] instance with `pattern` for formatting the number.\n     */\n    fun format(bytes: Long, pattern: String): String {\n      return format(bytes, DecimalFormat(pattern))\n    }\n\n    /**\n     * Return `bytes` as human-readable size string (e.g., \"1.2 GiB\". This will use a default\n     * [DecimalFormat] instance for formatting the number.\n     */\n    @JvmOverloads fun format(\n      bytes: Long,\n      format: NumberFormat = DecimalFormat(\n        DEFAULT_FORMAT_PATTERN,\n      ),\n    ): String {\n      require(bytes >= 0) { \"bytes < 0: $bytes\" }\n      var unitIndex = 0\n      var count = bytes.toDouble()\n      while (count >= 1024.0 && unitIndex < UNITS.size - 1) {\n        count /= 1024.0\n        unitIndex += 1\n      }\n      return format.format(count) + ' ' + UNITS[unitIndex]\n    }\n  }\n}\n"
  },
  {
    "path": "src/jvmMain/kotlin/com/jakewharton/byteunits/BitUnit.kt",
    "content": "package com.jakewharton.byteunits\n\nimport java.text.DecimalFormat\nimport java.text.NumberFormat\n\n/**\n * A [BitUnit] represents bit size at a given unit of granularity and provides utility\n * methods to convert across units. A [BitUnit] does not maintain bit size information,\n * but only helps organize and use bit size representations that may be maintained separately\n * across various contexts.\n */\nenum class BitUnit : ByteUnit {\n  /** Bit unit representing one bit. */\n  BITS {\n    override fun convert(sourceCount: Long, sourceUnit: BitUnit): Long =\n      sourceUnit.toBits(sourceCount)\n\n    override fun toBytes(count: Long): Long = count / BYTE\n\n    override fun toBits(count: Long): Long = count\n\n    override fun toKilobits(count: Long): Long = count / (KB / B)\n\n    override fun toMegabits(count: Long): Long = count / (MB / B)\n\n    override fun toGigabits(count: Long): Long = count / (GB / B)\n\n    override fun toTerabits(count: Long): Long = count / (TB / B)\n\n    override fun toPetabits(count: Long): Long = count / (PB / B)\n  },\n\n  /** A bit unit representing 1000 bits. */\n  KILOBITS {\n    override fun convert(sourceCount: Long, sourceUnit: BitUnit): Long =\n      sourceUnit.toKilobits(sourceCount)\n\n    override fun toBytes(count: Long): Long = count * KBYTE\n\n    override fun toBits(count: Long): Long = checkedMultiply(count, KB / B, MAX / (KB / B))\n\n    override fun toKilobits(count: Long): Long = count\n\n    override fun toMegabits(count: Long): Long = count / (MB / KB)\n\n    override fun toGigabits(count: Long): Long = count / (GB / KB)\n\n    override fun toTerabits(count: Long): Long = count / (TB / KB)\n\n    override fun toPetabits(count: Long): Long = count / (PB / KB)\n  },\n\n  /** A bit unit representing 1000 kilobits. */\n  MEGABITS {\n    override fun convert(sourceCount: Long, sourceUnit: BitUnit): Long =\n      sourceUnit.toMegabits(sourceCount)\n\n    override fun toBytes(count: Long): Long = count * MBYTE\n\n    override fun toBits(count: Long): Long = checkedMultiply(count, MB / B, MAX / (MB / B))\n\n    override fun toKilobits(count: Long): Long = checkedMultiply(count, MB / KB, MAX / (MB / KB))\n\n    override fun toMegabits(count: Long): Long = count\n\n    override fun toGigabits(count: Long): Long = count / (GB / MB)\n\n    override fun toTerabits(count: Long): Long = count / (TB / MB)\n\n    override fun toPetabits(count: Long): Long = count / (PB / MB)\n  },\n\n  /** A bit unit representing 1000 megabits. */\n  GIGABITS {\n    override fun convert(sourceCount: Long, sourceUnit: BitUnit): Long =\n      sourceUnit.toGigabits(sourceCount)\n\n    override fun toBytes(count: Long): Long = count * GBYTE\n\n    override fun toBits(count: Long): Long = checkedMultiply(count, GB / B, MAX / (GB / B))\n\n    override fun toKilobits(count: Long): Long = checkedMultiply(count, GB / KB, MAX / (GB / KB))\n\n    override fun toMegabits(count: Long): Long = checkedMultiply(count, GB / MB, MAX / (GB / MB))\n\n    override fun toGigabits(count: Long): Long = count\n\n    override fun toTerabits(count: Long): Long = count / (TB / GB)\n\n    override fun toPetabits(count: Long): Long = count / (PB / GB)\n  },\n\n  /** A bit unit representing 1000 gigabits. */\n  TERABITS {\n    override fun convert(sourceCount: Long, sourceUnit: BitUnit): Long =\n      sourceUnit.toTerabits(sourceCount)\n\n    override fun toBytes(count: Long): Long = count * TBYTE\n\n    override fun toBits(count: Long): Long = checkedMultiply(count, TB / B, MAX / (TB / B))\n\n    override fun toKilobits(count: Long): Long = checkedMultiply(count, TB / KB, MAX / (TB / KB))\n\n    override fun toMegabits(count: Long): Long = checkedMultiply(count, TB / MB, MAX / (TB / MB))\n\n    override fun toGigabits(count: Long): Long = checkedMultiply(count, TB / GB, MAX / (TB / GB))\n\n    override fun toTerabits(count: Long): Long = count\n\n    override fun toPetabits(count: Long): Long = count / (PB / TB)\n  },\n\n  /** A bit unit representing 1000 terabits. */\n  PETABITS {\n    override fun convert(sourceCount: Long, sourceUnit: BitUnit): Long =\n      sourceUnit.toPetabits(sourceCount)\n\n    override fun toBytes(count: Long): Long = count * PBYTE\n\n    override fun toBits(count: Long): Long = checkedMultiply(count, PB / B, MAX / (PB / B))\n\n    override fun toKilobits(count: Long): Long = checkedMultiply(count, PB / KB, MAX / (PB / KB))\n\n    override fun toMegabits(count: Long): Long = checkedMultiply(count, PB / MB, MAX / (PB / MB))\n\n    override fun toGigabits(count: Long): Long = checkedMultiply(count, PB / GB, MAX / (PB / GB))\n\n    override fun toTerabits(count: Long): Long = checkedMultiply(count, PB / TB, MAX / (PB / TB))\n\n    override fun toPetabits(count: Long): Long = count\n  },\n  ;\n\n  /**\n   * Converts the given size in the given unit to this unit. Conversions from finer to coarser\n   * granularities truncate, so lose precision. For example, converting from `999` bit to\n   * kilobits results in `0`. Conversions from coarser to finer granularities with arguments\n   * that would numerically overflow saturate to [Long.MIN_VALUE] if negative or\n   * [Long.MAX_VALUE] if positive.\n   *\n   *\n   * For example, to convert 10 kilobytes to bytes, use:\n   * `ByteUnit.KILOBITS.convert(10, ByteUnit.BITS)`\n   *\n   * [sourceCount] the size in the given [sourceUnit].\n   * [sourceUnit] the unit of the [sourceCount] argument.\n   * @return the converted size in this unit, or [Long.MIN_VALUE] if conversion would\n   * negatively overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun convert(sourceCount: Long, sourceUnit: BitUnit): Long\n\n  /**\n   * Equivalent to [BITS.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toBits(count: Long): Long\n\n  /**\n   * Equivalent to [KILOBITS.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toKilobits(count: Long): Long\n\n  /**\n   * Equivalent to [MEGABITS.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toMegabits(count: Long): Long\n\n  /**\n   * Equivalent to [GIGABITS.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toGigabits(count: Long): Long\n\n  /**\n   * Equivalent to [TERABITS.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toTerabits(count: Long): Long\n\n  /**\n   * Equivalent to [PETABITS.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toPetabits(count: Long): Long\n\n  companion object {\n    private const val B = 1L\n    private const val KB = B * 1000L\n    private const val MB = KB * 1000L\n    private const val GB = MB * 1000L\n    private const val TB = GB * 1000L\n    private const val PB = TB * 1000L\n    private const val BYTE = B * 8\n    private const val KBYTE = 1000L / BYTE\n    private const val MBYTE = KBYTE * 1000L\n    private const val GBYTE = MBYTE * 1000L\n    private const val TBYTE = GBYTE * 1000L\n    private const val PBYTE = TBYTE * 1000L\n    private const val MAX = Long.MAX_VALUE\n    private val UNITS = arrayOf(\"b\", \"Kb\", \"Mb\", \"Gb\", \"Tb\", \"Pb\")\n\n    /**\n     * Return `bits` as human-readable size string (e.g., \"1.2 Gb\". This will use a\n     * [DecimalFormat] instance with [pattern] for formatting the number.\n     */\n    fun format(bits: Long, pattern: String): String {\n      return format(bits, DecimalFormat(pattern))\n    }\n\n    /**\n     * Return `bits` as human-readable size string (e.g., \"1.2 Gb\". This will use a default\n     * [DecimalFormat] instance for formatting the number.\n     */\n    @JvmOverloads fun format(\n      bits: Long,\n      format: NumberFormat = DecimalFormat(\n        DEFAULT_FORMAT_PATTERN,\n      ),\n    ): String {\n      require(bits >= 0) { \"bits < 0: $bits\" }\n      var unitIndex = 0\n      var count = bits.toDouble()\n      while (count >= 1000.0 && unitIndex < UNITS.size - 1) {\n        count /= 1000.0\n        unitIndex += 1\n      }\n      return format.format(count) + ' ' + UNITS[unitIndex]\n    }\n  }\n}\n"
  },
  {
    "path": "src/jvmMain/kotlin/com/jakewharton/byteunits/ByteUnit.kt",
    "content": "package com.jakewharton.byteunits\n\n/**\n * A [ByteUnit] represents a size at a given unit of granularity which can be converted\n * into bytes. A [ByteUnit] does not maintain byte size information, but only helps use byte\n * size representations that may be maintained separately across various contexts.\n *\n * @see DecimalByteUnit\n * @see BinaryByteUnit\n * @see BitUnit\n */\nsealed interface ByteUnit {\n  /**\n   * Converts the given size in the given unit to bytes. Conversions with arguments that would\n   * numerically overflow saturate to [Long.MIN_VALUE] if negative or [Long.MAX_VALUE]\n   * if positive.\n   *\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  fun toBytes(count: Long): Long\n}\n"
  },
  {
    "path": "src/jvmMain/kotlin/com/jakewharton/byteunits/DecimalByteUnit.kt",
    "content": "package com.jakewharton.byteunits\n\nimport java.text.DecimalFormat\nimport java.text.NumberFormat\n\n/**\n * A [DecimalByteUnit] represents power-of-ten byte sizes at a given unit of granularity and\n * provides utility methods to convert across units. A [DecimalByteUnit] does not maintain\n * byte size information, but only helps organize and use byte size representations that may be\n * maintained separately across various contexts.\n */\nenum class DecimalByteUnit : ByteUnit {\n  /** Byte unit representing one byte. */\n  BYTES {\n    override fun convert(sourceCount: Long, sourceUnit: DecimalByteUnit): Long =\n      sourceUnit.toBytes(sourceCount)\n\n    override fun toBytes(count: Long): Long = count\n\n    override fun toKilobytes(count: Long): Long = count / (KB / B)\n\n    override fun toMegabytes(count: Long): Long = count / (MB / B)\n\n    override fun toGigabytes(count: Long): Long = count / (GB / B)\n\n    override fun toTerabytes(count: Long): Long = count / (TB / B)\n\n    override fun toPetabytes(count: Long): Long = count / (PB / B)\n  },\n\n  /** A byte unit representing 1000 bytes. */\n  KILOBYTES {\n    override fun convert(sourceCount: Long, sourceUnit: DecimalByteUnit): Long =\n      sourceUnit.toKilobytes(sourceCount)\n\n    override fun toBytes(count: Long): Long = checkedMultiply(count, KB / B, MAX / (KB / B))\n\n    override fun toKilobytes(count: Long): Long = count\n\n    override fun toMegabytes(count: Long): Long = count / (MB / KB)\n\n    override fun toGigabytes(count: Long): Long = count / (GB / KB)\n\n    override fun toTerabytes(count: Long): Long = count / (TB / KB)\n\n    override fun toPetabytes(count: Long): Long = count / (PB / KB)\n  },\n\n  /** A byte unit representing 1000 kilobytes. */\n  MEGABYTES {\n    override fun convert(sourceCount: Long, sourceUnit: DecimalByteUnit): Long =\n      sourceUnit.toMegabytes(sourceCount)\n\n    override fun toBytes(count: Long): Long = checkedMultiply(count, MB / B, MAX / (MB / B))\n\n    override fun toKilobytes(count: Long): Long = checkedMultiply(count, MB / KB, MAX / (MB / KB))\n\n    override fun toMegabytes(count: Long): Long = count\n\n    override fun toGigabytes(count: Long): Long = count / (GB / MB)\n\n    override fun toTerabytes(count: Long): Long = count / (TB / MB)\n\n    override fun toPetabytes(count: Long): Long = count / (PB / MB)\n  },\n\n  /** A byte unit representing 1000 megabytes. */\n  GIGABYTES {\n    override fun convert(sourceCount: Long, sourceUnit: DecimalByteUnit): Long =\n      sourceUnit.toGigabytes(sourceCount)\n\n    override fun toBytes(count: Long): Long = checkedMultiply(count, GB / B, MAX / (GB / B))\n\n    override fun toKilobytes(count: Long): Long = checkedMultiply(count, GB / KB, MAX / (GB / KB))\n\n    override fun toMegabytes(count: Long): Long = checkedMultiply(count, GB / MB, MAX / (GB / MB))\n\n    override fun toGigabytes(count: Long): Long = count\n\n    override fun toTerabytes(count: Long): Long = count / (TB / GB)\n\n    override fun toPetabytes(count: Long): Long = count / (PB / GB)\n  },\n\n  /** A byte unit representing 1000 gigabytes. */\n  TERABYTES {\n    override fun convert(sourceCount: Long, sourceUnit: DecimalByteUnit): Long =\n      sourceUnit.toTerabytes(sourceCount)\n\n    override fun toBytes(count: Long): Long = checkedMultiply(count, TB / B, MAX / (TB / B))\n\n    override fun toKilobytes(count: Long): Long = checkedMultiply(count, TB / KB, MAX / (TB / KB))\n\n    override fun toMegabytes(count: Long): Long = checkedMultiply(count, TB / MB, MAX / (TB / MB))\n\n    override fun toGigabytes(count: Long): Long = checkedMultiply(count, TB / GB, MAX / (TB / GB))\n\n    override fun toTerabytes(count: Long): Long = count\n\n    override fun toPetabytes(count: Long): Long = count / (PB / TB)\n  },\n\n  /** A byte unit representing 1000 terabytes. */\n  PETABYTES {\n    override fun convert(sourceCount: Long, sourceUnit: DecimalByteUnit): Long =\n      sourceUnit.toPetabytes(sourceCount)\n\n    override fun toBytes(count: Long): Long = checkedMultiply(count, PB / B, MAX / (PB / B))\n\n    override fun toKilobytes(count: Long): Long = checkedMultiply(count, PB / KB, MAX / (PB / KB))\n\n    override fun toMegabytes(count: Long): Long = checkedMultiply(count, PB / MB, MAX / (PB / MB))\n\n    override fun toGigabytes(count: Long): Long = checkedMultiply(count, PB / GB, MAX / (PB / GB))\n\n    override fun toTerabytes(count: Long): Long = checkedMultiply(count, PB / TB, MAX / (PB / TB))\n\n    override fun toPetabytes(count: Long): Long = count\n  },\n  ;\n\n  /**\n   * Converts the given size in the given unit to this unit. Conversions from finer to coarser\n   * granularities truncate, so lose precision. For example, converting from `999` bytes to\n   * kilobytes results in `0`. Conversions from coarser to finer granularities with arguments\n   * that would numerically overflow saturate to [Long.MIN_VALUE] if negative or\n   * [Long.MAX_VALUE] if positive.\n   *\n   *\n   * For example, to convert 10 kilobytes to bytes, use:\n   * `ByteUnit.KILOBYTES.convert(10, ByteUnit.BYTES)`\n   *\n   * [sourceCount] the size in the given [sourceUnit].\n   * [sourceUnit] the unit of the [sourceCount] argument.\n   * @return the converted size in this unit, or [Long.MIN_VALUE] if conversion would\n   * negatively overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun convert(sourceCount: Long, sourceUnit: DecimalByteUnit): Long\n\n  /**\n   * Equivalent to [KILOBYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toKilobytes(count: Long): Long\n\n  /**\n   * Equivalent to [MEGABYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toMegabytes(count: Long): Long\n\n  /**\n   * Equivalent to [GIGABYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toGigabytes(count: Long): Long\n\n  /**\n   * Equivalent to [TERABYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toTerabytes(count: Long): Long\n\n  /**\n   * Equivalent to [PETABYTES.convert(count, this)][convert].\n   * [count] the bit count\n   * @return the converted count, or [Long.MIN_VALUE] if conversion would negatively\n   * overflow, or [Long.MAX_VALUE] if it would positively overflow.\n   */\n  abstract fun toPetabytes(count: Long): Long\n\n  companion object {\n    private const val B = 1L\n    private const val KB = B * 1000L\n    private const val MB = KB * 1000L\n    private const val GB = MB * 1000L\n    private const val TB = GB * 1000L\n    private const val PB = TB * 1000L\n    private const val MAX = Long.MAX_VALUE\n    private val UNITS = arrayOf(\"B\", \"KB\", \"MB\", \"GB\", \"TB\", \"PB\")\n\n    /**\n     * Return `bytes` as human-readable size string (e.g., \"1.2 GB\". This will use a\n     * [DecimalFormat] instance with `pattern` for formatting the number.\n     */\n    fun format(bytes: Long, pattern: String): String {\n      return format(bytes, DecimalFormat(pattern))\n    }\n\n    /**\n     * Return `bytes` as human-readable size string (e.g., \"1.2 GB\". This will use a default\n     * [DecimalFormat] instance for formatting the number.\n     */\n    @JvmOverloads fun format(\n      bytes: Long,\n      format: NumberFormat = DecimalFormat(\n        DEFAULT_FORMAT_PATTERN,\n      ),\n    ): String {\n      require(bytes >= 0) { \"bytes < 0: $bytes\" }\n      var unitIndex = 0\n      var count = bytes.toDouble()\n      while (count >= 1000.0 && unitIndex < UNITS.size - 1) {\n        count /= 1000.0\n        unitIndex += 1\n      }\n      return format.format(count) + ' ' + UNITS[unitIndex]\n    }\n  }\n}\n"
  },
  {
    "path": "src/jvmMain/kotlin/com/jakewharton/byteunits/UnitUtil.kt",
    "content": "package com.jakewharton.byteunits\n\ninternal const val DEFAULT_FORMAT_PATTERN = \"#,##0.#\"\n\n/** Multiply [size] by [factor] accounting for overflow. */\ninternal fun checkedMultiply(size: Long, factor: Long, over: Long): Long = when {\n  size > over -> Long.MAX_VALUE\n  size < -over -> Long.MIN_VALUE\n  else -> size * factor\n}\n"
  },
  {
    "path": "src/jvmTest/kotlin/com/jakewharton/byteunits/BinaryByteUnitTest.kt",
    "content": "package com.jakewharton.byteunits\n\nimport com.jakewharton.byteunits.BinaryByteUnit.BYTES\nimport com.jakewharton.byteunits.BinaryByteUnit.GIBIBYTES\nimport com.jakewharton.byteunits.BinaryByteUnit.KIBIBYTES\nimport com.jakewharton.byteunits.BinaryByteUnit.MEBIBYTES\nimport com.jakewharton.byteunits.BinaryByteUnit.PEBIBYTES\nimport com.jakewharton.byteunits.BinaryByteUnit.TEBIBYTES\nimport java.text.DecimalFormat\nimport java.text.DecimalFormatSymbols\nimport java.text.NumberFormat\nimport java.util.Locale\nimport kotlin.test.Test\nimport kotlin.test.assertEquals\nimport kotlin.test.assertFailsWith\n\nclass BinaryByteUnitTest {\n  @Suppress(\"KotlinConstantConditions\")\n  @Test\n  fun convertInternal() {\n    for (s in 0..998) {\n      assertEquals(s / 1_024L, BYTES.toKibibytes(s.toLong()))\n      assertEquals(s / 1_048_576L, BYTES.toMebibytes(s.toLong()))\n      assertEquals(s / 1_073_741_824L, BYTES.toGibibytes(s.toLong()))\n      assertEquals(s / 1_099_511_627_776L, BYTES.toTebibytes(s.toLong()))\n      assertEquals(s / 1_125_899_906_842_624L, BYTES.toPebibytes(s.toLong()))\n\n      assertEquals(s * 1_024L, KIBIBYTES.toBytes(s.toLong()))\n      assertEquals(s / 1_024L, KIBIBYTES.toMebibytes(s.toLong()))\n      assertEquals(s / 1_048_576L, KIBIBYTES.toGibibytes(s.toLong()))\n      assertEquals(s / 1_073_741_824L, KIBIBYTES.toTebibytes(s.toLong()))\n      assertEquals(s / 1_099_511_627_776L, KIBIBYTES.toPebibytes(s.toLong()))\n\n      assertEquals(s * 1_048_576L, MEBIBYTES.toBytes(s.toLong()))\n      assertEquals(s * 1_024L, MEBIBYTES.toKibibytes(s.toLong()))\n      assertEquals(s / 1_024L, MEBIBYTES.toGibibytes(s.toLong()))\n      assertEquals(s / 1_048_576L, MEBIBYTES.toTebibytes(s.toLong()))\n      assertEquals(s / 1_073_741_824L, MEBIBYTES.toPebibytes(s.toLong()))\n\n      assertEquals(s * 1_073_741_824L, GIBIBYTES.toBytes(s.toLong()))\n      assertEquals(s * 1_048_576L, GIBIBYTES.toKibibytes(s.toLong()))\n      assertEquals(s * 1_024L, GIBIBYTES.toMebibytes(s.toLong()))\n      assertEquals(s / 1_024L, GIBIBYTES.toTebibytes(s.toLong()))\n      assertEquals(s / 1_048_576L, GIBIBYTES.toPebibytes(s.toLong()))\n\n      assertEquals(s * 1_099_511_627_776L, TEBIBYTES.toBytes(s.toLong()))\n      assertEquals(s * 1_073_741_824L, TEBIBYTES.toKibibytes(s.toLong()))\n      assertEquals(s * 1_048_576L, TEBIBYTES.toMebibytes(s.toLong()))\n      assertEquals(s * 1_024L, TEBIBYTES.toGibibytes(s.toLong()))\n      assertEquals(s / 1_024L, TEBIBYTES.toPebibytes(s.toLong()))\n\n      assertEquals(s * 1_125_899_906_842_624L, PEBIBYTES.toBytes(s.toLong()))\n      assertEquals(s * 1_099_511_627_776L, PEBIBYTES.toKibibytes(s.toLong()))\n      assertEquals(s * 1_073_741_824L, PEBIBYTES.toMebibytes(s.toLong()))\n      assertEquals(s * 1_048_576L, PEBIBYTES.toGibibytes(s.toLong()))\n      assertEquals(s * 1_024L, PEBIBYTES.toTebibytes(s.toLong()))\n    }\n  }\n\n  @Test fun format() {\n    assertEquals(\"0 B\", BinaryByteUnit.format(0))\n    assertEquals(\"1 B\", BinaryByteUnit.format(1))\n    assertEquals(\"1 KiB\", BinaryByteUnit.format(1024))\n    assertEquals(\"1 KiB\", BinaryByteUnit.format(1025))\n    assertEquals(\"16 KiB\", BinaryByteUnit.format(16384))\n    assertEquals(\"1.2 MiB\", BinaryByteUnit.format(1234567))\n    assertEquals(\"1.2 GiB\", BinaryByteUnit.format(1288490189))\n    assertEquals(\"8,192 PiB\", BinaryByteUnit.format(Long.MAX_VALUE))\n  }\n\n  @Test fun formatWithPattern() {\n    val pattern = \"0.0#\"\n    assertEquals(\"0.0 B\", BinaryByteUnit.format(0, pattern))\n    assertEquals(\"1.0 B\", BinaryByteUnit.format(1, pattern))\n    assertEquals(\"1.0 KiB\", BinaryByteUnit.format(1024, pattern))\n    assertEquals(\"1.0 KiB\", BinaryByteUnit.format(1025, pattern))\n    assertEquals(\"16.0 KiB\", BinaryByteUnit.format(16384, pattern))\n    assertEquals(\"1.18 MiB\", BinaryByteUnit.format(1234567, pattern))\n  }\n\n  @Test fun formatWithDecimalFormat() {\n    val format: NumberFormat = DecimalFormat(\"#.##\", DecimalFormatSymbols(Locale.FRENCH))\n    assertEquals(\"16 KiB\", BinaryByteUnit.format(16384, format))\n    assertEquals(\"1,18 MiB\", BinaryByteUnit.format(1234567, format))\n  }\n\n  @Test fun formatNegativeValuesThrows() {\n    assertFailsWith<IllegalArgumentException> {\n      BinaryByteUnit.format(-1)\n    }.also {\n      assertEquals(\"bytes < 0: -1\", it.message)\n    }\n    assertFailsWith<IllegalArgumentException> {\n      BinaryByteUnit.format(-1, \"#.##\")\n    }.also {\n      assertEquals(\"bytes < 0: -1\", it.message)\n    }\n\n    val format: NumberFormat = DecimalFormat(\"#.##\", DecimalFormatSymbols(Locale.FRENCH))\n    assertFailsWith<IllegalArgumentException> {\n      BinaryByteUnit.format(-1, format)\n    }.also {\n      assertEquals(\"bytes < 0: -1\", it.message)\n    }\n  }\n}\n"
  },
  {
    "path": "src/jvmTest/kotlin/com/jakewharton/byteunits/BitUnitTest.kt",
    "content": "package com.jakewharton.byteunits\n\nimport com.jakewharton.byteunits.BitUnit.BITS\nimport com.jakewharton.byteunits.BitUnit.GIGABITS\nimport com.jakewharton.byteunits.BitUnit.KILOBITS\nimport com.jakewharton.byteunits.BitUnit.MEGABITS\nimport com.jakewharton.byteunits.BitUnit.PETABITS\nimport com.jakewharton.byteunits.BitUnit.TERABITS\nimport java.text.DecimalFormat\nimport java.text.DecimalFormatSymbols\nimport java.text.NumberFormat\nimport java.util.Locale\nimport kotlin.test.Test\nimport kotlin.test.assertEquals\nimport kotlin.test.assertFailsWith\n\nclass BitUnitTest {\n  @Suppress(\"KotlinConstantConditions\")\n  @Test\n  fun convertInternal() {\n    for (s in 0..998) {\n      assertEquals(s / 8L, BITS.toBytes(s.toLong()))\n      assertEquals(s / 1000L, BITS.toKilobits(s.toLong()))\n      assertEquals(s / 1000000L, BITS.toMegabits(s.toLong()))\n      assertEquals(s / 1000000000L, BITS.toGigabits(s.toLong()))\n      assertEquals(s / 1000000000000L, BITS.toTerabits(s.toLong()))\n      assertEquals(s / 1000000000000000L, BITS.toPetabits(s.toLong()))\n      assertEquals(s * 125L, KILOBITS.toBytes(s.toLong()))\n      assertEquals(s * 1000L, KILOBITS.toBits(s.toLong()))\n      assertEquals(s / 1000L, KILOBITS.toMegabits(s.toLong()))\n      assertEquals(s / 1000000L, KILOBITS.toGigabits(s.toLong()))\n      assertEquals(s / 1000000000L, KILOBITS.toTerabits(s.toLong()))\n      assertEquals(s / 1000000000000L, KILOBITS.toPetabits(s.toLong()))\n      assertEquals(s * 125000L, MEGABITS.toBytes(s.toLong()))\n      assertEquals(s * 1000000L, MEGABITS.toBits(s.toLong()))\n      assertEquals(s * 1000L, MEGABITS.toKilobits(s.toLong()))\n      assertEquals(s / 1000L, MEGABITS.toGigabits(s.toLong()))\n      assertEquals(s / 1000000L, MEGABITS.toTerabits(s.toLong()))\n      assertEquals(s / 1000000000L, MEGABITS.toPetabits(s.toLong()))\n      assertEquals(s * 125000000L, GIGABITS.toBytes(s.toLong()))\n      assertEquals(s * 1000000000L, GIGABITS.toBits(s.toLong()))\n      assertEquals(s * 1000000L, GIGABITS.toKilobits(s.toLong()))\n      assertEquals(s * 1000L, GIGABITS.toMegabits(s.toLong()))\n      assertEquals(s / 1000L, GIGABITS.toTerabits(s.toLong()))\n      assertEquals(s / 1000000L, GIGABITS.toPetabits(s.toLong()))\n      assertEquals(s * 125000000000L, TERABITS.toBytes(s.toLong()))\n      assertEquals(s * 1000000000000L, TERABITS.toBits(s.toLong()))\n      assertEquals(s * 1000000000L, TERABITS.toKilobits(s.toLong()))\n      assertEquals(s * 1000000L, TERABITS.toMegabits(s.toLong()))\n      assertEquals(s * 1000L, TERABITS.toGigabits(s.toLong()))\n      assertEquals(s / 1000L, TERABITS.toPetabits(s.toLong()))\n      assertEquals(s * 125000000000000L, PETABITS.toBytes(s.toLong()))\n      assertEquals(s * 1000000000000000L, PETABITS.toBits(s.toLong()))\n      assertEquals(s * 1000000000000L, PETABITS.toKilobits(s.toLong()))\n      assertEquals(s * 1000000000L, PETABITS.toMegabits(s.toLong()))\n      assertEquals(s * 1000000L, PETABITS.toGigabits(s.toLong()))\n      assertEquals(s * 1000L, PETABITS.toTerabits(s.toLong()))\n    }\n  }\n\n  @Test fun format() {\n    assertEquals(\"0 b\", BitUnit.format(0))\n    assertEquals(\"1 b\", BitUnit.format(1))\n    assertEquals(\"1 Kb\", BitUnit.format(1000))\n    assertEquals(\"1 Kb\", BitUnit.format(1001))\n    assertEquals(\"16 Kb\", BitUnit.format(16000))\n    assertEquals(\"1.2 Mb\", BitUnit.format(1177171))\n    assertEquals(\"1.2 Gb\", BitUnit.format(1200000000))\n    assertEquals(\"9,223.4 Pb\", BitUnit.format(Long.MAX_VALUE))\n  }\n\n  @Test fun formatWithPattern() {\n    val pattern = \"0.0#\"\n    assertEquals(\"0.0 b\", BitUnit.format(0, pattern))\n    assertEquals(\"1.0 b\", BitUnit.format(1, pattern))\n    assertEquals(\"1.0 Kb\", BitUnit.format(1000, pattern))\n    assertEquals(\"1.0 Kb\", BitUnit.format(1001, pattern))\n    assertEquals(\"16.0 Kb\", BitUnit.format(16000, pattern))\n    assertEquals(\"1.18 Mb\", BitUnit.format(1177171, pattern))\n  }\n\n  @Test fun formatWithDecimalFormat() {\n    val format: NumberFormat = DecimalFormat(\"#.##\", DecimalFormatSymbols(Locale.FRENCH))\n    assertEquals(\"16 Kb\", BitUnit.format(16000, format))\n    assertEquals(\"1,18 Mb\", BitUnit.format(1177171, format))\n  }\n\n  @Test fun formatNegativeValuesThrows() {\n    assertFailsWith<IllegalArgumentException> {\n      BitUnit.format(-1)\n    }.also {\n      assertEquals(\"bits < 0: -1\", it.message)\n    }\n    assertFailsWith<IllegalArgumentException> {\n      BitUnit.format(-1, \"#.##\")\n    }.also {\n      assertEquals(\"bits < 0: -1\", it.message)\n    }\n\n    val format: NumberFormat = DecimalFormat(\"#.##\", DecimalFormatSymbols(Locale.FRENCH))\n    assertFailsWith<IllegalArgumentException> {\n      BitUnit.format(-1, format)\n    }.also {\n      assertEquals(\"bits < 0: -1\", it.message)\n    }\n  }\n}\n"
  },
  {
    "path": "src/jvmTest/kotlin/com/jakewharton/byteunits/DecimalByteUnitTest.kt",
    "content": "package com.jakewharton.byteunits\n\nimport com.jakewharton.byteunits.DecimalByteUnit.BYTES\nimport com.jakewharton.byteunits.DecimalByteUnit.GIGABYTES\nimport com.jakewharton.byteunits.DecimalByteUnit.KILOBYTES\nimport com.jakewharton.byteunits.DecimalByteUnit.MEGABYTES\nimport com.jakewharton.byteunits.DecimalByteUnit.PETABYTES\nimport com.jakewharton.byteunits.DecimalByteUnit.TERABYTES\nimport java.text.DecimalFormat\nimport java.text.DecimalFormatSymbols\nimport java.text.NumberFormat\nimport java.util.Locale\nimport kotlin.test.Test\nimport kotlin.test.assertEquals\nimport kotlin.test.assertFailsWith\n\nclass DecimalByteUnitTest {\n  @Suppress(\"KotlinConstantConditions\")\n  @Test\n  fun convertInternal() {\n    for (s in 0..998) {\n      assertEquals(s / 1000L, BYTES.toKilobytes(s.toLong()))\n      assertEquals(s / 1000000L, BYTES.toMegabytes(s.toLong()))\n      assertEquals(s / 1000000000L, BYTES.toGigabytes(s.toLong()))\n      assertEquals(s / 1000000000000L, BYTES.toTerabytes(s.toLong()))\n      assertEquals(s / 1000000000000000L, BYTES.toPetabytes(s.toLong()))\n      assertEquals(s * 1000L, KILOBYTES.toBytes(s.toLong()))\n      assertEquals(s / 1000L, KILOBYTES.toMegabytes(s.toLong()))\n      assertEquals(s / 1000000L, KILOBYTES.toGigabytes(s.toLong()))\n      assertEquals(s / 1000000000L, KILOBYTES.toTerabytes(s.toLong()))\n      assertEquals(s / 1000000000000L, KILOBYTES.toPetabytes(s.toLong()))\n      assertEquals(s * 1000000L, MEGABYTES.toBytes(s.toLong()))\n      assertEquals(s * 1000L, MEGABYTES.toKilobytes(s.toLong()))\n      assertEquals(s / 1000L, MEGABYTES.toGigabytes(s.toLong()))\n      assertEquals(s / 1000000L, MEGABYTES.toTerabytes(s.toLong()))\n      assertEquals(s / 1000000000L, MEGABYTES.toPetabytes(s.toLong()))\n      assertEquals(s * 1000000000L, GIGABYTES.toBytes(s.toLong()))\n      assertEquals(s * 1000000L, GIGABYTES.toKilobytes(s.toLong()))\n      assertEquals(s * 1000L, GIGABYTES.toMegabytes(s.toLong()))\n      assertEquals(s / 1000L, GIGABYTES.toTerabytes(s.toLong()))\n      assertEquals(s / 1000000L, GIGABYTES.toPetabytes(s.toLong()))\n      assertEquals(s * 1000000000000L, TERABYTES.toBytes(s.toLong()))\n      assertEquals(s * 1000000000L, TERABYTES.toKilobytes(s.toLong()))\n      assertEquals(s * 1000000L, TERABYTES.toMegabytes(s.toLong()))\n      assertEquals(s * 1000L, TERABYTES.toGigabytes(s.toLong()))\n      assertEquals(s / 1000L, TERABYTES.toPetabytes(s.toLong()))\n      assertEquals(s * 1000000000000000L, PETABYTES.toBytes(s.toLong()))\n      assertEquals(s * 1000000000000L, PETABYTES.toKilobytes(s.toLong()))\n      assertEquals(s * 1000000000L, PETABYTES.toMegabytes(s.toLong()))\n      assertEquals(s * 1000000L, PETABYTES.toGigabytes(s.toLong()))\n      assertEquals(s * 1000L, PETABYTES.toTerabytes(s.toLong()))\n    }\n  }\n\n  @Test fun format() {\n    assertEquals(\"0 B\", DecimalByteUnit.format(0))\n    assertEquals(\"1 B\", DecimalByteUnit.format(1))\n    assertEquals(\"1 KB\", DecimalByteUnit.format(1000))\n    assertEquals(\"1 KB\", DecimalByteUnit.format(1001))\n    assertEquals(\"16 KB\", DecimalByteUnit.format(16000))\n    assertEquals(\"1.2 MB\", DecimalByteUnit.format(1177171))\n    assertEquals(\"1.2 GB\", DecimalByteUnit.format(1200000000))\n    assertEquals(\"9,223.4 PB\", DecimalByteUnit.format(Long.MAX_VALUE))\n  }\n\n  @Test fun formatWithPattern() {\n    val pattern = \"0.0#\"\n    assertEquals(\"0.0 B\", DecimalByteUnit.format(0, pattern))\n    assertEquals(\"1.0 B\", DecimalByteUnit.format(1, pattern))\n    assertEquals(\"1.0 KB\", DecimalByteUnit.format(1000, pattern))\n    assertEquals(\"1.0 KB\", DecimalByteUnit.format(1001, pattern))\n    assertEquals(\"16.0 KB\", DecimalByteUnit.format(16000, pattern))\n    assertEquals(\"1.18 MB\", DecimalByteUnit.format(1177171, pattern))\n  }\n\n  @Test fun formatWithDecimalFormat() {\n    val format: NumberFormat = DecimalFormat(\"#.##\", DecimalFormatSymbols(Locale.FRENCH))\n    assertEquals(\"16 KB\", DecimalByteUnit.format(16000, format))\n    assertEquals(\"1,18 MB\", DecimalByteUnit.format(1177171, format))\n  }\n\n  @Test fun formatNegativeValuesThrows() {\n    assertFailsWith<IllegalArgumentException> {\n      DecimalByteUnit.format(-1)\n    }.also {\n      assertEquals(\"bytes < 0: -1\", it.message)\n    }\n    assertFailsWith<IllegalArgumentException> {\n      DecimalByteUnit.format(-1, \"#.##\")\n    }.also {\n      assertEquals(\"bytes < 0: -1\", it.message)\n    }\n\n    val format: NumberFormat = DecimalFormat(\"#.##\", DecimalFormatSymbols(Locale.FRENCH))\n    assertFailsWith<IllegalArgumentException> {\n      DecimalByteUnit.format(-1, format)\n    }.also {\n      assertEquals(\"bytes < 0: -1\", it.message)\n    }\n  }\n}\n"
  }
]